How to add tags to groups when creating an api map? And how to set the color of each label?
def create_map(mapname, markers):
url = 'https://maphub.net/api/1/map/upload'
api_key = 'xxx'
args = {
'file_type': 'geojson',
'title': mapname,
'short_name': mapname.lower().replace(' ', '-'),
'visibility': 'public', # Доступ к карте только по ссылке
}
headers = {
'Authorization': 'Token ' + api_key,
'MapHub-API-Arg': json.dumps(args),
}
groups = []
for marker in markers:
group_exists = False
for group in groups:
if group['title'] == marker['type']:
group_exists = True
break
if not group_exists:
new_group = {
'title': marker['type'],
'color': marker['color']
}
groups.append(new_group)
features = []
for marker in markers:
feature = {
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [marker['lon'], marker['lat']]
},
'properties': {
'title': marker['name'],
'description': marker['description'],
'group': marker['type']
}
}
features.append(feature)
geojson = {
'type': 'FeatureCollection',
'features': features,
'groups': groups
}
r = requests.post(url, headers=headers, data=json.dumps(geojson))
response_data = r.json()
if 'url' in response_data:
map_url = response_data['url']
return map_url
else:
return None
markers = [{'lat': 45.3485, 'lon': 40.2019, 'name': '178.34.59.237', 'description': 'Severin', 'color': '#FF0000', 'type': 'IP'}, {'lat': 44.6004, 'lon': 40.1025, 'name': '37.78.0.115', 'description': 'Maykop', 'color': '#FF0000', 'type': 'IP'}, {'lat': 55.8236, 'lon': 37.6034, 'name': '62.183.126.225', 'description': 'Moscow', 'color': '#FF0000', 'type': 'IP'}, {'lat': 55.8236, 'lon': 37.6034, 'name': '62.183.127.156', 'description': 'Moscow', 'color': '#FF0000', 'type': 'IP'}, {'lat': 39.2891, 'lon': -76.5583, 'name': '69.251.203.9', 'description': 'Baltimore', 'color': '#FF0000', 'type': 'IP'}, {'lat': 39.3408, 'lon': -76.4078, 'name': '96.244.13.39', 'description': 'Middle River', 'color': '#FF0000', 'type': 'IP'}]