from IPython.core.display import HTML, Javascript # load the Google Maps API library # TO DO: make it easy to add API key def gmap_init(): js = """ window.gmap_initialize = function() {}; $.getScript('https://maps.googleapis.com/maps/api/js?v=3&sensor=false&callback=gmap_initialize'); """ return Javascript(data=js) gmap_init() %%html """ % (div_id) js = """ """ % (div_id) HTML(html+js) import uuid def gmap(lat=37.8717,long=-122.2728,zoom=8): div_id = 'i' + str(uuid.uuid4()) html = """
""" % (div_id) js = """ """ % (zoom, lat,long, div_id) return HTML(html+js) import jinja2 TEMPLATE = """{{greeting}}, {{name}}""" my_template = jinja2.Template(TEMPLATE) my_template.render(greeting="hello", name="RY") %%html
%%javascript var myLatlng = new google.maps.LatLng(37.8717,-122.2728); var mapOptions = { zoom: 8, center: myLatlng }; var map = new google.maps.Map(document.getElementById('markers'), mapOptions); // To add the marker to the map, use the 'map' property var marker = new google.maps.Marker({ position: myLatlng, map: map, title:"Berkeley" }); %%html
%%javascript // This example creates circles on the map, representing // populations in the United States. // First, create an object containing LatLng and population for each city. var citymap = {}; citymap['chicago'] = { center: new google.maps.LatLng(41.878113, -87.629798), population: 2842518 }; citymap['newyork'] = { center: new google.maps.LatLng(40.714352, -74.005973), population: 8143197 }; citymap['losangeles'] = { center: new google.maps.LatLng(34.052234, -118.243684), population: 3844829 }; var cityCircle; var mapOptions = { zoom: 4, center: new google.maps.LatLng(37.09024, -95.712891), mapTypeId: google.maps.MapTypeId.TERRAIN }; var map = new google.maps.Map(document.getElementById('circles'), mapOptions); // Construct the circle for each value in citymap. // Note: We scale the population by a factor of 20. for (var city in citymap) { var populationOptions = { strokeColor: '#FF0000', strokeOpacity: 0.8, strokeWeight: 2, fillColor: '#FF0000', fillOpacity: 0.35, map: map, center: citymap[city].center, radius: citymap[city].population / 20 }; // Add the circle for this city to the map. cityCircle = new google.maps.Circle(populationOptions); }