from __future__ import print_function from leafletwidget import ( Map, Marker, TileLayer, ImageOverlay, Polyline, Polygon, Rectangle, Circle, CircleMarker, GeoJSON, DrawControl ) from leafletwidget import initialize_notebook from IPython.html import widgets from IPython.display import display from IPython.utils.traitlets import link # Run this if you have an internet connection initialize_notebook() # Run this if you have installed the JS/CSS in $HOME/.ipython/nbextensions initialize_notebook(leaflet_url='/nbextensions/leaflet-0.7.2', leaflet_draw_url='/nbextensions/leaflet.draw/0.2.3') center = [34.6252978589571, -77.34580993652344] zoom = 10 c = widgets.ContainerWidget() m = Map(width='600px',height='400px', center=center, zoom=zoom) c.children = [m] display(c) m.zoom dc = DrawControl() def handle_draw(self, action, geo_json): print(action) print(geo_json) dc.on_draw(handle_draw) m.add_control(dc) dc.last_action dc.last_draw m2 = Map(width='600px',height='400px', center=center, zoom=zoom) display(m2) map_center_link = link((m,'center'),(m2,'center')) map_zoom_link = link((m,'zoom'),(m2,'zoom')) new_poly = GeoJSON(data=dc.last_draw) m2.add_layer(new_poly) dc2 = DrawControl(polygon={'shapeOptions':{'color':'#00F'}}, polyline={}, circle={'shapeOptions':{'color':'#00F'}}) m2.add_control(dc2)