diff --git a/tarteaucitron.services.js b/tarteaucitron.services.js index 3b71ce6..a962c2f 100644 --- a/tarteaucitron.services.js +++ b/tarteaucitron.services.js @@ -620,18 +620,37 @@ tarteaucitron.services.googlemaps = { "cookies": [], "js": function () { "use strict"; + var mapOptions, + map, + uniqIds = [], + i; + if (tarteaucitron.user.googlemapsApiKey === undefined) { return; } - tarteaucitron.addScript('//maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&callback=tarteaucitron_googlemaps&key=' + tarteaucitron.user.googlemapsApiKey); + + tarteaucitron.addScript('//maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&callback=tac_googlemaps_callback&key=' + tarteaucitron.user.googlemapsApiKey); + + window.tac_googlemaps_callback = function () { + tarteaucitron.fallback(['googlemaps-canvas'], function (x) { + var uniqId = '_' + Math.random().toString(36).substr(2, 9); + uniqIds.push(uniqId); + return '
'; + }); + + for (i = 0; i < uniqIds.length; i += 1) { + mapOptions = { + zoom: parseInt(document.getElementById(uniqIds[i]).getAttribute('zoom'), 10), + center: new google.maps.LatLng(parseFloat(document.getElementById(uniqIds[i]).getAttribute('latitude'), 10), parseFloat(document.getElementById(uniqIds[i]).getAttribute('longitude'), 10)) + }; + map = new google.maps.Map(document.getElementById(uniqIds[i]), mapOptions); + } + }; }, "fallback": function () { "use strict"; var id = 'googlemaps'; - - if (document.getElementById('tac_map-canvas')) { - document.getElementById('tac_map-canvas').innerHTML = tarteaucitron.engage(id); - } + tarteaucitron.fallback(['googlemaps-canvas'], tarteaucitron.engage(id)); } };