ipyleaflet icon indicating copy to clipboard operation
ipyleaflet copied to clipboard

Adding a layer with a Marker with an empty location tuple breaks leaflet zoom and pan

Open noresistence opened this issue 3 years ago • 2 comments
trafficstars

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

ipyleaflet_bug.webm

noresistence avatar Jul 20 '22 18:07 noresistence

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 ?

HaudinFlorence avatar Sep 02 '22 19:09 HaudinFlorence

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.

noresistence avatar Sep 07 '22 15:09 noresistence