1

In a Jupyter notebook, I'm trying to make a simple widget using iPyLeaflet that lets me draw a polygon on a map and gives me the coordinates of the corners of the polygon. For some reason, after I initialize my map, I can draw one polygon just fine. When I go to draw the second polygon, the "click first point to close" function stops working, and the only way to get out of the shape drawing tool is to click "cancel" on the side menu.

If I try to delete any shapes after this, I can click the shapes and they'll disappear but I'm unable to click the "save" button on the side menu ("cancel" and "clear all" still work though).

Finally, if I rerun the cells, the map will no longer display. The notebook says the cell has finished running but no map or other output appears under the cell.

I've tried version updates and haven't seen a difference (I've used iPyLeaflet 0.17.0 and 0.17.3). Here's my code defining the map:

class PolygonMap():
    def __init__(self):
        self.polygons = []
        
        self.m = Map(zoom=10, dragging=True)

        self.draw_control = DrawControl()

        self.draw_control.on_draw(self.handle_draw)
        self.m.add_control(self.draw_control)
        return

        
    def handle_draw(self,target, action, geo_json):
        # Get coordinates of selected polygon out of map drawing
        coords = geo_json['geometry']['coordinates'][0]
        print(coords)

        return
    
    def display(self):
        display(self.m)
        return

and the cell I'm using to display/interact with the map is just

m = PolygonMap()
m.display()

Is there something wrong here in my code? Is it a dependencies issue? I'm using Python 3.10.9 (Anaconda) and can provide any other info that might be helpful. Thanks!

Jake
  • 99
  • 7

0 Answers0