11/*!
2- * ui-leaflet 1.0.0 2016-07-18
2+ * ui-leaflet 1.0.0 2016-08-22
33* ui-leaflet - An AngularJS directive to easily interact with Leaflet maps
44* git: https://github.com/angular-ui/ui-leaflet
55*/
@@ -26,7 +26,8 @@ angular.module('ui-leaflet', ['nemLogging']).directive('leaflet', ["$q", "leafle
2626 controls : '=' ,
2727 decorations : '=' ,
2828 eventBroadcast : '=' ,
29- watchOptions : '='
29+ watchOptions : '=' ,
30+ id : '@'
3031 } ,
3132 transclude : true ,
3233 template : '<div class="angular-leaflet-map"><div ng-transclude></div></div>' ,
@@ -124,7 +125,7 @@ angular.module('ui-leaflet', ['nemLogging']).directive('leaflet', ["$q", "leafle
124125 // if no event-broadcast attribute, all events are broadcasted
125126 if ( ! isDefined ( attrs . eventBroadcast ) ) {
126127 var logic = "broadcast" ;
127- addEvents ( map , mapEvents , "eventName" , scope , logic ) ;
128+ addEvents ( map , attrs . id , mapEvents , "eventName" , scope , logic ) ;
128129 }
129130
130131 // Resolve the map object to the promises
@@ -502,6 +503,10 @@ angular.module('ui-leaflet').factory('leafletControlHelpers', ["$rootScope", "le
502503 map . addControl ( _layersControl ) ;
503504 }
504505 return mustBeLoaded ;
506+ } ,
507+
508+ destroyMapLayersControl : function destroyMapLayersControl ( mapId ) {
509+ delete _controls [ mapId ] ;
505510 }
506511 } ;
507512} ] ) ;
@@ -1385,7 +1390,7 @@ angular.module('ui-leaflet').service('leafletIterators', ["leafletLogger", "leaf
13851390 // `key:value` pairs.
13861391 var _matcher ,
13871392 _matches = null ;
1388- _matcher = _matches = function ( attrs ) {
1393+ _matcher = _matches = function _matches ( attrs ) {
13891394 attrs = _extendOwn ( { } , attrs ) ;
13901395 return function ( obj ) {
13911396 return _isMatch ( obj , attrs ) ;
@@ -1404,7 +1409,7 @@ angular.module('ui-leaflet').service('leafletIterators', ["leafletLogger", "leaf
14041409
14051410 var _every ,
14061411 _all = null ;
1407- _every = _all = function ( obj , predicate , context ) {
1412+ _every = _all = function _all ( obj , predicate , context ) {
14081413 predicate = cb ( predicate , context ) ;
14091414 var keys = ! _isArrayLike ( obj ) && _keys ( obj ) ,
14101415 length = ( keys || obj ) . length ;
@@ -3475,6 +3480,10 @@ angular.module('ui-leaflet').directive('controls', ["leafletLogger", "leafletHel
34753480 var leafletControls = { } ;
34763481 var errorHeader = leafletHelpers . errorHeader + ' [Controls] ' ;
34773482
3483+ scope . $on ( '$destroy' , function ( ) {
3484+ leafletControlHelpers . destroyMapLayersControl ( scope . mapId ) ;
3485+ } ) ;
3486+
34783487 controller . getMap ( ) . then ( function ( map ) {
34793488
34803489 leafletScope . $watchCollection ( 'controls' , function ( newControls ) {
@@ -3640,7 +3649,7 @@ angular.module('ui-leaflet').directive('eventBroadcast', ["leafletLogger", "$roo
36403649 }
36413650 // as long as the map is removed in the root leaflet directive we
36423651 // do not need ot clean up the events as leaflet does it itself
3643- addEvents ( map , mapEvents , "eventName" , leafletScope , logic ) ;
3652+ addEvents ( map , attrs . id , mapEvents , "eventName" , leafletScope , logic ) ;
36443653 } ) ;
36453654 }
36463655 } ;
@@ -3683,7 +3692,7 @@ angular.module('ui-leaflet').directive('geojson', ["$timeout", "leafletLogger",
36833692 if ( angular . isFunction ( geojson . onEachFeature ) ) {
36843693 onEachFeature = geojson . onEachFeature ;
36853694 } else {
3686- onEachFeature = function ( feature , layer ) {
3695+ onEachFeature = function onEachFeature ( feature , layer ) {
36873696 if ( leafletHelpers . LabelPlugin . isLoaded ( ) && isDefined ( feature . properties . description ) ) {
36883697 layer . bindLabel ( feature . properties . description ) ;
36893698 }
@@ -3946,7 +3955,7 @@ angular.module('ui-leaflet').directive('layercontrol', ["$filter", "leafletLogge
39463955 leafletScope . $watch ( 'layers.overlays' , function ( newOverlayLayers ) {
39473956 var overlaysArray = [ ] ;
39483957 var groupVisibleCount = { } ;
3949- leafletData . getLayers ( ) . then ( function ( leafletLayers ) {
3958+ leafletData . getLayers ( ) . then ( function ( ) {
39503959 var key ;
39513960 for ( key in newOverlayLayers ) {
39523961 var layer = newOverlayLayers [ key ] ;
@@ -3978,9 +3987,11 @@ angular.module('ui-leaflet').directive('layercontrol', ["$filter", "leafletLogge
39783987 groupVisibleCount [ layer . group ] . visibles ++ ;
39793988 }
39803989 }
3981- if ( isDefined ( layer . index ) && leafletLayers . overlays [ key ] . setZIndex ) {
3990+ /*
3991+ if(isDefined(layer.index) && leafletLayers.overlays[key].setZIndex) {
39823992 leafletLayers.overlays[key].setZIndex(newOverlayLayers[key].index);
39833993 }
3994+ */
39843995 }
39853996
39863997 for ( key in groupVisibleCount ) {
@@ -4021,6 +4032,10 @@ angular.module('ui-leaflet').directive('layers', ["leafletLogger", "$q", "leafle
40214032 updateLayersControl = leafletControlHelpers . updateLayersControl ,
40224033 isLayersControlVisible = false ;
40234034
4035+ scope . $on ( '$destroy' , function ( ) {
4036+ leafletControlHelpers . destroyMapLayersControl ( scope . mapId ) ;
4037+ } ) ;
4038+
40244039 controller . getMap ( ) . then ( function ( map ) {
40254040
40264041 // We have baselayers to add to the map
@@ -4164,6 +4179,10 @@ angular.module('ui-leaflet').directive('layers', ["leafletLogger", "$q", "leafle
41644179 if ( newOverlayLayers [ newName ] . visible === true ) {
41654180 safeAddLayer ( map , leafletLayers . overlays [ newName ] ) ;
41664181 }
4182+
4183+ if ( isDefined ( newOverlayLayers [ newName ] . index ) && leafletLayers . overlays [ newName ] . setZIndex ) {
4184+ leafletLayers . overlays [ newName ] . setZIndex ( newOverlayLayers [ newName ] . index ) ;
4185+ }
41674186 } else {
41684187 // check for the .visible property to hide/show overLayers
41694188 if ( newOverlayLayers [ newName ] . visible && ! map . hasLayer ( leafletLayers . overlays [ newName ] ) ) {
@@ -4174,14 +4193,20 @@ angular.module('ui-leaflet').directive('layers', ["leafletLogger", "$q", "leafle
41744193 }
41754194
41764195 // check for the .layerOptions.opacity property has changed.
4177- if ( newOverlayLayers [ newName ] . layerOptions . opacity !== oldOverlayLayers [ newName ] . layerOptions . opacity && map . hasLayer ( leafletLayers . overlays [ newName ] ) ) {
4196+ var ly = leafletLayers . overlays [ newName ] ;
4197+ if ( map . hasLayer ( leafletLayers . overlays [ newName ] ) ) {
4198+ if ( newOverlayLayers [ newName ] . layerOptions . opacity !== oldOverlayLayers [ newName ] . layerOptions . opacity ) {
41784199
4179- var ly = leafletLayers . overlays [ newName ] ;
4180- if ( isDefined ( ly . setOpacity ) ) {
4181- ly . setOpacity ( newOverlayLayers [ newName ] . layerOptions . opacity ) ;
4200+ if ( isDefined ( ly . setOpacity ) ) {
4201+ ly . setOpacity ( newOverlayLayers [ newName ] . layerOptions . opacity ) ;
4202+ }
4203+ if ( isDefined ( ly . getLayers ) && isDefined ( ly . eachLayer ) ) {
4204+ ly . eachLayer ( changeOpacityListener ( newOverlayLayers [ newName ] . layerOptions . opacity ) ) ;
4205+ }
41824206 }
4183- if ( isDefined ( ly . getLayers ) && isDefined ( ly . eachLayer ) ) {
4184- ly . eachLayer ( changeOpacityListener ( newOverlayLayers [ newName ] . layerOptions . opacity ) ) ;
4207+
4208+ if ( isDefined ( newOverlayLayers [ newName ] . index ) && ly . setZIndex && newOverlayLayers [ newName ] . index !== oldOverlayLayers [ newName ] . index ) {
4209+ ly . setZIndex ( newOverlayLayers [ newName ] . index ) ;
41854210 }
41864211 }
41874212 }
@@ -4544,7 +4569,7 @@ angular.module('ui-leaflet').directive('markers', ["leafletLogger", "$rootScope"
45444569 if ( isDefined ( controller [ 1 ] ) ) {
45454570 getLayers = controller [ 1 ] . getLayers ;
45464571 } else {
4547- getLayers = function ( ) {
4572+ getLayers = function getLayers ( ) {
45484573 var deferred = $q . defer ( ) ;
45494574 deferred . resolve ( ) ;
45504575 return deferred . promise ;
@@ -4671,7 +4696,7 @@ angular.module('ui-leaflet').directive('paths', ["leafletLogger", "$q", "leaflet
46714696 if ( isDefined ( controller [ 1 ] ) ) {
46724697 getLayers = controller [ 1 ] . getLayers ;
46734698 } else {
4674- getLayers = function ( ) {
4699+ getLayers = function getLayers ( ) {
46754700 var deferred = $q . defer ( ) ;
46764701 deferred . resolve ( ) ;
46774702 return deferred . promise ;
@@ -5173,7 +5198,9 @@ angular.module('ui-leaflet').factory('leafletMapEvents', ["$rootScope", "$q", "l
51735198 } ;
51745199
51755200 var _genDispatchMapEvent = function _genDispatchMapEvent ( scope , eventName , logic , maybeMapId ) {
5176- if ( maybeMapId ) maybeMapId = maybeMapId + '.' ;
5201+ if ( maybeMapId ) {
5202+ maybeMapId = maybeMapId + '.' ;
5203+ }
51775204 return function ( e ) {
51785205 // Put together broadcast name
51795206 var broadcastName = 'leafletDirectiveMap.' + maybeMapId + eventName ;
@@ -5199,11 +5226,15 @@ angular.module('ui-leaflet').factory('leafletMapEvents', ["$rootScope", "$q", "l
51995226 }
52005227 } ;
52015228
5202- var _addEvents = function _addEvents ( map , mapEvents , contextName , scope , logic ) {
5229+ var _addEvents = function _addEvents ( map , mapId , mapEvents , contextName , scope , logic ) {
52035230 leafletIterators . each ( mapEvents , function ( eventName ) {
52045231 var context = { } ;
52055232 context [ contextName ] = eventName ;
5206- map . on ( eventName , _genDispatchMapEvent ( scope , eventName , logic , map . _container . id || '' ) , context ) ;
5233+ if ( ! mapId ) {
5234+ mapId = map . _container . id || '' ;
5235+ }
5236+
5237+ map . on ( eventName , _genDispatchMapEvent ( scope , eventName , logic , mapId ) , context ) ;
52075238 } ) ;
52085239 } ;
52095240
0 commit comments