Last active
December 18, 2015 14:26
-
-
Save k0d3d/79dcb9626dd2977a201e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MapApp = angular.module('GoogleMapsInitializer', []); | |
MapApp.factory('Initializer', function($window, $q){ | |
//Google's url for async maps initialization accepting callback function | |
var asyncUrl = 'https://maps.googleapis.com/maps/api/js?key=AIzaSyCOt9IYHpYN22m7alw_HKi5y5WBgu57p4s&v=3.exp&sensor=true&callback=googleMapsInitialized', | |
mapsDefer = $q.defer(); | |
function init () { | |
var gMapsLoader = $.getScript(asyncUrl); | |
gMapsLoader.fail(function (err) { | |
return mapsDefer.reject(err); | |
}); | |
//Callback function - resolving promise after maps successfully loaded | |
$window.googleMapsInitialized = mapsDefer.resolve; | |
} | |
init(); | |
//Usage: Initializer.mapsInitialized.then(callback) | |
return { | |
mapsInitialized : mapsDefer.promise, | |
reload: init | |
}; | |
}); | |
MapApp.directive("cityState", ['Initializer', function (Initializer) { | |
return { | |
template: '<em>{{locationData.formatted_address}}</em>', | |
scope: { | |
locationData: "=cityState" | |
}, | |
link: function (scope) { | |
Initializer.mapsInitialized | |
.then(function () { | |
}); | |
} | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment