Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Upload map

https://maphub.net/api/1/map/upload

Upload a file and create a new map.

When empty is used for file_type, an empty map will be created.

A static image is automatically generated for the uploaded map.

For this endpoint you’ll need to

  • send the arguments as a JSON encoded string in the MapHub-API-Arg header
  • send the uploaded file as binary data in the request body (except with empty file_type)

Arguments

  • file_type (required): one of empty, kml, gpx, geojson, csv, or excel. For KMZ files, use kml. For XLS, XLSX, and ODS files, use excel.
  • visibility (required): The visibility option of the map. One of public, unlisted, private.
  • title (optional): the preferred title of the map
  • description (optional): the preferred description of the map
  • short_name (optional): the short name of the map, visible in the URL. This is just a preference, the final URL will be returned in the response.

Table imports

CSV and spreadsheet uploads never geocode addresses and do not consume geocoding allowance. Provide latitude and longitude columns or an inline geojson column when an item needs a location. A row without valid source geometry is preserved with no location under Unlocated Items.

The upload imports rows up to the map owner’s item limit. Rows beyond that capacity are not imported. Source group paths are preserved, and unlocated grouped rows use an Unlocated Items subgroup under their source parent.

See XLSX / CSV import for supported columns, geometry precedence, and group syntax.

Response

  • id: id of the map
  • url: URL of the map
  • owner: map owner’s username
  • short_name: short name of the map, used in the URL
  • title: title of the map
  • visibility: visibility mode of the map. One of public, unlisted, private, select.

Limitations

Following limits apply to uploads:

  • maximum file size 15 MB
  • maximum processing time 2 minutes

On a MapHub Enterprise server, there are no limits. If you are interested in MapHub Enterprise, contact us.

Multi-level groups

You can create multi-level groups by using the following format for “group”.

North America/United States/California/Los Angeles

Note, you have to use exactly this character. Please copy and paste it. It is not the same as the normal / character.

Code example

curl with file

curl https://maphub.net/api/1/map/upload \
    --header 'Authorization: Token <api_key>' \
    --header 'MapHub-API-Arg: {"file_type": "gpx", "visibility": "public"}' \
    --data-binary @test.gpx

curl with geojson data

curl https://maphub.net/api/1/map/upload \
    --header 'Authorization: Token <api_key>' \
    --header 'MapHub-API-Arg: {"file_type": "geojson", "visibility": "public"}' \
    --data-raw '{"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "Point", "coordinates": [12.34, 56.78]}, "properties": {"title": "Test point", "description": "Test description", "group": 12345}}], "groups": [{"title": "Test group", "id": 12345}]}'

Python with file

import json
import requests

url = 'https://maphub.net/api/1/map/upload'

api_key = '<api_key>'

args = {
    'file_type': 'gpx',
    'title': 'Sample Title',
    'short_name': 'short name',
    'visibility': 'public',
}

headers = {
    'Authorization': 'Token ' + api_key,
    'MapHub-API-Arg': json.dumps(args),
}

with open('test.gpx', 'rb') as f:
    r = requests.post(url, headers=headers, data=f)

print(r.json())

Python with geojson data

import json
import requests

url = 'https://maphub.net/api/1/map/upload'

api_key = '<api_key>'

args = {
    'file_type': 'geojson',
    'title': 'Sample Title',
    'short_name': 'short name',
    'visibility': 'public',
}

headers = {
    'Authorization': 'Token ' + api_key,
    'MapHub-API-Arg': json.dumps(args),
}

geojson = {
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "geometry": {"type": "Point", "coordinates": [12.34, 56.78]},
            "properties": {
                "title": 'Test point',
                "description": 'Test description',
                "group": 12345,
            },
        }
    ],
    "groups": [{"title": 'Test group', "id": 12345}],
}


r = requests.post(url, headers=headers, data=json.dumps(geojson))
print(r.json())

Python empty map

import json
import requests

url = 'https://maphub.net/api/1/map/upload'

api_key = '<api_key>'

args = {
    'file_type': 'empty',
    'title': 'Sample Title',
    'short_name': 'short name',
    'visibility': 'public',
}

headers = {
    'Authorization': 'Token ' + api_key,
    'MapHub-API-Arg': json.dumps(args),
}


r = requests.post(url, headers=headers)
print(r.json())