Skip to content
This repository was archived by the owner on Sep 20, 2019. It is now read-only.

Commit 9acabbd

Browse files
committed
Merge with original
2 parents 78b498e + e0978f8 commit 9acabbd

File tree

10 files changed

+133
-14
lines changed

10 files changed

+133
-14
lines changed

dist/ui-leaflet.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* ui-leaflet 1.0.0 2016-06-24
2+
* ui-leaflet 1.0.0 2016-08-19
33
* ui-leaflet - An AngularJS directive to easily interact with Leaflet maps
44
* git: https://github.com/angular-ui/ui-leaflet
55
*/
@@ -502,6 +502,10 @@ angular.module('ui-leaflet').factory('leafletControlHelpers', ["$rootScope", "le
502502
map.addControl(_layersControl);
503503
}
504504
return mustBeLoaded;
505+
},
506+
507+
destroyMapLayersControl: function destroyMapLayersControl(mapId) {
508+
delete _controls[mapId];
505509
}
506510
};
507511
}]);
@@ -2319,10 +2323,12 @@ angular.module('ui-leaflet').service('leafletMarkersHelpers', ["$rootScope", "$t
23192323
if (!DomMarkersPlugin.isLoaded()) {
23202324
$log.error(errorHeader + 'The DomMarkers Plugin is not loaded.');
23212325
}
2322-
var markerScope = angular.isFunction(iconData.getMarkerScope) ? iconData.getMarkerScope() : $rootScope,
2326+
var markerScope = angular.isFunction(iconData.getMarkerScope) ? iconData.getMarkerScope().$new() : $rootScope,
23232327
template = $compile(iconData.template)(markerScope),
23242328
iconDataCopy = angular.copy(iconData);
2329+
iconDataCopy.ngElement = template;
23252330
iconDataCopy.element = template[0];
2331+
if (angular.isFunction(iconData.getMarkerScope)) iconDataCopy.scope = markerScope;
23262332
return new L.DomMarkers.icon(iconDataCopy);
23272333
}
23282334

@@ -2366,8 +2372,23 @@ angular.module('ui-leaflet').service('leafletMarkersHelpers', ["$rootScope", "$t
23662372
}
23672373
};
23682374

2375+
var _cleanDomIcon = function _cleanDomIcon(marker) {
2376+
if (marker.options.icon.options.ngElement) {
2377+
marker.options.icon.options.ngElement.remove();
2378+
}
2379+
if (marker.options.icon.options.scope) {
2380+
marker.options.icon.options.scope.$destroy();
2381+
}
2382+
};
2383+
23692384
var _deleteMarker = function _deleteMarker(marker, map, layers) {
23702385
marker.closePopup();
2386+
2387+
// if it's a dom icon, clean it
2388+
if (marker.options.icon && marker.options.icon.options && marker.options.icon.options.type === 'dom') {
2389+
_cleanDomIcon(marker);
2390+
}
2391+
23712392
// There is no easy way to know if a marker is added to a layer, so we search for it
23722393
// if there are overlays
23732394
if (isDefined(layers) && isDefined(layers.overlays)) {
@@ -2561,6 +2582,10 @@ angular.module('ui-leaflet').service('leafletMarkersHelpers', ["$rootScope", "$t
25612582
if (!isObject(markerData.icon)) {
25622583
// If there is no icon property or it's not an object
25632584
if (isObject(oldMarkerData.icon)) {
2585+
if (oldMarkerData.icon.type === 'dom') {
2586+
// clean previous icon if it's a dom one
2587+
_cleanDomIcon(marker);
2588+
}
25642589
// If there was an icon before restore to the default
25652590
marker.setIcon(createLeafletIcon());
25662591
marker.closePopup();
@@ -2576,6 +2601,10 @@ angular.module('ui-leaflet').service('leafletMarkersHelpers', ["$rootScope", "$t
25762601
if (marker.dragging) {
25772602
dragG = marker.dragging.enabled();
25782603
}
2604+
if (oldMarkerData.icon.type === 'dom') {
2605+
// clean previous icon if it's a dom one
2606+
_cleanDomIcon(marker);
2607+
}
25792608
marker.setIcon(createLeafletIcon(markerData.icon));
25802609
if (dragG) {
25812610
marker.dragging.enable();
@@ -3450,6 +3479,10 @@ angular.module('ui-leaflet').directive('controls', ["leafletLogger", "leafletHel
34503479
var leafletControls = {};
34513480
var errorHeader = leafletHelpers.errorHeader + ' [Controls] ';
34523481

3482+
scope.$on('$destroy', function () {
3483+
leafletControlHelpers.destroyMapLayersControl(scope.mapId);
3484+
});
3485+
34533486
controller.getMap().then(function (map) {
34543487

34553488
leafletScope.$watchCollection('controls', function (newControls) {
@@ -3998,6 +4031,10 @@ angular.module('ui-leaflet').directive('layers', ["leafletLogger", "$q", "leafle
39984031
updateLayersControl = leafletControlHelpers.updateLayersControl,
39994032
isLayersControlVisible = false;
40004033

4034+
scope.$on('$destroy', function () {
4035+
leafletControlHelpers.destroyMapLayersControl(scope.mapId);
4036+
});
4037+
40014038
controller.getMap().then(function (map) {
40024039

40034040
// We have baselayers to add to the map
@@ -4582,6 +4619,9 @@ angular.module('ui-leaflet').directive('markers', ["leafletLogger", "$rootScope"
45824619
if (watchTrap.changeFromDirective) return;
45834620
_create(newMarkers, oldMarkers);
45844621
});
4622+
scope.$on('$destroy', function () {
4623+
_destroy(leafletScope.markers, {}, leafletMarkers, map, layers);
4624+
});
45854625
});
45864626
});
45874627
}

dist/ui-leaflet.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ui-leaflet.min.no-header.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ui-leaflet_dev_mapped.js

Lines changed: 42 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ui-leaflet_dev_mapped.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/directives/controls.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ angular.module('ui-leaflet').directive('controls', function (leafletLogger, leaf
1919
var leafletControls = {};
2020
var errorHeader = leafletHelpers.errorHeader + ' [Controls] ';
2121

22+
scope.$on('$destroy', function () {
23+
leafletControlHelpers.destroyMapLayersControl(scope.mapId);
24+
});
25+
2226
controller.getMap().then(function(map) {
2327

2428
leafletScope.$watchCollection('controls', function(newControls) {

src/directives/layers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ angular.module('ui-leaflet').directive('layers', function (leafletLogger, $q, le
2323
updateLayersControl = leafletControlHelpers.updateLayersControl,
2424
isLayersControlVisible = false;
2525

26+
scope.$on('$destroy', function () {
27+
leafletControlHelpers.destroyMapLayersControl(scope.mapId);
28+
});
29+
2630
controller.getMap().then(function(map) {
2731

2832
// We have baselayers to add to the map

src/directives/markers.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ angular.module('ui-leaflet').directive('markers',
269269
return;
270270
_create(newMarkers, oldMarkers);
271271
});
272+
scope.$on('$destroy', function () {
273+
_destroy(leafletScope.markers, {}, leafletMarkers, map, layers);
274+
});
272275
});
273276
});
274277
}

src/services/leafletControlHelpers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ angular.module('ui-leaflet').factory('leafletControlHelpers', function ($rootSco
194194
map.addControl(_layersControl);
195195
}
196196
return mustBeLoaded;
197+
},
198+
199+
destroyMapLayersControl: function(mapId) {
200+
delete _controls[mapId];
197201
}
198202
};
199203
});

src/services/leafletMarkersHelpers.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,13 @@ angular.module('ui-leaflet').service('leafletMarkersHelpers', function ($rootSco
7676
if (!DomMarkersPlugin.isLoaded()) {
7777
$log.error(errorHeader + 'The DomMarkers Plugin is not loaded.');
7878
}
79-
var markerScope = angular.isFunction(iconData.getMarkerScope) ? iconData.getMarkerScope() : $rootScope,
79+
var markerScope = angular.isFunction(iconData.getMarkerScope) ? iconData.getMarkerScope().$new() : $rootScope,
8080
template = $compile(iconData.template)(markerScope),
8181
iconDataCopy = angular.copy(iconData);
82+
iconDataCopy.ngElement = template;
8283
iconDataCopy.element = template[0];
84+
if(angular.isFunction(iconData.getMarkerScope))
85+
iconDataCopy.scope = markerScope;
8386
return new L.DomMarkers.icon(iconDataCopy);
8487
}
8588

@@ -123,8 +126,23 @@ angular.module('ui-leaflet').service('leafletMarkersHelpers', function ($rootSco
123126
}
124127
};
125128

129+
var _cleanDomIcon = function _cleanDomIcon(marker) {
130+
if( marker.options.icon.options.ngElement) {
131+
marker.options.icon.options.ngElement.remove();
132+
}
133+
if( marker.options.icon.options.scope) {
134+
marker.options.icon.options.scope.$destroy();
135+
}
136+
};
137+
126138
var _deleteMarker = function (marker, map, layers) {
127139
marker.closePopup();
140+
141+
// if it's a dom icon, clean it
142+
if(marker.options.icon && marker.options.icon.options && marker.options.icon.options.type === 'dom') {
143+
_cleanDomIcon(marker);
144+
}
145+
128146
// There is no easy way to know if a marker is added to a layer, so we search for it
129147
// if there are overlays
130148
if (isDefined(layers) && isDefined(layers.overlays)) {
@@ -319,6 +337,9 @@ angular.module('ui-leaflet').service('leafletMarkersHelpers', function ($rootSco
319337
if (!isObject(markerData.icon)) {
320338
// If there is no icon property or it's not an object
321339
if (isObject(oldMarkerData.icon)) {
340+
if(oldMarkerData.icon.type === 'dom') { // clean previous icon if it's a dom one
341+
_cleanDomIcon(marker);
342+
}
322343
// If there was an icon before restore to the default
323344
marker.setIcon(createLeafletIcon());
324345
marker.closePopup();
@@ -334,6 +355,9 @@ angular.module('ui-leaflet').service('leafletMarkersHelpers', function ($rootSco
334355
if (marker.dragging) {
335356
dragG = marker.dragging.enabled();
336357
}
358+
if(oldMarkerData.icon.type === 'dom') { // clean previous icon if it's a dom one
359+
_cleanDomIcon(marker);
360+
}
337361
marker.setIcon(createLeafletIcon(markerData.icon));
338362
if (dragG) {
339363
marker.dragging.enable();

0 commit comments

Comments
 (0)