from IPython.display import HTML
import folium
import numpy as np
from matplotlib import pyplot as plt
Folium is available from https://github.com/wrobstory/folium
and is installable via
$ pip install folium
Read the docs for more
def inline_map(map):
"""
Embeds the HTML source of the map directly into the IPython notebook.
This method will not work if the map depends on any files (json data). Also this uses
the HTML5 srcdoc attribute, which may not be supported in all browsers.
"""
map._build_map()
return HTML('<iframe srcdoc="{srcdoc}" style="width: 100%; height: 700px; border: none"></iframe>'.format(srcdoc=map.HTML.replace('"', '"')))
def embed_map(map, path="map.html"):
"""
Embeds a linked iframe to the map into the IPython notebook.
Note: this method will not capture the source of the map into the notebook.
This method should work for all maps (as long as they use relative urls).
"""
map.create_map(path=path)
return HTML('<iframe src="files/{path}" style="width: 100%; height: 700px; border: 3"></iframe>'.format(path=path))
# NIWA Auckland Office
niwa_auckland = [-36.8441449, 174.76182459999995]
map = folium.Map(location=niwa_auckland, zoom_start=11, )
# map_osm.create_map(path='osm.html')
map.simple_marker(location=niwa_auckland, popup="NIWA Auckland Office")
map
<folium.folium.Map at 0x109ed2a10>
tileset = r'http://maps.niwa.co.nz/nztopo/{z}/{x}/{y}.png'
# tileset = r'http://{s}.tiles.mapbox.com/v3/MapID/{z}/{x}/{y}.png'
map = folium.Map(location=niwa_auckland, zoom_start=6, tiles=tileset, attr='NIWA Topo50')
inline_map(map)
This has limited zoom levels - no map tiles after zoom level 8. Only good for countrywide views.
mapbox = folium.Map(location=niwa_auckland, zoom_start=6, tiles='Mapbox Bright')
mapbox.simple_marker(location=niwa_auckland, popup="NIWA Auckland Office")
inline_map(mapbox)