Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vector tile layer control doesn't work #747

Open
lopezvoliver opened this issue Jun 6, 2024 · 5 comments
Open

Vector tile layer control doesn't work #747

lopezvoliver opened this issue Jun 6, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@lopezvoliver
Copy link
Collaborator

lopezvoliver commented Jun 6, 2024

Environment Information

  • leafmap version: 0.32.1
  • Python version: 3.12.3
  • Operating System: Ubuntu 22.04.4 LTS

Description

Adding a vector tile layer, I expect the control to turn on/off the layer to work, but the layer remains in the map.

What I Did

Example using ipyleaflet without leafmap (expected behavior)

import ipyleaflet
m = ipyleaflet.Map(center=[30.25, 38.25],zoom=10)

styles = {
    "fields":{
        "fillOpacity": 1,
        "fillColor": "#aefeae",
        "fill": True,
        "weight": 1,
        "color": "black",
        "opacity": 1
    }
}
url_data = "path/to/my/vector-tile-layer/{z}/{x}/{y}.pbf"
vl = ipyleaflet.VectorTileLayer(url=url_data, vector_tile_layer_styles=styles, name="Fields")
m.add_layer(vl)
control = ipyleaflet.LayersControl(position='topright')
m.add(control)
m

ipyleaflet

Example using leafmap (bug)

import ipyleaflet
import leafmap
m = leafmap.Map(center=[30.25, 38.25],zoom=10)

styles = {
    "fields":{
        "fillOpacity": 1,
        "fillColor": "#aefeae",
        "fill": True,
        "weight": 1,
        "color": "black",
        "opacity": 1
    }
}
url_data = "path/to/my/vector-tile-layer/{z}/{x}/{y}.pbf"
vl = ipyleaflet.VectorTileLayer(url=url_data, vector_tile_layer_styles=styles, name="Fields")
m.add_layer(vl)
#m.add_vector_tile(url_data,styles, "Field use")  # Same issue
m

leafmap

@lopezvoliver lopezvoliver added the bug Something isn't working label Jun 6, 2024
@lopezvoliver
Copy link
Collaborator Author

Here's another clue: if I add the simple ipyleaflet.LayersControl, it does work.. so the issue is with the leafmap toolbar:

leafmap_wcontrol

@giswqs
Copy link
Member

giswqs commented Jun 6, 2024

This is probably an ipyleaflet issue because the VectorTileLater class doesn't have an attribute for toggling the layer off programmatically, e.g., layer.visible=False

https://ipyleaflet.readthedocs.io/en/latest/layers/vector_tile.html

@lopezvoliver
Copy link
Collaborator Author

lopezvoliver commented Jun 6, 2024

Was just about to comment.. yes I found out that it's not as simple as with other layers which have the .visible attribute. However, a similar strategy could be used as was done for the geojson layers (e.g. here). In my custom example, I'm now able to do something like:

for l in layers:
    if l.name=="Fields":
        l.vector_tile_layer_styles = {'fields':{'fillOpacity':0, 'opacity':0}}

which worked to make it invisible. However this involves keeping track of the original styles and names used for these layers. I'll work on this anyway independently, but if I manage to make it work in leafmap, I'll make a PR.

@giswqs
Copy link
Member

giswqs commented Jun 6, 2024

Sounds good. Thanks.

@zvezdi
Copy link

zvezdi commented Jun 8, 2024

Hello :) I'm working on a project for a university course I'm taking and I hit a similar issue.

Same problem is reproducible with add_circle_markers_from_xy when you pass different names with the layer_name parameter. The layers names are visible when you open the toolbox but visibility and opacity changes are not applied to the map.

I just started familiarising myself with the library so I might be just using it wrong. This is how I try to use it:

map = leafmap.Map()
map.add_circle_markers_from_xy(dataset1, ..., layer_name = "dataset1")
map.add_circle_markers_from_xy(dataset2, ..., layer_name = "dataset2")

Thank you for your efforts! This library has huge potential, I'm excited to dig deeper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants