In [1]:
from leafletwidget import (
    Map,
    Marker,
    TileLayer, ImageOverlay,
    Polyline, Polygon, Rectangle, Circle, CircleMarker,
    GeoJSON,
    DrawControl
)
from leafletwidget import initialize_notebook

In [2]:
from IPython.html import widgets
from IPython.display import display

In [3]:
# Run this if you have an internet connection
initialize_notebook()



In [3]:
# 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')


Map


In [4]:
center = [34.6252978589571, -77.34580993652344]
zoom = 10

In [5]:
m = Map(width='100%', default_tiles=TileLayer(opacity=1.0), center=center, zoom=zoom)

In [6]:
m

In [ ]:
display(m)

In [ ]:
m.interact(zoom=(5,10,1))

In [ ]:
m.remove_layer(m.default_tiles)

In [ ]:
m.add_layer(m.default_tiles)

In [ ]:
m.model_id

In [ ]:
print m.center
print m.zoom
print m.bounds

Marker


In [ ]:
mark = Marker(location=m.center)

In [ ]:
mark.visible

In [ ]:
m += mark

In [ ]:
mark.interact(opacity=(0.0,1.0,0.01))

In [ ]:
mark.visible

In [ ]:
mark.visible = False

Image Overlay


In [ ]:
io = ImageOverlay(url='http://ipython.org/_static/IPy_header.png', bounds=m.bounds)
m.add_layer(io)

In [ ]:
m.remove_layer(io)

Polyline


In [ ]:
pl = Polyline(locations=m.bounds_polygon)
m += pl

In [ ]:
pl.fill_color = '#F00'
pl.fill_opacity = 1.0

In [ ]:
m -= pl

Polygon


In [ ]:
pg = Polygon(locations=m.bounds_polygon, weight=3,
            color='#F00', opacity=0.8, fill_opacity=0.8,
            fill_color='#0F0')
m += pg

In [ ]:
m -= pg

Rectangle


In [ ]:
r = Rectangle(bounds=m.bounds, weight=10, fill_opacity=0.0)
m += r

In [ ]:
m -= r

Circle


In [ ]:
c = Circle(location=m.center)
m.add_layer(c)

In [ ]:
c.interact(weight=(0,10,1), opacity=(0.0,1.0,0.01))

In [ ]:
c.model_id

In [ ]:
m.remove_layer(c)

In [ ]:
c.close()

In [ ]:
m.layers

In [ ]:
c2 = Circle(location=m.center, radius=30, weight=1,
            color='#F00', opacity=1.0, fill_opacity=1.0,
            fill_color='#0F0')
m.add_layer(c2)

In [ ]:
c2.model_id

In [ ]:
m.remove_layer(c2)

In [ ]:
c2.close()

CircleMarker


In [ ]:
cm = CircleMarker(location=m.center, radius=30, weight=2,
                  color='#F00', opacity=1.0, fill_opacity=1.0,
                  fill_color='#0F0')
m.add_layer(cm)

In [ ]:
cm.model_id

In [ ]:
m.remove_layer(cm)

In [ ]:
cm.close()

Multiple Circles


In [ ]:
circles = []
for pos in m.bounding_polygon:
    c = Circle(location=pos, radius=1000)
    circles.append(c)
    m.add_layer(c)

In [ ]:
for c in circles:
    m.remove_layer(c)

In [ ]:
m.remove_layer(p)

In [ ]:
p.close()