eodaGmbH / py-maplibregl

Python bindings for MapLibre GL JS
https://eodagmbh.github.io/py-maplibregl/
MIT License
27 stars 2 forks source link

Add Layer Controls #69

Closed Martenz closed 1 week ago

Martenz commented 1 week ago

It would be nice to have also a layer list control that can be added. Like leaflet Layer Groups / Layer Controls in order to control layer visibility in case of multiple layer added to the map.

crazycapivara commented 1 week ago

Yep, this is really useful. For some reason MapLibre does not ship with such a control by default but I will add a custom one.

Martenz commented 1 week ago

Nice! If I can contribute in some way I'll keep an eye on the repo. Meanwhile thanks for the support. I did something but only in JS with custom controls https://maplibre.org/maplibre-gl-js/docs/API/interfaces/IControl/ It would be nice to have it in python and maybe extend it in future for also other custom controls like style dynamic changes (opacity, colors etc..)

crazycapivara commented 1 week ago

Yep, that's how it works. If you want pure Python you need to use Map.set_layout_property in combination with a Shiny ui element or a Jupyter interaction element.

crazycapivara commented 1 week ago

In general you do dynamic changes with Map.set_layout_property and Map.set_paint_property. Take a look at this example using Shiny. You need to run the example in order to get the select boxes.

giswqs commented 1 week ago

Leafmap has a widget for changing MapLibre layer opacity and color interactively. It is not as nice as the leaflet built-in LayerControl, but it does work. https://leafmap.org/maplibre/color_switcher/

https://github.com/eodaGmbH/py-maplibregl/assets/5016453/ec9898ea-cb03-4e20-bb2f-c82ea1e77067

giswqs commented 1 week ago

The PMTiles Viewer has a layer control for changing layer visibility. It is a good example.

image