Position of layers in ipyleaflet

20 Views Asked by At

With ipyleaflet, I am creating a map to which I add a DrawControl.

from ipyleaflet import Map, GeoJSON, DrawControl

m = Map(center=(40.730610, -73.935242), zoom=10)
draw_control = DrawControl(polyline={}, circlemarker={})
draw_control.rectangle = { 'shapeOptions': {"fillColor": "#ffab71"}}
m.add(draw_control)
m

Now, with DrawControl, I am creating polygons over the map.

Next, I add a GeoJSON layer to the map.

ny_poly= [
    {
        "type": "Feature",
        "geometry": {
            "type": "Polygon",
            "coordinates": [
                [
                    [-74.0479, 40.6839],
                    [-73.9696, 40.6807],
                    [-73.9911, 40.6413],
                    [-74.0479, 40.6839]
                ]
            ]
        },
        "properties": {"name": "Polygon 1"}
    }]

geojson_layer1 = GeoJSON(data=ny_poly[0], style={"color": "red", "opacity": 1, "fillOpacity": 1})
m.add(geojson_layer1)

How can I ensure that the GeoJSON polygon is shown on top of the basemap, but below the polygons drawn with DrawControl?

I have seen other people using m.panes or playing with the order in the m.layers tuple but since I am working with DrawContorl, I cannot manage to make it work. See the image, how the red polygon is on top of the orange one.

enter image description here

Any suggestions?

Some references to similar solutions here and here

0

There are 0 best solutions below