Draw Control#

The DrawControl allows one to draw shapes on the map such as Rectangle Circle or lines.

Example#

from ipyleaflet import Map, basemaps, basemap_to_tiles, DrawControl

watercolor = basemap_to_tiles(basemaps.Stadia.StamenTerrain)

m = Map(layers=(watercolor, ), center=(50, 354), zoom=5)

draw_control = DrawControl()
draw_control.polyline =  {
    "shapeOptions": {
        "color": "#6bc2e5",
        "weight": 8,
        "opacity": 1.0
    }
}
draw_control.polygon = {
    "shapeOptions": {
        "fillColor": "#6be5c3",
        "color": "#6be5c3",
        "fillOpacity": 1.0
    },
    "drawError": {
        "color": "#dd253b",
        "message": "Oups!"
    },
    "allowIntersection": False
}
draw_control.circle = {
    "shapeOptions": {
        "fillColor": "#efed69",
        "color": "#efed69",
        "fillOpacity": 1.0
    }
}
draw_control.rectangle = {
    "shapeOptions": {
        "fillColor": "#fca45d",
        "color": "#fca45d",
        "fillOpacity": 1.0
    }
}

m.add(draw_control)

m

Methods#

class ipyleaflet.leaflet.DrawControl(**kwargs: Any)[source]#

DrawControl class.

Drawing tools for drawing on the map.

clear()[source]#

Clear all drawings.

clear_circle_markers()[source]#

Clear all circle markers.

clear_circles()[source]#

Clear all circles.

clear_markers()[source]#

Clear all markers.

clear_polygons()[source]#

Clear all polygons.

clear_polylines()[source]#

Clear all polylines.

clear_rectangles()[source]#

Clear all rectangles.

on_draw(callback, remove=False)[source]#

Add a draw event listener.

Parameters:
  • callback (callable) – Callback function that will be called on draw event.

  • remove (boolean) – Whether to remove this callback or not. Defaults to False.