from IPython.display import HTML, display, clear_output import uuid import jinja2 from jinja2 import Template from settings import LEAFLET_KEY CSS_URL = "http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" LEAFLET_JS_URL = "http://cdn.leafletjs.com/leaflet-0.7.2/leaflet" div_id = 'i' + str(uuid.uuid4()) JS = u""" """ # demonstrates interference from .rendered_html CSS CSS = """ """ HTML_ = """
""" template = Template(CSS + JS + HTML_) HTML(template.render(leaflet_js_url=LEAFLET_JS_URL, css_url = CSS_URL, leaflet_api_key = LEAFLET_KEY, lat=37.8717, long=-122.2728, zoom=12, div_id=div_id, height=200 )) # will normalize.css fix this problem? from IPython.display import HTML, display, clear_output import uuid import jinja2 from jinja2 import Template from settings import LEAFLET_KEY CSS_URL = "http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" LEAFLET_JS_URL = "http://cdn.leafletjs.com/leaflet-0.7.2/leaflet" div_id = 'i' + str(uuid.uuid4()) JS = u""" """ # demonstrates interference from .rendered_html CSS CSS = """ """ HTML_ = """
""" template = Template(CSS + JS + HTML_) HTML(template.render(leaflet_js_url=LEAFLET_JS_URL, css_url = CSS_URL, leaflet_api_key = LEAFLET_KEY, lat=37.8717, long=-122.2728, zoom=12, div_id=div_id, height=200 )) import uuid from functools import partial from IPython.display import HTML, display, clear_output import jinja2 from jinja2 import Template from settings import LEAFLET_KEY CSS_URL = "http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" LEAFLET_JS_URL = "http://cdn.leafletjs.com/leaflet-0.7.2/leaflet" JS = u""" """ CSS = """ """ HTML_ = """
""" template = Template(CSS + JS + HTML_) def leaflet(leaflet_api_key, lat, long, zoom, height): div_id = 'i' + str(uuid.uuid4()) display(HTML(template.render(leaflet_js_url=LEAFLET_JS_URL, css_url = CSS_URL, leaflet_api_key = leaflet_api_key, lat=lat, long=long, zoom=zoom, div_id=div_id, height=height ))) leaflet(leaflet_api_key=LEAFLET_KEY, lat=37.8717, long=-122.2728, zoom=9, height=300) %%javascript require(["leaflet"], function(leaflet) { var map = window._my_maps['i3c9fe247-096f-4df2-b6d7-291bb6d3b0e1'] console.log(map.getCenter()); }); from IPython.html import widgets from IPython.html.widgets import interact, fixed zoom_widget = widgets.IntSliderWidget(min=1, max=18, step=1) zoom_widget.value = 12 interact (leaflet, leaflet_api_key=fixed(LEAFLET_KEY), lat=fixed(37.8717), long=fixed(-122.2728),height=fixed(500), zoom=zoom_widget) %%javascript console.log(IPython.notebook.get_cells()); %%javascript require(["leaflet"], function(leaflet) { console.log(L.version); // attempt to find maps in the window object -- not successful. var mapObjects = []; for(var key in window) { var value = window[key]; if (value instanceof L.Map) { // foo instance found in the global scope, named by key mapObjects.push(value) } } console.log(mapObjects); });