Add tolltip and popup options to map layer configuration.

- `tooltip` takes the name of a GeoJSON property that will be
  shown in a tooltip when hovering the mouse over a feature.

- `popup` can take either the name of a property as above, or
  the boolean value `true`. In the latter case, a table of all
  the feature's properties will be shown when clicking on the
  feature. In the former case, only the value of the designated
  property will be shown.
This commit is contained in:
D. Berge
2023-09-13 12:55:37 +02:00
parent 441a4e296d
commit ed91026319

View File

@@ -56,16 +56,31 @@ if __name__ == '__main__':
file_info = { file_info = {
"type": "map_layer", "type": "map_layer",
"format": layer["format"], "format": layer["format"],
"name": layer_name "name": layer_name,
"tooltip": layer.get("tooltip"),
"popup": layer.get("popup")
} }
db.save_file_data(logical_filepath, json.dumps(file_info)) db.save_file_data(logical_filepath, json.dumps(file_info))
else: else:
file_info = db.get_file_data(logical_filepath) file_info = db.get_file_data(logical_filepath)
if file_info and file_info["name"] != layer_name: dirty = False
if file_info:
if file_info["name"] != layer_name:
print("Renaming to", layer_name) print("Renaming to", layer_name)
file_info["name"] = layer_name file_info["name"] = layer_name
dirty = True
if file_info.get("tooltip") != layer.get("tooltip"):
print("Changing tooltip to", layer.get("tooltip") or "null")
file_info["tooltip"] = layer.get("tooltip")
dirty = True
if file_info.get("popup") != layer.get("popup"):
print("Changing popup to", layer.get("popup") or "null")
file_info["popup"] = layer.get("popup")
dirty = True
if dirty:
db.save_file_data(logical_filepath, json.dumps(file_info)) db.save_file_data(logical_filepath, json.dumps(file_info))
else: else:
print("Already in DB") print("Already in DB")