Skip to content

Instantly share code, notes, and snippets.

@eperedo
Created July 22, 2013 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eperedo/6050780 to your computer and use it in GitHub Desktop.
Save eperedo/6050780 to your computer and use it in GitHub Desktop.
Angular directive for static google maps using [gmaps](hpneo.github.io/gmaps/)
angular.module('Your_Name_App').directive('staticMap', [function () {
return {
restrict: 'A',
template: '<a href="{{mapUrl}}" target="_blank"><img src="{{mapUrl}}" /></a>',
replace: true,
scope: {
position: '=position',
},
link: function postLink(scope, element, attrs, controller) {
var generateStaticMap = function() {
scope.mapUrl = GMaps.staticMapURL({
size: [300, 317],
lat: scope.position.lat,
lng: scope.position.lng,
markers: [
{ lat: scope.position.lat, lng: scope.position.lng, color:'blue'}
]
});
};
if (scope.position) {
generateStaticMap();
}
scope.$watch('position', function(newVal) {
if (newVal) {
generateStaticMap();
}
});
}
};
}]);
<div data-position="{lat:'12.02', lng:'74.02'}" data-static-map></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment