diff --git a/.jshintrc b/.jshintrc index 35793b5..c792b75 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,7 +1,7 @@ { "node": true, "browser": true, - "es5": true, + "es5": false, "esnext": true, "bitwise": true, "camelcase": true, diff --git a/dist/angular-mapbox.js b/dist/angular-mapbox.js index 9fc8c73..b3892a7 100644 --- a/dist/angular-mapbox.js +++ b/dist/angular-mapbox.js @@ -228,8 +228,8 @@ var style = setStyleOptions(attrs); var marker; - function setStyleOptions(attrs, default_opts) { - var opts = default_opts || {}; + function setStyleOptions(attrs, defaultOpts) { + var opts = defaultOpts || {}; if(attrs.size) { opts['marker-size'] = attrs.size; } @@ -250,7 +250,9 @@ opts = opts || {}; var marker = L.mapbox.marker.style({ properties: style }, latlng); - if(popupContent && popupContent.length > 0) marker.bindPopup(popupContent); + if(popupContent && popupContent.length > 0) { + marker.bindPopup(popupContent); + } if(controller.$scope.isClusteringMarkers && opts.excludeFromClustering !== true) { controller.$scope.clusterGroup.addLayer(marker); @@ -260,7 +262,9 @@ // this needs to come after being added to map because the L.mapbox.marker.style() factory // does not let us pass other opts (eg, draggable) in - if(opts.draggable) marker.dragging.enable(); + if(opts.draggable) { + marker.dragging.enable(); + } mapboxService.addMarker(marker); //mapboxService.fitMapToMarkers(map); // TODO: debounce this @@ -280,11 +284,13 @@ }; controller.getMap().then(function(map) { - map.on('popupopen', function(e) { + map.on('popupopen', function() { // ensure that popups are compiled var popup = angular.element(document.getElementsByClassName('leaflet-popup-content')); $compile(popup)(scope); - if(!scope.$$phase) scope.$digest(); + if(!scope.$$phase) { + scope.$digest(); + } }); setTimeout(function() { @@ -292,7 +298,9 @@ var popupHTML = ''; var transcluded = transclude(scope, function() {}); for(var i = 0; i < transcluded.length; i++) { - if(transcluded[i].outerHTML !== undefined) popupHTML += transcluded[i].outerHTML; + if(transcluded[i].outerHTML !== undefined) { + popupHTML += transcluded[i].outerHTML; + } } if(attrs.currentLocation !== undefined) { @@ -301,7 +309,9 @@ if(popupHTML) { var popup = angular.element(popupHTML); $compile(popup)(scope); - if(!scope.$$phase) scope.$digest(); + if(!scope.$$phase) { + scope.$digest(); + } var newPopupHTML = ''; for(i = 0; i < popup.length; i++) { diff --git a/dist/angular-mapbox.min.js b/dist/angular-mapbox.min.js index 7d4c280..1e77760 100644 --- a/dist/angular-mapbox.min.js +++ b/dist/angular-mapbox.min.js @@ -1 +1 @@ -!function(){"use strict";angular.module("angular-mapbox",[])}(),function(){"use strict";function mapboxService(){function init(opts){if(!opts.accessToken)throw"MissingMapboxApiToken";L.mapbox.accessToken=opts.accessToken}function addMapInstance(map,mapOptions){mapOptions=mapOptions||{},_mapInstances.push(map),_mapOptions.push(mapOptions),_markers.push([])}function getMapInstances(){return _mapInstances}function addMarker(marker){var map=getMapInstances()[0];_markers[0].push(marker);var opts=getOptionsForMap(map);opts.scaleToFit&&fitMapToMarkers(map)}function debounce(func,wait,immediate){var timeout;return function(){var context=this,args=arguments,later=function(){timeout=null,immediate||func.apply(context,args)},callNow=immediate&&!timeout;clearTimeout(timeout),timeout=setTimeout(later,wait),callNow&&func.apply(context,args)}}function getMarkers(){return _markers[0]}function getOptionsForMap(){return _mapOptions[0]}var _mapInstances=[],_markers=[],_mapOptions=[],fitMapToMarkers=debounce(function(){var map=_mapInstances[0],group=new L.featureGroup(getMarkers());map.fitBounds(group.getBounds())},0),service={init:init,getMapInstances:getMapInstances,addMapInstance:addMapInstance,getMarkers:getMarkers,addMarker:addMarker,fitMapToMarkers:fitMapToMarkers};return service}angular.module("angular-mapbox").service("mapboxService",mapboxService)}(),function(){"use strict";angular.module("angular-mapbox").directive("featureLayer",function(){return{restrict:"E",require:"^mapbox",link:function(scope,element,attrs,controller){attrs.data?controller.getMap().then(function(map){var geojsonObject=scope.$eval(attrs.data),featureLayer=L.mapbox.featureLayer(geojsonObject).addTo(map);controller.$scope.featureLayers.push(featureLayer)}):attrs.url&&controller.getMap().then(function(map){var featureLayer=L.mapbox.featureLayer().addTo(map);featureLayer.loadURL(attrs.url),controller.$scope.featureLayers.push(featureLayer)})}}})}(),function(){"use strict";angular.module("angular-mapbox").directive("mapbox",["$compile","$q","mapboxService",function($compile,$q,mapboxService){var _mapboxMap;return{restrict:"E",transclude:!0,scope:!0,replace:!0,link:function(scope,element,attrs){scope.map=L.mapbox.map(element[0],attrs.mapId),_mapboxMap.resolve(scope.map);var mapOptions={clusterMarkers:void 0!==attrs.clusterMarkers,scaleToFit:void 0!==attrs.scaleToFit};mapboxService.addMapInstance(scope.map,mapOptions);var mapWidth=attrs.width||500,mapHeight=attrs.height||500;element.css("width",mapWidth+"px"),element.css("height",mapHeight+"px");var zoom=attrs.zoom||12;attrs.lat&&attrs.lng&&scope.map.setView([attrs.lat,attrs.lng],zoom),scope.isClusteringMarkers=void 0!==attrs.clusterMarkers,attrs.onReposition&&scope.map.on("dragend",function(){scope[attrs.onReposition](scope.map.getBounds())}),attrs.onZoom&&scope.map.on("zoomend",function(){scope[attrs.onZoom](scope.map.getBounds())})},template:'
',controller:["$scope","mapboxService",function($scope,mapboxService){$scope.markers=mapboxService.getMarkers(),$scope.featureLayers=[],_mapboxMap=$q.defer(),$scope.getMap=this.getMap=function(){return _mapboxMap.promise},L.MarkerClusterGroup&&($scope.clusterGroup=new L.MarkerClusterGroup,this.getMap().then(function(map){map.addLayer($scope.clusterGroup)})),this.$scope=$scope}]}}])}(),function(){"use strict";angular.module("angular-mapbox").directive("marker",["$compile","mapboxService",function($compile,mapboxService){var _colors={navy:"#001f3f",blue:"#0074d9",aqua:"#7fdbff",teal:"#39cccc",olive:"#3d9970",green:"#2ecc40",lime:"#01ff70",yellow:"#ffdc00",orange:"#ff851b",red:"#ff4136",fuchsia:"#f012be",purple:"#b10dc9",maroon:"#85144b",white:"white",silver:"#dddddd",gray:"#aaaaaa",black:"#111111"};return{restrict:"E",require:"^mapbox",transclude:!0,scope:!0,link:function(scope,element,attrs,controller,transclude){function setStyleOptions(attrs,default_opts){var opts=default_opts||{};return attrs.size&&(opts["marker-size"]=attrs.size),attrs.color&&(opts["marker-color"]="#"===attrs.color[0]?attrs.color:_colors[attrs.color]||attrs.color),attrs.icon&&(opts["marker-symbol"]=attrs.icon),opts}var marker,opts={draggable:void 0!==attrs.draggable},style=setStyleOptions(attrs),addMarker=function(map,latlng,popupContent,opts,style){opts=opts||{};var marker=L.mapbox.marker.style({properties:style},latlng);return popupContent&&popupContent.length>0&&marker.bindPopup(popupContent),controller.$scope.isClusteringMarkers&&opts.excludeFromClustering!==!0?controller.$scope.clusterGroup.addLayer(marker):marker.addTo(map),opts.draggable&&marker.dragging.enable(),mapboxService.addMarker(marker),marker},addCurrentLocation=function(map,popupContent,opts,style){style=setStyleOptions(style,{"marker-color":"#000","marker-symbol":"star"}),opts.excludeFromClustering=!0,map.on("locationfound",function(e){marker=addMarker(map,[e.latlng.lat,e.latlng.lng],null,opts,style)}),map.locate()};controller.getMap().then(function(map){map.on("popupopen",function(){var popup=angular.element(document.getElementsByClassName("leaflet-popup-content"));$compile(popup)(scope),scope.$$phase||scope.$digest()}),setTimeout(function(){for(var popupHTML="",transcluded=transclude(scope,function(){}),i=0;i