/*!
* angular-mapboxgl-directive 0.13.1 2016-09-27
* An AngularJS directive for Mapbox GL
* git: git+https://github.com/Naimikan/angular-mapboxgl-directive.git
*/
!function(a,b,c){"use strict";a.module("mapboxgl-directive",[]).directive("mapboxgl",["$q","mapboxglUtils","mapboxglConstants","mapboxglEventsUtils","mapboxglMapsData",function(c,d,e,f,g){function h(a){this._mapboxGlMap=c.defer(),this._geojsonObjects=[],this._imageObjects=[],this._videoObjects=[],this._markerObjects=[],this._persistentGeojson=e.map.defaultPersistentGeojson,this._persistentImage=e.map.defaultPersistentImage,this._persistentVideo=e.map.defaultPersistentVideo,this._elementDOM=null,this.getMap=function(){return this._mapboxGlMap.promise},this.getMapboxGlScope=function(){return a},this.getDOMElement=function(){return this._elementDOM},this.setDOMElement=function(a){this._elementDOM=a},this.getGeojsonObjects=function(){return this._geojsonObjects},this.addGeojsonObject=function(a){this._geojsonObjects.push(a)},this.removeGeojsonObjects=function(){this._geojsonObjects=[]},this.getImageObjects=function(){return this._imageObjects},this.addImageObject=function(a){this._imageObjects.push(a)},this.removeImageObjects=function(){this._imageObjects=[]},this.getVideoObjects=function(){return this._videoObjects},this.addVideoObject=function(a){this._videoObjects.push(a)},this.removeVideoObjects=function(){this._videoObjects=[]},this.getMarkerObjects=function(){return this._markerObjects},this.addMarkerObject=function(a){this._markerObjects.push(a)},this.removeMarkerObjects=function(){this._markerObjects=[]},this.isGeojsonPersistent=function(){return this._persistentGeojson},this.setPersistentGeojson=function(a){this._persistentGeojson=a},this.isImagePersistent=function(){return this._persistentImage},this.setPersistentImage=function(a){this._persistentImage=a},this.isVideoPersistent=function(){return this._persistentVideo},this.setPersistentVideo=function(a){this._persistentVideo=a},this.changeLoadingMap=function(a){a?this._elementDOM.hasClass("angular-mapboxgl-map-loading")||(this.getMap().then(function(a){a.getCanvas().style.opacity=.25}),this._elementDOM.addClass("angular-mapboxgl-map-loading")):this._elementDOM.hasClass("angular-mapboxgl-map-loading")&&(this.getMap().then(function(a){a.getCanvas().style.opacity=1}),this._elementDOM.removeClass("angular-mapboxgl-map-loading"))}}function i(c,h,i,j){if(!b)throw new Error("Mapbox GL does not included");if(!b.accessToken){if(!(a.isDefined(i.accessToken)&&i.accessToken.length>0))throw new Error("Mapbox access token does not defined");b.accessToken=i.accessToken}if(!b.supported())throw new Error("Your browser does not support Mapbox GL");j.setDOMElement(h),c.mapboxglMapId=i.id?i.id:d.generateMapId(),h.attr("id",c.mapboxglMapId);var k=function(){isNaN(i.width)?h.css("width",i.width):h.css("width",i.width+"px"),j.getMap().then(function(a){a.resize()})},l=function(){isNaN(i.height)?h.css("height",i.height):h.css("height",i.height+"px"),j.getMap().then(function(a){a.resize()})},m=function(b){a.isDefined(i.language)&&b.setLayoutProperty("country-label-lg","text-field","{name_"+i.language+"}")};a.isDefined(i.width)&&(k(),c.$watch(function(){return h[0].getAttribute("width")},function(){k()})),a.isDefined(i.height)?(l(),c.$watch(function(){return h[0].getAttribute("height")},function(){l()})):h.css("height",e.defaultHeight),a.isDefined(c.persistentGeojson)&&"boolean"==typeof c.persistentGeojson&&(j.setPersistentGeojson(c.persistentGeojson),c.$watch(function(){return c.persistentGeojson},function(){if("boolean"!=typeof c.persistentGeojson)throw new Error("Invalid parameter");j.setPersistentGeojson(c.persistentGeojson)})),a.isDefined(c.persistentImage)&&"boolean"==typeof c.persistentImage&&(j.setPersistentImage(c.persistentImage),c.$watch(function(){return c.persistentImage},function(){if("boolean"!=typeof c.persistentImage)throw new Error("Invalid parameter");j.setPersistentImage(c.persistentImage)})),a.isDefined(c.persistentVideo)&&"boolean"==typeof c.persistentVideo&&(j.setPersistentVideo(c.persistentVideo),c.$watch(function(){return c.persistentVideo},function(){if("boolean"!=typeof c.persistentVideo)throw new Error("Invalid parameter");j.setPersistentVideo(c.persistentVideo)}));var n=new b.Map({container:c.mapboxglMapId,style:c.glStyle||e.map.defaultStyle,center:e.map.defaultCenter,hash:a.isDefined(i.hash)&&"boolean"==typeof i.hash?i.hash:e.map.defaultHash,bearingSnap:a.isDefined(i.bearingSnap)&&a.isNumber(i.bearingSnap)?i.bearingSnap:e.map.defaultBearingSnap,failIfMajorPerformanceCaveat:a.isDefined(i.failIfMajorPerformanceCaveat)&&"boolean"==typeof i.failIfMajorPerformanceCaveat?i.failIfMajorPerformanceCaveat:e.map.defaultFailIfMajorPerformanceCaveat,preserveDrawingBuffer:a.isDefined(i.preserveDrawingBuffer)&&"boolean"==typeof i.preserveDrawingBuffer?i.preserveDrawingBuffer:e.map.defaultPreserveDrawingBuffer,trackResize:a.isDefined(i.trackResize)&&"boolean"==typeof i.trackResize?i.trackResize:e.map.defaultTrackResize,attributionControl:!1});g.addMap(c.mapboxglMapId,n),j._mapboxGlMap.resolve(n),f.exposeMapEvents(n),j.getMap().then(function(a){c.$watch(function(){return i.language},function(){a.loaded()?m(a):a.on("load",function(){m(a)})}),c.$watch(function(){return i.showCollisionBoxes},function(){"boolean"==typeof i.showCollisionBoxes&&(a.showCollisionBoxes=i.showCollisionBoxes)}),c.$watch(function(){return i.showTileBoundaries},function(){"boolean"==typeof i.showTileBoundaries&&(a.showTileBoundaries=i.showTileBoundaries)}),c.$watch(function(){return i.repaint},function(){"boolean"==typeof i.repaint&&(a.repaint=i.repaint)})}),c.$on("mapboxglMap:styleChanged",function(){j.getMap().then(function(a){m(a)})}),c.$on("$destroy",function(){n.remove()})}var j={restrict:"EA",replace:!0,scope:{glStyle:"=",glCenter:"=",glMinZoom:"=",glMaxZoom:"=",glZoom:"=",glBearing:"=",glPitch:"=",glControls:"=",glFilter:"=",glClasses:"=",glGeojson:"=",glInteractive:"=",glHandlers:"=",glImage:"=",glVideo:"=",glPopups:"=",glMarkers:"=",persistentGeojson:"=",persistentImage:"=",persistentVideo:"="},transclude:!0,template:'
',controller:h,link:i};return h.$inject=["$scope"],j}]),a.module("mapboxgl-directive").factory("mapboxglEventsUtils",["$rootScope",function(a){function b(b){c.map(function(c){b.on(c,function(b){a.$broadcast("mapboxglMap:"+c,b)})})}var c=["webglcontextlost","webglcontextrestored","error","render","mouseout","mousedown","mouseup","mousemove","touchstart","touchend","touchmove","touchcancel","click","dblclick","contextmenu","load","movestart","moveend","move","zoomend","zoomstart","zoom","boxzoomend","boxzoomcancel","boxzoomstart","rotatestart","rotateend","rotate","dragstart","drag","dragend","pitch"],d={exposeMapEvents:b};return d}]),a.module("mapboxgl-directive").factory("mapboxglGeojsonUtils",["mapboxglUtils","mapboxglConstants",function(b,d){function e(b,e){if(a.isUndefined(b)||null===b)throw new Error("Map is undefined");if(a.isUndefined(e)||null===e)throw new Error("Object definition is undefined");var f=function(b,c){var d=["ref","source-layer","minzoom","maxzoom","interactive","filter","layout","paint"];a.isDefined(c)&&d.map(function(d){a.isDefined(c[d])&&null!==c[d]&&(b[d]=c[d])})};e.id=e.type+"_"+Date.now();var g;if(a.isDefined(e.source)&&a.isDefined(e.source.data))g=e.source.data;else{if(a.isUndefined(e.coordinates)||null===e.coordinates)throw new Error("Object coordinates are undefined");if("line"===e.type)e.geometryType="LineString";else if("polygon"===e.type)e.geometryType="Polygon";else{if("circle"!==e.type)throw new Error("Invalid geojson type");e.geometryType="Point"}g={type:"Feature",properties:e.properties||{},geometry:{type:e.geometryType,coordinates:e.coordinates}}}var h={type:"geojson",data:g,maxzoom:a.isDefined(e.maxzoom)?e.maxzoom:d.source.defaultMaxZoom,buffer:a.isDefined(e.buffer)?e.buffer:d.source.defaultBuffer,tolerance:a.isDefined(e.tolerance)?e.tolerance:d.source.defaultTolerance,cluster:a.isDefined(e.cluster)?e.cluster:d.source.defaultCluster,clusterRadius:a.isDefined(e.clusterRadius)?e.clusterRadius:d.source.defaultClusterRadius};a.isDefined(e.clusterMaxZoom)&&a.isNumber(e.clusterMaxZoom)&&(h.clusterMaxZoom=e.clusterMaxZoom),b.addSource(e.id,h);var i=a.isDefined(e.layer)&&a.isDefined(e.layer.before)?e.layer.before:c,j={id:e.id,type:e.type,source:e.id,metadata:{type:"mapboxgl:geojson",popup:e.popup}};f(j,e.layer),b.addLayer(j,i)}var f={createGeojsonByObject:e};return f}]),a.module("mapboxgl-directive").factory("mapboxglImageUtils",["mapboxglUtils","mapboxglConstants",function(b,c){function d(b,c){if(a.isUndefined(b)||null===b)throw new Error("Map is undefined");if(a.isUndefined(c)||null===c)throw new Error("Object definition is undefined");if(a.isUndefined(c.url)||null===c.url)throw new Error("Object url is undefined");if(a.isUndefined(c.coordinates)||null===c.coordinates)throw new Error("Object coordinates are undefined");c.id="image_"+Date.now(),b.addSource(c.id,{type:"image",url:c.url,coordinates:c.coordinates}),b.addLayer({id:c.id,source:c.id,type:"raster",layout:a.isDefined(c.layer)&&a.isDefined(c.layer.layout)?c.layer.layout:{},paint:a.isDefined(c.layer)&&a.isDefined(c.layer.paint)?c.layer.paint:{}})}var e={createImageByObject:d};return e}]),a.module("mapboxgl-directive").factory("mapboxglMapsData",["mapboxglUtils",function(a){function b(a,b){g.push({id:a,mapInstance:b})}function c(b){var c=a.arrayObjectIndexOf(g,b,"id");if(c!==-1){var d=g[c];d.mapInstance.remove(),g.splice(c,1)}}function d(){g.map(function(a){a.mapInstance.remove()}),g=[]}function e(){return g}function f(b){var c=a.arrayObjectIndexOf(g,b,"id");return c!==-1?g[c].mapInstance:null}var g=[],h={addMap:b,removeMapById:c,removeAllMaps:d,getMaps:e,getMapById:f};return h}]),a.module("mapboxgl-directive").factory("mapboxglMarkerUtils",["mapboxglUtils","mapboxglConstants","mapboxglPopupUtils",function(c,d,e){function f(c,d){if(a.isUndefined(c)||null===c)throw new Error("Map is undefined");if(a.isUndefined(d)||null===d)throw new Error("Object definition is undefined");if(a.isUndefined(d.coordinates)||null===d.coordinates)throw new Error("Object coordinates are undefined");if(a.isUndefined(d.element)||null===d.element)throw new Error("Object element is undefined");var f=d.options||{},g=new b.Marker(d.element,f).setLngLat(d.coordinates);if(a.isDefined(d.popup)){var h=e.createPopupByObject(c,d.popup);g.setPopup(h)}return g.addTo(c),g}var g={createMarkerByObject:f};return g}]),a.module("mapboxgl-directive").factory("mapboxglPopupUtils",["mapboxglUtils","mapboxglConstants",function(c,d){function e(c,d){if(a.isUndefined(c)||null===c)throw new Error("Map is undefined");if(a.isUndefined(d)||null===d)throw new Error("Object definition is undefined");if(a.isUndefined(d.coordinates)||null===d.coordinates)throw new Error("Object coordinates are undefined");if(a.isUndefined(d.html)||null===d.html)throw new Error("Object html is undefined");var e=d.options||{},f=new b.Popup(e).setLngLat(d.coordinates).setHTML(d.html).addTo(c);return f}var f={createPopupByObject:e};return f}]),a.module("mapboxgl-directive").factory("mapboxglUtils",["$window","$q",function(b,c){function d(){return"mapbox-gl-map-"+Date.now()}function e(d){var e=c.defer();return a.isDefined(d)&&(a.isDefined(d.autodiscover)&&d.autodiscover?b.navigator.geolocation.getCurrentPosition(function(a){var b=a.coords;e.resolve([b.longitude,b.latitude])},function(a){e.reject(a)},{enableHighAccuracy:!0,timeout:5e3,maximumAge:0}):a.isNumber(d.lat)&&a.isNumber(d.lng)&&(d.lng>-180||d.lng<180)&&(d.lat>-90||d.lat<90)?e.resolve([d.lng,d.lat]):a.isArray(d)&&2===d.length&&a.isNumber(d[0])&&a.isNumber(d[1])&&(d[0]>-180||d[0]<180)&&(d[1]>-90||d[1]<90)?e.resolve(d):e.resolve(!1)),e.promise}function f(a,b,c){for(var d=0,e=a.length;d0){var h=g[0],i=h.layer.metadata.popup.options,j=h.layer.metadata.popup.message;new b.Popup(i).setLngLat(c.unproject(d.point)).setHTML(j).addTo(c)}}),c.on("mousemove",function(b){var d=c.getStyle(),e=d.layers.filter(function(b){if(a.isDefined(b.metadata)&&a.isDefined(b.metadata.type))return"mapboxgl:geojson"===b.metadata.type}).map(function(a){return a.id}),f=c.queryRenderedFeatures(b.point,{layers:e});c.getCanvas().style.cursor=f.length?"pointer":""})},k=function(b,d,e){if(a.isDefined(e)){if(i(b),Object.prototype.toString.call(e)===Object.prototype.toString.call({}))c.createGeojsonByObject(b,e),d.addGeojsonObject(e);else{if(Object.prototype.toString.call(e)!==Object.prototype.toString.call([]))throw new Error("Invalid geojson parameter");e.map(function(a){c.createGeojsonByObject(b,a),d.addGeojsonObject(a)})}j(b)}};d.$on("mapboxglMap:styleChanged",function(){if(g.isGeojsonPersistent()){var b=a.copy(g.getGeojsonObjects());g.removeGeojsonObjects(),g.getMap().then(function(a){k(a,g,b)})}else g.removeGeojsonObjects()}),g.getMap().then(function(a){h.$watchCollection("glGeojson",function(b){a.style.loaded()?k(a,g,b):a.style.on("load",function(){k(a,g,b)})})})}var e={restrict:"A",scope:!1,replace:!1,require:"?^mapboxgl",link:d};return e}]),a.module("mapboxgl-directive").directive("glHandlers",[function(){function b(b,c,d,e){if(!e)throw new Error("Invalid angular-mapboxgl-directive controller");var f=e.getMapboxGlScope();e.getMap().then(function(b){f.$watch("glHandlers",function(c){if(a.isDefined(c)&&Object.prototype.toString.call(c)===Object.prototype.toString.call({}))for(var d in c){var e=c[d]?"enable":"disable";b[d][e]()}},!0)})}var c={restrict:"A",scope:!1,replace:!1,require:"?^mapboxgl",link:b};return c}]),a.module("mapboxgl-directive").directive("glImage",["mapboxglImageUtils",function(b){function c(c,d,e,f){if(!f)throw new Error("Invalid angular-mapboxgl-directive controller");var g=f.getMapboxGlScope(),h=function(c,d,e){if(a.isDefined(e))if(Object.prototype.toString.call(e)===Object.prototype.toString.call({}))b.createImageByObject(c,e),d.addImageObject(e);else{if(Object.prototype.toString.call(e)!==Object.prototype.toString.call([]))throw new Error("Invalid image parameter");e.map(function(a){b.createImageByObject(c,a),d.addImageObject(a)})}};c.$on("mapboxglMap:styleChanged",function(){if(f.isImagePersistent()){var b=a.copy(f.getImageObjects());f.removeImageObjects(),f.getMap().then(function(a){h(a,f,b)})}else f.removeImageObjects()}),f.getMap().then(function(a){g.$watchCollection("glImage",function(b){a.style.loaded()?h(a,f,b):a.once("style.load",function(){h(a,f,b)})})})}var d={restrict:"A",scope:!1,replace:!1,require:"?^mapboxgl",link:c};return d}]),a.module("mapboxgl-directive").directive("glInteractive",[function(){function b(b,c,d,e){if(!e)throw new Error("Invalid angular-mapboxgl-directive controller");var f=["touchZoomRotate","scrollZoom","boxZoom","dragRotate","dragPan","doubleClickZoom","keyboard"],g=e.getMapboxGlScope();e.getMap().then(function(b){g.$watch("glInteractive",function(c){if(a.isDefined(c)&&"boolean"==typeof c){var d=c?"enable":"disable";f.map(function(a){b[a][d]()})}})})}var c={restrict:"A",scope:!1,replace:!1,require:"?^mapboxgl",link:b};return c}]),a.module("mapboxgl-directive").directive("glMarkers",["mapboxglMarkerUtils",function(b){function c(c,d,e,f){if(!f)throw new Error("Invalid angular-mapboxgl-directive controller");var g=f.getMapboxGlScope(),h=[],i=function(){h.map(function(a){a.remove()}),h=[]},j=function(c,d){if(a.isDefined(d))if(i(),Object.prototype.toString.call(d)===Object.prototype.toString.call({})){var e=b.createMarkerByObject(c,d);h.push(e)}else{if(Object.prototype.toString.call(d)!==Object.prototype.toString.call([]))throw new Error("Invalid marker parameter");d.map(function(a){var d=b.createMarkerByObject(c,a);h.push(d)})}};f.getMap().then(function(a){g.$watchCollection("glMarkers",function(b){j(a,b)})})}var d={restrict:"A",scope:!1,replace:!1,require:"?^mapboxgl",link:c};return d}]),a.module("mapboxgl-directive").directive("glMaxBounds",[function(){function b(b,c,d,e){if(!e)throw new Error("Invalid angular-mapboxgl-directive controller");var f=e.getMapboxGlScope();e.getMap().then(function(b){f.$watch("glMaxBounds",function(c){if(!a.isArray(c)||2!==c.length)throw new Error("Invalid max bounds");b.setMaxBounds(c)},!0)})}var c={restrict:"A",scope:!1,replace:!1,require:"?^mapboxgl",link:b};return c}]),a.module("mapboxgl-directive").directive("glMaxZoom",[function(){function b(b,c,d,e){if(!e)throw new Error("Invalid angular-mapboxgl-directive controller");var f=e.getMapboxGlScope();e.getMap().then(function(b){f.$watch("glMaxZoom",function(c){if(!a.isNumber(c)||!(c>=0||c<=20))throw new Error("Invalid max zoom");b.setMaxZoom(c)},!0)})}var c={restrict:"A",scope:!1,replace:!1,require:"?^mapboxgl",link:b};return c}]),a.module("mapboxgl-directive").directive("glMinZoom",[function(){function b(b,c,d,e){if(!e)throw new Error("Invalid angular-mapboxgl-directive controller");var f=e.getMapboxGlScope();e.getMap().then(function(b){f.$watch("glMinZoom",function(c){if(!a.isNumber(c)||!(c>=0||c<=20))throw new Error("Invalid min zoom");b.setMinZoom(c)},!0)})}var c={restrict:"A",scope:!1,replace:!1,require:"?^mapboxgl",link:b};return c}]),a.module("mapboxgl-directive").directive("glPitch",[function(){function b(b,c,d,e){if(!e)throw new Error("Invalid angular-mapboxgl-directive controller");var f=e.getMapboxGlScope();e.getMap().then(function(b){f.$watch("glPitch",function(c){if(!a.isNumber(c)||!(c>=0||c<=60))throw new Error("Invalid pitch");b.setPitch(c)},!0)})}var c={restrict:"A",scope:!1,replace:!1,require:"?^mapboxgl",link:b};return c}]),a.module("mapboxgl-directive").directive("glPopups",["mapboxglPopupUtils",function(b){function c(c,d,e,f){if(!f)throw new Error("Invalid angular-mapboxgl-directive controller");var g=f.getMapboxGlScope(),h=[],i=function(){h.map(function(a){a.remove()}),h=[]},j=function(c,d){if(a.isDefined(d))if(i(),Object.prototype.toString.call(d)===Object.prototype.toString.call({})){var e=b.createPopupByObject(c,d);h.push(e)}else{if(Object.prototype.toString.call(d)!==Object.prototype.toString.call([]))throw new Error("Invalid popup parameter");d.map(function(a){var d=b.createPopupByObject(c,a);h.push(d)})}};f.getMap().then(function(a){g.$watchCollection("glPopups",function(b){j(a,b)})})}var d={restrict:"A",scope:!1,replace:!1,require:"?^mapboxgl",link:c};return d}]),a.module("mapboxgl-directive").directive("glStyle",["$rootScope",function(a){function b(b,c,d,e){if(!e)throw new Error("Invalid angular-mapboxgl-directive controller");var f=e.getMapboxGlScope();e.getMap().then(function(b){f.$watch("glStyle",function(c,d){b.setStyle(c),b.style.on("load",function(){a.$broadcast("mapboxglMap:styleChanged")})},!0)})}var c={restrict:"A",scope:!1,replace:!1,require:"?^mapboxgl",link:b};return c}]),a.module("mapboxgl-directive").directive("glVideo",["mapboxglVideoUtils",function(b){function c(c,d,e,f){if(!f)throw new Error("Invalid angular-mapboxgl-directive controller");var g=f.getMapboxGlScope(),h=function(c,d,e){if(a.isDefined(e))if(Object.prototype.toString.call(e)===Object.prototype.toString.call({}))b.createVideoByObject(c,e),d.addVideoObject(e);else{if(Object.prototype.toString.call(e)!==Object.prototype.toString.call([]))throw new Error("Invalid video parameter");e.map(function(a){b.createVideoByObject(c,a),d.addVideoObject(a)})}};f.getMap().then(function(a){g.$watchCollection("glVideo",function(b){a.loaded()?h(a,f,b):a.on("load",function(){h(a,f,b)})})})}var d={restrict:"A",scope:!1,replace:!1,require:"?^mapboxgl",link:c};return d}]),a.module("mapboxgl-directive").directive("glZoom",[function(){function b(b,c,d,e){if(!e)throw new Error("Invalid angular-mapboxgl-directive controller");var f=e.getMapboxGlScope();e.getMap().then(function(b){f.$watch("glZoom",function(c){if(!a.isNumber(c)||!(c>=0||c<=20))throw new Error("Invalid zoom");b.setZoom(c)},!0)})}var c={restrict:"A",scope:!1,replace:!1,require:"?^mapboxgl",link:b};return c}])}(angular,mapboxgl);