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
. For ".kmz" files, usekml
- 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.
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.
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())