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

Map widget missing layers when displayed more than once #82

Open
giswqs opened this issue Jun 30, 2024 · 3 comments
Open

Map widget missing layers when displayed more than once #82

giswqs opened this issue Jun 30, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@giswqs
Copy link
Contributor

giswqs commented Jun 30, 2024

When rendering the map object multiple times in a Jupyter notebook, layers only show up the first time when it is displayed.

import ipywidgets as widgets

from maplibre import Layer, LayerType
from maplibre.sources import GeoJSONSource
from maplibre.controls import ScaleControl, Marker
from maplibre.ipywidget import MapWidget as Map

# Create a source
earthquakes = GeoJSONSource(
    data="https://docs.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson"
)

# Create a layer
layer_id = "earthquakes"

earthquake_circles = Layer(
    type=LayerType.CIRCLE,
    id=layer_id,
    source=earthquakes,
    paint={"circle-color": "yellow"}
)

# Render map
m = Map(height="200px")
m.add_control(ScaleControl(), position="bottom-left")
m.add_layer(earthquake_circles)
m.add_tooltip(layer_id, "mag")
m.add_marker(Marker(lng_lat=(100.507, 13.745)))
m

image

@crazycapivara
Copy link
Contributor

Yep, that's the expected behavior. After the map is rendered, the message queue is cleared!

@giswqs
Copy link
Contributor Author

giswqs commented Jun 30, 2024

Is it possible to retain the message queue?

One use case is that users may want to see the map first before saving it to an HTML file. However, once the map is rendered, saving the map to an HTML file does not work properly anymore because the layers are gone.

@crazycapivara
Copy link
Contributor

Yes, this seems to be a special use case for the ipywidget. We can store it This also makes it possible to get information about layers etc from the python object even after the map has rendered. So I will keep this issue open.

@crazycapivara crazycapivara self-assigned this Jul 5, 2024
@crazycapivara crazycapivara added the enhancement New feature or request label Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants