from ipyleaflet import (
Map,
Marker, MarkerCluster,
TileLayer, ImageOverlay,
Polyline, Polygon, Rectangle, Circle, CircleMarker,
Popup,
GeoJSON,
DrawControl,
basemaps
)
from ipywidgets import HTML
center = [34.6252978589571, -77.34580993652344]
zoom = 10
m = Map(center=center, zoom=zoom)
m
m.interact(zoom=(5,10,1))
m.clear_layers()
m.add_layer(basemaps.Esri.DeLorme)
print(m.center)
print(m.zoom)
mark = Marker(location=m.center)
m += mark
mark.interact(opacity=(0.0,1.0,0.01))
html_widget = HTML(
value="""
<div>Some html with a list of items
<ul class='list-group'>
<li class='list-group-item'>Item A</li>
<li class='list-group-item'>Item B</li>
<li class='list-group-item'>Item C</li>
</ul></div>""",
placeholder='',
description='',
)
mark.popup = html_widget
When we have many markers on a map, it is helpful to cluster them together at high zoom levels. First, we create a small grid of markers.
xscale = 5
yscale = 10
x = [m.center[0] + i * xscale * .05 for i in (-1,0,1)]
y = [m.center[1] + i * yscale * .05 for i in (-1,0,1)]
from itertools import product
locations = product(x, y)
markers = [Marker(location=loc) for loc in locations]
Then we add them all to a MarkerCluster
, which automatically clusters them at appropriate zoom levels.
marker_cluster = MarkerCluster(markers = markers)
m += marker_cluster
m.remove_layer(marker_cluster)
io = ImageOverlay(url='http://ipython.org/_static/IPy_header.png', bounds=m.bounds)
m.add_layer(io)
m.bounds
m
m.remove_layer(io)
pl = Polyline(locations=m.bounds_polygon)
m += pl
pl.fill_color = '#F00'
pl.fill_opacity = 1.0
m -= pl
pg = Polygon(locations=m.bounds_polygon, weight=3,
color='#F00', opacity=0.8, fill_opacity=0.8,
fill_color='#0F0')
m += pg
m -= pg
r = Rectangle(bounds=m.bounds, weight=10, fill_opacity=0.0)
m += r
m -= r
c = Circle(location=m.center)
m.add_layer(c)
c.interact(weight=(0,10,1), opacity=(0.0,1.0,0.01))
c.model_id
m.remove_layer(c)
c.close()
m.layers
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)
c2.model_id
m.remove_layer(c2)
c2.close()
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)
cm.model_id
m.remove_layer(cm)
cm.close()
circles = []
for pos in m.bounds_polygon:
c = Circle(location=pos, radius=1000)
circles.append(c)
m.add_layer(c)
for c in circles:
m.remove_layer(c)