eoda-dev / py-maplibregl

Python bindings for MapLibre GL JS
https://eoda-dev.github.io/py-maplibregl/
MIT License
45 stars 5 forks source link

Update Marker location #67

Closed giswqs closed 5 months ago

giswqs commented 5 months ago

MapLibre JS Marker has a setLngLat() method for updating marker location. Is it possible to support this as well?

Use case: https://maplibre.org/maplibre-gl-js/docs/examples/animate-marker/

crazycapivara commented 5 months ago

There is no out-of.the-box solution, because MapLibre's Map object does not store markers in the way it does for sources and layers, where you can get them by id in order to update them. But I could create on object, where markers are stored if we pass an ID, like Map.add_marker(..., id=None). Then a function Map.set_marker(id, lng_lat) could update the Marker. If you do not explicitly need a marker, you could update a data source instead as shown in this example.

giswqs commented 5 months ago

Make sense. The combination of m.add_source() and m.set_data() solves the issue.