From 870d75ac9155e4b1060bcba79798f451a12e0e32 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Fri, 29 Nov 2013 11:06:19 +0100 Subject: [PATCH] begin maps API v2 to v3 migration --- example/sandbox/settings.py | 2 +- telemeta/static/telemeta/js/resourcemap.js | 48 ++++++++++++------- .../templates/telemeta/geo_continents.html | 5 +- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/example/sandbox/settings.py b/example/sandbox/settings.py index 0a380300..bce19233 100644 --- a/example/sandbox/settings.py +++ b/example/sandbox/settings.py @@ -142,7 +142,7 @@ TEMPLATE_CONTEXT_PROCESSORS = ( TELEMETA_ORGANIZATION = 'Parisson' TELEMETA_SUBJECTS = ('test', 'telemeta', 'sandbox') TELEMETA_DESCRIPTION = "Telemeta TEST sandbox" -TELEMETA_GMAP_KEY = 'ABQIAAAArg7eSfnfTkBRma8glnGrlxRVbMrhnNNvToCbZQtWdaMbZTA_3RRGObu5PDoiBImgalVnnLU2yN4RMA' +TELEMETA_GMAP_KEY = 'AIzaSyBcwFdXEpMduxGg0eOepva5VnkX_VF3Oxg' TELEMETA_CACHE_DIR = MEDIA_ROOT + 'cache/' TELEMETA_EXPORT_CACHE_DIR = MEDIA_ROOT + 'export/' TELEMETA_DATA_CACHE_DIR = TELEMETA_CACHE_DIR + "data/" diff --git a/telemeta/static/telemeta/js/resourcemap.js b/telemeta/static/telemeta/js/resourcemap.js index 881b7a26..8f9d8b8e 100644 --- a/telemeta/static/telemeta/js/resourcemap.js +++ b/telemeta/static/telemeta/js/resourcemap.js @@ -19,12 +19,13 @@ function ResourceMap(list, cfg) { }); that.resize(); }); - google.load('maps', '2'); - google.setOnLoadCallback(function() { + + that.createMap(); that.parseResources(); - $(window).bind('unload', google.maps.Unload); - }); + // $(window).bind('unload', google.maps.Unload); + + } that.resize = function() { @@ -90,29 +91,42 @@ function ResourceMap(list, cfg) { //var name = $.trim(e.find('.resourcemap-name').text()); //var link = e.find('a').attr('href'); //var linktitle = e.find('a').attr('title'); - var marker = new google.maps.Marker(new GLatLng(lat, lng), {title: name}); + var marker = new google.maps.Marker(new google.maps.LatLng(lat, lng), {title: name, map: that.map}); //var info = that.makeInfoBox(name, link, linktitle); - google.maps.Event.addListener(marker, "click", function() { + google.maps.event.addListener(marker, "click", function() { that.showResourceInfo(marker, e); //marker.openInfoWindowHtml(info); }); - that.map.addOverlay(marker); + } }); } that.createMap = function() { - that.log("GMap loaded"); - if (google.maps.BrowserIsCompatible()) { - that.map = new google.maps.Map2(that.container[0]); - var bounds = new GLatLngBounds(); - that.map.setCenter(new GLatLng(0, 0), that.map.getBoundsZoomLevel(bounds)); // France - that.map.setUIToDefault(); - } else { - that.log("Browser isn't compatible with GMap ?!"); - that.toggle(); - } + var mapOptions = { + zoom: 2, + center: new google.maps.LatLng(42.0, 6.0) + }; + that.log("GMap loaded"); + that.map = new google.maps.Map(that.container[0], mapOptions); + // var bounds = new google.maps.LatLngBounds(); + // that.map.setCenter(new google.maps.LatLng(0, 0), that.map.getBoundsZoomLevel(bounds)); // France + // that.map.setUIToDefault(); } that.init(list, cfg); } + + +function initialize() { + var resourceMap = new ResourceMap('.continents', { + 'countryInfoUri': '/geo/country_info/RESOURCEID/'}); +} + + +function loadScript() { + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&callback=initialize'; + document.body.appendChild(script); +} diff --git a/telemeta/templates/telemeta/geo_continents.html b/telemeta/templates/telemeta/geo_continents.html index 9fec8aee..f9802cb9 100644 --- a/telemeta/templates/telemeta/geo_continents.html +++ b/telemeta/templates/telemeta/geo_continents.html @@ -6,12 +6,9 @@ {% block extra_javascript %} {% if gmap_key %} - {% endif %} {% endblock %} -- 2.39.5