-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathangular-gm.min.js
More file actions
8 lines (8 loc) · 13.7 KB
/
angular-gm.min.js
File metadata and controls
8 lines (8 loc) · 13.7 KB
1
2
3
4
5
6
7
8
/**
* AngularGM - Google Maps Directives for AngularJS
* @version v2.0.0 - 2017-01-04
* @link http://dylanfprice.github.com/angular-gm
* @author Dylan Price <the.dylan.price@gmail.com>
* @license MIT License, http://www.opensource.org/licenses/MIT
*/
!function(){"use strict";angular.module("AngularGM",[]).factory("angulargmDefaults",function(){return{precision:3,markerConstructor:google.maps.Marker,polylineConstructor:google.maps.Polyline,circleConstructor:google.maps.Circle,mapOptions:{zoom:8,center:{lat:46,lng:-120},mapTypeId:google.maps.MapTypeId.ROADMAP}}})}(),function(){"use strict";angular.module("AngularGM").directive("gmCircles",["$parse","$compile","$timeout","$log","angulargmUtils","angulargmShape",function(a,b,c,d,e,f){function g(a,b,c,d){if(!("gmCircleCenter"in c))throw"gmCircleCenter attribute required";var e=function(b){var c=a.gmCircleCenter({object:b}),d=h(c);if(null==d)return null;var e=a.gmCircleOptions({object:b}),f={};return angular.extend(f,e,{center:d}),f};f.createShapeDirective("circle",a,c,d,e)}var h=e.validateLatLng;return{restrict:"AE",priority:100,scope:{gmObjects:"&",gmId:"&",gmCircleCenter:"&",gmCircleOptions:"&"},require:"^gmMap",link:g}}])}(),function(){"use strict";angular.module("AngularGM").directive("gmInfoWindow",["$parse","$compile","$timeout","angulargmUtils",function(a,b,c,d){function e(b,d,e,g){var h=angular.extend({},b.$eval(e.gmInfoWindowOptions));h.content=d[0];var i=a(e.gmInfoWindow),j=i(b);j||(j=new google.maps.InfoWindow(h),i.assign(b,j));var k=f(e);angular.forEach(k,function(a,d){google.maps.event.addListener(j,d,function(){c(function(){a(b,{infoWindow:j})})})})}var f=d.getEventHandlers;return{restrict:"A",priority:100,scope:!1,link:e}}])}(),function(){"use strict";angular.module("AngularGM").directive("gmMap",["$timeout","angulargmUtils","debounce",function(a,b,c){function d(b,d,h,i){if(angular.isDefined(b.gmCenter)||(b.center={}),angular.isDefined(b.gmBounds)||(b.bounds={}),!angular.isDefined(b.gmMapId))throw"angulargm must have non-empty gmMapId attribute";var j=!1,k=!1,l=!1,m=!1;h.hasOwnProperty("gmCenter")&&(j=!0),h.hasOwnProperty("gmZoom")&&(k=!0),h.hasOwnProperty("gmBounds")&&(l=!0),h.hasOwnProperty("gmMapTypeId")&&(m=!0);var n=function(){a(function(){(j||k||l||m)&&b.$apply(function(a){if(j&&(b.gmCenter=i.center),k&&(b.gmZoom=i.zoom),l){var c=i.bounds;c&&(b.gmBounds=c)}m&&(b.gmMapTypeId=i.mapTypeId)})})},o=c(n,100);i.addMapListener("drag",o),i.addMapListener("zoom_changed",o),i.addMapListener("center_changed",o),i.addMapListener("bounds_changed",o),i.addMapListener("maptypeid_changed",o),i.addMapListener("resize",o);var p=i.getMap(h.gmMapId),q=e(h);angular.forEach(q,function(c,d){i.addMapListener(d,function(d){var e={map:p};void 0!==d&&(e.event=d),a(function(){c(b.$parent,e)})})}),j&&b.$watch("gmCenter",function(a,b){var c=null!=f(a)&&!g(a,b);c&&!i.dragging&&(i.center=a)},!0),k&&b.$watch("gmZoom",function(a,b){var c=null!=a&&!isNaN(a);c&&a!==b&&(i.zoom=a)}),l&&b.$watch("gmBounds",function(a,b){var c=a!==b;if(c&&!i.dragging){var d=a;d&&(i.bounds=d)}}),m&&b.$watch("gmMapTypeId",function(a,b){var c=a!==b;c&&a&&(i.mapTypeId=a)}),b.$on("gmMapResize",function(a,c){b.gmMapId()===c&&i.mapTrigger("resize")}),i.addMapListenerOnce("idle",function(){b.$emit("gmMapIdle",b.gmMapId())}),i.mapTrigger("resize")}var e=b.getEventHandlers,f=b.validateLatLng,g=b.latLngLiteralEqual;return{restrict:"AE",priority:100,template:'<div><div id="" style="width:100%;height:100%;"></div><div ng-transclude></div></div>',transclude:!0,replace:!0,scope:{gmCenter:"=",gmZoom:"=",gmBounds:"=",gmMapTypeId:"=",gmMapOptions:"&",gmMapId:"&"},controller:"angulargmMapController",link:d}}])}(),function(){"use strict";angular.module("AngularGM").directive("gmMarkers",["$log","$parse","$timeout","angulargmUtils","angulargmShape",function(a,b,c,d,e){function f(a,b,c,d){if(!("gmPosition"in c))throw"gmPosition attribute required";var f=function(b){var c=a.gmPosition({object:b}),d=g(c);if(null==d)return null;var e=a.gmMarkerOptions({object:b}),f={};return angular.extend(f,e,{position:d}),f};e.createShapeDirective("marker",a,c,d,f)}var g=d.validateLatLng;return{restrict:"AE",priority:100,scope:{gmObjects:"&",gmId:"&",gmPosition:"&",gmMarkerOptions:"&",gmEvents:"&"},require:"^gmMap",link:f}}])}(),function(){"use strict";angular.module("AngularGM").directive("gmPolylines",["$parse","$compile","$timeout","$log","angulargmUtils","angulargmShape",function(a,b,c,d,e,f){function g(a,b,c,e){if(!("gmPath"in c))throw"gmPath attribute required";var g=function(b){var c=a.gmPath({object:b}),e=[];angular.forEach(c,function(a){var b=h(a);return null==b?void d.warn("Unable to generate lat/lng from ",a):void e.push(b)});var f=a.gmPolylineOptions({object:b}),g={};return angular.extend(g,f,{path:e}),g};f.createShapeDirective("polyline",a,c,e,g)}var h=e.validateLatLng;return{restrict:"AE",priority:100,scope:{gmObjects:"&",gmId:"&",gmPath:"&",gmPolylineOptions:"&",gmEvents:"&"},require:"^gmMap",link:g}}])}(),function(){"use strict";angular.module("AngularGM").factory("angulargmContainer",["$q",function(a){function b(a,b){if(!(b instanceof google.maps.Map))throw"map not a google.maps.Map: "+b;if(a in g)throw"already contain map with id "+a;g[a]=b,a in h&&h[a].resolve(b)}function c(a){return g[a]}function d(b){var d=h[b]||a.defer(),e=c(b);return h[b]=d,void 0!==e&&d.resolve(e),d.promise}function e(a){a in g&&delete g[a],a in h&&delete h[a]}function f(){g={},h={}}var g={},h={};return{addMap:b,getMap:c,getMapPromise:d,removeMap:e,clear:f}}])}(),function(){"use strict";angular.module("AngularGM").factory("angulargmShape",["$timeout","angulargmUtils",function(a,b){function c(a){if(!("gmObjects"in a))throw"gmObjects attribute required";if(!("gmId"in a))throw"gmId attribute required"}function d(a,b){var c={};return angular.forEach(b,function(b){var d=a.gmId({object:b});c[d]=b}),c}function e(b,c,d,e,f,g){angular.forEach(f,function(f,h){var i=d.getElement(b,c.$id,h),j=g(f);null!=j&&(i?d.updateElement(b,c.$id,h,j):(d.addElement(b,c.$id,h,j),i=d.getElement(b,c.$id,h),angular.forEach(e,function(e,g){d.addListener(i,g,function(){a(function(){var a={object:f};a[b]=i,angular.version.major<=1&&angular.version.minor<=2?e(c.$parent.$parent,a):e(c.$parent.$parent.$parent,a)})})})))})}function f(a,b,c,d){var e=[];c.forEachElementInScope(a,b.$id,function(a,b){b in d||e.push(b)}),angular.forEach(e,function(d){c.removeElement(a,b.$id,d)})}function g(a,b){var c=b.charAt(0).toUpperCase()+b.slice(1)+"s";return a.replace("Shapes",c)}function h(b,c,d,e,f){c.$watch("gmObjects().length",function(a,b){null!=a&&a!==b&&f(c,c.gmObjects())}),c.$watch("gmObjects()",function(a,b){null!=a&&a!==b&&f(c,c.gmObjects())}),c.$watch("gmEvents()",function(d,f){null!=d&&d!==f&&angular.forEach(d,function(d){var f=d.event,g=d.ids;angular.forEach(g,function(d){var g=e.getElement(b,c.$id,d);null!=g&&a(angular.bind(this,e.trigger,g,f))})})}),c.$on(g("gmShapesRedraw",b),function(a,b){null!=b&&b!==d.gmObjects||(f(c),f(c,c.gmObjects()))}),c.$on(g("gmShapesUpdate",b),function(a,b){null!=b&&b!==d.gmObjects||f(c,c.gmObjects())})}function i(i,j,k,l,m){c(k);var n=function(a,c){var h=d(a,c),j=b.getEventHandlers(k);e(i,a,l,j,h,m),f(i,a,l,h),a.$emit(g("gmShapesUpdated",i),k.gmObjects)};h(i,j,k,l,n),a(angular.bind(null,n,j,j.gmObjects()))}return{createShapeDirective:i}}])}(),function(){"use strict";angular.module("AngularGM").factory("angulargmUtils",["$parse",function(a){function b(a,b){return Math.abs(a-b)<1e-6}function c(a,c){return a instanceof google.maps.LatLng&&c instanceof google.maps.LatLng&&(b(a.lat(),c.lat())&&b(a.lng(),c.lng()))}function d(a,c){return!!(null!=a&&a.hasOwnProperty("lat")&&a.hasOwnProperty("lng")&&null!=c&&c.hasOwnProperty("lat")&&c.hasOwnProperty("lng"))&&(b(a.lat,c.lat)&&b(a.lng,c.lng))}function e(a,b){if(!(a instanceof google.maps.LatLngBounds&&b instanceof google.maps.LatLngBounds))return!1;var d=a.getSouthWest(),e=b.getSouthWest(),f=a.getNorthEast(),g=b.getNorthEast();return c(d,e)&&c(f,g)}function f(a){if(!(a instanceof google.maps.LatLng))throw"latLng not a google.maps.LatLng";return{lat:a.lat(),lng:a.lng()}}function g(a){if(null!=a){var b=a.lat,c=a.lng,d=!(null==b||null==c||isNaN(b)||isNaN(c));if(d)return new google.maps.LatLng(b,c)}return null}function h(a){if(null!=a){var b=a.lat,c=a.lng,d=!(null==b||null==c||isNaN(b)||isNaN(c));if(d)return a}return null}function i(a){if(!(a instanceof google.maps.LatLng))throw"latLng must be a google.maps.LatLng";var b=null==a.lat()||null==a.lng(),c=isNaN(a.lat())||isNaN(a.lng());return b||c}function j(b){var c={};return angular.forEach(b,function(b,d){if(0===d.lastIndexOf("gmOn",0)){var e=angular.lowercase(d.substring(4).replace(/(?!^)([A-Z])/g,"_$&")),f=a(b);c[e]=f}}),c}function k(a,b){if(void 0===a||null===a)throw b?b+" was: "+a:"value was: "+a}return{latLngEqual:c,latLngLiteralEqual:d,boundsEqual:e,latLngToObj:f,objToLatLng:g,validateLatLng:h,hasNaN:i,getEventHandlers:j,assertDefined:k}}])}(),function(){"use strict";angular.module("AngularGM").factory("debounce",["$timeout",function(a){return function(b,c,d){function e(){h=this,g=arguments;var e=function(){f=null,d||(i=b.apply(h,g))},j=d&&!f;return f&&a.cancel(f),f=a(e,c),j&&(i=b.apply(h,g)),i}var f,g,h,i;return e.cancel=function(){a.cancel(f),f=null},e}}])}(),function(){"use strict";angular.module("AngularGM").controller("angulargmMapController",["$scope","$element","angulargmUtils","angulargmDefaults","angulargmContainer",function(a,b,c,d,e){var f=c.latLngToObj,g=c.validateLatLng,h=c.boundsEqual,i=c.hasNaN,j=c.assertDefined,k=function(a,b){var c=a.gmMapId();if(!c)throw"angulargm must have non-empty gmMapId attribute";var j=angular.element(b[0].firstChild);j.attr("id",c);var k=this._getConfig(a,d);this._map=this._createMap(c,j,k,e,a),this._elements={},this._listeners={},this.dragging=!1,Object.defineProperties(this,{precision:{value:d.precision,writeable:!1},center:{configurable:!0,get:function(){return f(this._map.getCenter())},set:function(a){if(null===g(a))throw"center contains null or NaN";var b=this.center!==a;b&&this._map.panTo(a)}},zoom:{configurable:!0,get:function(){return this._map.getZoom()},set:function(a){if(null==a||isNaN(a))throw"zoom was null or NaN";var b=this.zoom!==a;b&&this._map.setZoom(a)}},bounds:{configurable:!0,get:function(){return this._map.getBounds()},set:function(a){var b=!i(a.getSouthWest())&&!i(a.getNorthEast());if(!b)throw"bounds contains null or NaN";var c=!h(this.bounds,a);c&&this._map.fitBounds(a)}},mapTypeId:{configurable:!0,get:function(){return this._map.getMapTypeId()},set:function(a){if(null==a)throw"mapTypeId was null or unknown";var b=this.mapTypeId!==a;b&&this._map.setMapTypeId(a)}}}),this._initDragListeners(),a.$on("$destroy",angular.bind(this,this._destroy))};this._getConfig=function(a,b){var c=b.mapOptions,d={};return angular.extend(d,c,a.gmMapOptions()),d},this._createMap=function(a,b,c,d){var e=d.getMap(a);if(e){var f=e.getDiv();b.replaceWith(f),this._map=e,this.mapTrigger("resize"),e.setOptions(c)}else e=new google.maps.Map(b[0],c),d.addMap(a,e);return e},this._initDragListeners=function(){var a=this;this.addMapListener("dragstart",function(){a.dragging=!0}),this.addMapListener("idle",function(){a.dragging=!1})},this._destroy=function(){angular.forEach(this._listeners,function(a){angular.forEach(a,function(a){google.maps.event.removeListener(a)})}),this._listeners={};var a=this,b=Object.keys(this._elements);angular.forEach(b,function(b){var c=Object.keys(a._getElements(b));angular.forEach(c,function(c){a.forEachElementInScope(b,c,function(d,e){a.removeElement(b,c,e)})})});var c=this._map.getStreetView();c&&c.getVisible()&&c.setVisible(!1)},this.addMapListener=function(a,b){var c=google.maps.event.addListener(this._map,a,b);void 0===this._listeners[a]&&(this._listeners[a]=[]),this._listeners[a].push(c)},this.addMapListenerOnce=function(a,b){var c=google.maps.event.addListenerOnce(this._map,a,b);void 0===this._listeners[a]&&(this._listeners[a]=[]),this._listeners[a].push(c)},this.addListener=function(a,b,c){google.maps.event.addListener(a,b,c)},this.addListenerOnce=function(a,b,c){google.maps.event.addListenerOnce(a,b,c)},this.mapTrigger=function(a){google.maps.event.trigger(this._map,a)},this.trigger=function(a,b){google.maps.event.trigger(a,b)},this._newElement=function(a,b){if("marker"===a)return new d.markerConstructor(b);if("polyline"===a){if(!(b.path instanceof Array))throw"polylineOptions did not contain a path";return new d.polylineConstructor(b)}if("circle"===a)return new d.circleConstructor(b);throw"unrecognized type "+a},this._getElements=function(a){return a in this._elements||(this._elements[a]={}),this._elements[a]},this.addElement=function(a,b,c,d){if(j(a,"type"),j(b,"scopeId"),j(c,"id"),j(d,"elementOptions"),this.hasElement(a,b,c))return!1;var e=this._getElements(a);null==e[b]&&(e[b]={});var f={};angular.extend(f,d);var g=this._newElement(a,f);return e[b][c]=g,g.setMap(this._map),!0},this.updateElement=function(a,b,c,d){j(a,"type"),j(b,"scopeId"),j(c,"id"),j(d,"elementOptions");var e=this.getElement(a,b,c);return!!e&&(e.setOptions(d),!0)},this.hasElement=function(a,b,c){return j(a,"type"),j(b,"scopeId"),j(c,"id"),null!=this.getElement(a,b,c)},this.getElement=function(a,b,c){j(a,"type"),j(b,"scopeId"),j(c,"id");var d=this._getElements(a);return null!=d[b]&&c in d[b]?d[b][c]:null},this.removeElement=function(a,b,c){j(a,"type"),j(b,"scopeId"),j(c,"id");var d=this._getElements(a),e=!1,f=d[b][c];return f&&(f.setMap(null),e=!0),d[b][c]=null,delete d[b][c],e},this.forEachElement=function(a,b){j(a,"type"),j(b,"fn");var c=this._getElements(a),d=Object.keys(c),e=d.reduce(function(a,b){return angular.forEach(c[b],function(b){a.push(b)}),a},[]);angular.forEach(e,function(a,c){null!=a&&b(a,c)})},this.forEachElementInScope=function(a,b,c){j(a,"type"),j(b,"scopeId"),j(c,"fn");var d=this._getElements(a);angular.forEach(d[b],function(a,b){null!=a&&c(a,b)})},this.getMap=function(){return this._map},angular.bind(this,k)(a,b)}])}();