ipyleaflet
ipyleaflet copied to clipboard
Adding a layer with a Marker with an empty location tuple breaks leaflet zoom and pan
When adding a layer with a Marker that was created with an empty tuple as location, the map will break.
Steps to reproduce
- create a LayerGroup
- add a polyline to the group
- add a
Marker(location=tuple(), ...)to the group - add group to map
- display map
- zoom, then pan
observed behavior
the polyline forgets its position and scale after moving the map
expected behavior
- polyline rendering not affected by the marker
- some sort of error for trying to construct a marker with invalid coordinates
code to reproduce
from ipyleaflet import Map, LayerGroup, Polyline, LayersControl, Marker
center = (52.204793, 360.121558)
track = [(center[0]+lat_offset, center[1]+lon_offset) for lat_offset, lon_offset in [(0.1, -0.1), (0.03, -0.07), (0, 0), (0.03, 0.07), (0.1, 0.1)]]
m = Map(zoom=10, center=center, scroll_wheel_zoom=True)
line_layer = LayerGroup()
line_layer.name = f'Example line'
line = Polyline(locations=track, color='red', fill=False, weight=4)
line_layer.add(line)
evil_marker = Marker(location=tuple())
line_layer.add(evil_marker)
m.add(line_layer)
display(m)
demonstration
Good evening, I am having a look at your issue and tested the notebook. I can indeed reproduce the observed behavior. Sorry if my question will be naive but do you have a particular reason to use a Marker with location defined by an empty tuple ?
I do not have a use case for a Marker with empty location; it happened by accident and was due to a bug in our code.
But it was rather hard to track down the issue; it would be helpful for future users to generate a warning if someone tries to use an empty tuple (or possibly other illegal values) for marker location instead of silently corrupting the map instance.