Skip to content
This repository was archived by the owner on Nov 7, 2023. It is now read-only.

Commit 519165f

Browse files
committed
Merge pull request tombatossals#821 from realtymaps/dev/nem/iisue_611
markers fixes
2 parents d39b9c8 + 7174aa3 commit 519165f

10 files changed

+144
-139
lines changed

dist/angular-leaflet-directive.js

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ angular.module("leaflet-directive", []).directive('leaflet',
4343
link: function(scope, element, attrs, ctrl) {
4444
var isDefined = leafletHelpers.isDefined,
4545
defaults = leafletMapDefaults.setDefaults(scope.defaults, attrs.id),
46-
genDispatchMapEvent = leafletEvents.genDispatchMapEvent,
47-
mapEvents = leafletEvents.getAvailableMapEvents();
46+
mapEvents = leafletEvents.getAvailableMapEvents(),
47+
addEvents = leafletEvents.addEvents;
4848

4949
scope.mapId = attrs.id;
5050
leafletData.setDirectiveControls({}, attrs.id);
@@ -132,12 +132,7 @@ angular.module("leaflet-directive", []).directive('leaflet',
132132
// if no event-broadcast attribute, all events are broadcasted
133133
if (!isDefined(attrs.eventBroadcast)) {
134134
var logic = "broadcast";
135-
for (var i = 0; i < mapEvents.length; i++) {
136-
var eventName = mapEvents[i];
137-
map.on(eventName, genDispatchMapEvent(scope, eventName, logic), {
138-
eventName: eventName
139-
});
140-
}
135+
addEvents(map, mapEvents, "eventName", scope, logic);
141136
}
142137

143138
// Resolve the map object to the promises
@@ -423,14 +418,25 @@ angular.module("leaflet-directive")
423418
}]);
424419

425420
angular.module("leaflet-directive").factory('leafletEvents',
426-
["leafletMapEvents", "leafletMarkerEvents", "leafletPathEvents", function (leafletMapEvents, leafletMarkerEvents, leafletPathEvents) {
427-
//NOTE THIS SHOULD BE DEPRECATED infavor of getting a specific events helper
428-
return angular.extend({},
421+
["leafletMapEvents", "leafletMarkerEvents", "leafletPathEvents", "leafletIterators", function (leafletMapEvents, leafletMarkerEvents, leafletPathEvents, leafletIterators) {
422+
//NOTE THIS SHOULD BE DEPRECATED infavor of getting a specific events helper
423+
var instance = angular.extend({},
429424
leafletMapEvents, {
430425
bindMarkerEvents: leafletMarkerEvents.bindEvents,
431426
getAvailableMarkerEvents: leafletMarkerEvents.getAvailableEvents
432-
},
433-
leafletPathEvents);
427+
}, leafletPathEvents);
428+
429+
var genDispatchMapEvent = instance.genDispatchMapEvent;
430+
431+
instance.addEvents = function(map, mapEvents, contextName, scope, logic){
432+
leafletIterators.each(mapEvents, function(eventName) {
433+
var context = {};
434+
context[contextName] = eventName;
435+
map.on(eventName, genDispatchMapEvent(scope, eventName, logic), context);
436+
});
437+
};
438+
439+
return instance;
434440
}]);
435441

436442
angular.module("leaflet-directive")
@@ -2811,7 +2817,8 @@ angular.module("leaflet-directive").directive('center',
28112817
safeApply = leafletHelpers.safeApply,
28122818
isValidCenter = leafletHelpers.isValidCenter,
28132819
isValidBounds = leafletBoundsHelpers.isValidBounds,
2814-
isUndefinedOrEmpty = leafletHelpers.isUndefinedOrEmpty;
2820+
isUndefinedOrEmpty = leafletHelpers.isUndefinedOrEmpty,
2821+
errorHeader = leafletHelpers.errorHeader;
28152822

28162823
var shouldInitializeMapWithBounds = function(bounds, center) {
28172824
return isDefined(bounds) && isValidBounds(bounds) && isUndefinedOrEmpty(center);
@@ -2837,7 +2844,7 @@ angular.module("leaflet-directive").directive('center',
28372844
var defaults = leafletMapDefaults.getDefaults(attrs.id);
28382845

28392846
if (attrs.center.search("-") !== -1) {
2840-
$log.error('The "center" variable can\'t use a "-" on his key name: "' + attrs.center + '".');
2847+
$log.error(errorHeader + ' The "center" variable can\'t use a "-" on his key name: "' + attrs.center + '".');
28412848
map.setView([defaults.center.lat, defaults.center.lng], defaults.center.zoom);
28422849
return;
28432850
} else if (shouldInitializeMapWithBounds(leafletScope.bounds, centerModel)) {
@@ -2871,7 +2878,7 @@ angular.module("leaflet-directive").directive('center',
28712878
};
28722879
});
28732880
} else if (!isDefined(centerModel)) {
2874-
$log.error('The "center" property is not defined in the main scope');
2881+
$log.error(errorHeader + ' The "center" property is not defined in the main scope');
28752882
map.setView([defaults.center.lat, defaults.center.lng], defaults.center.zoom);
28762883
return;
28772884
} else if (!(isDefined(centerModel.lat) && isDefined(centerModel.lng)) && !isDefined(centerModel.autoDiscover)) {
@@ -2917,7 +2924,7 @@ angular.module("leaflet-directive").directive('center',
29172924
}
29182925

29192926
if (!isValidCenter(center) && center.autoDiscover !== true) {
2920-
$log.warn("[AngularJS - Leaflet] invalid 'center'");
2927+
$log.warn(errorHeader + " invalid 'center'");
29212928
//map.setView([defaults.center.lat, defaults.center.lng], defaults.center.zoom);
29222929
return;
29232930
}
@@ -2955,7 +2962,7 @@ angular.module("leaflet-directive").directive('center',
29552962
mapReady = true;
29562963
});
29572964

2958-
map.on("moveend", function(/* event */) {
2965+
map.on('moveend', function(/* event */) {
29592966
// Resolve the center after the first map position
29602967
_leafletCenter.resolve();
29612968
leafletEvents.notifyCenterUrlHashChanged(leafletScope, map, attrs, $location.search());
@@ -2967,21 +2974,20 @@ angular.module("leaflet-directive").directive('center',
29672974
safeApply(leafletScope, function(scope) {
29682975
if (!leafletScope.settingCenterFromScope) {
29692976
//$log.debug("updating center model...", map.getCenter(), map.getZoom());
2970-
29712977
angular.extend(scope.center,{
2972-
lat: map.getCenter().lat,
2973-
lng: map.getCenter().lng,
2974-
zoom: map.getZoom(),
2975-
autoDiscover: false
2978+
lat: map.getCenter().lat,
2979+
lng: map.getCenter().lng,
2980+
zoom: map.getZoom(),
2981+
autoDiscover: false
29762982
});
29772983
}
29782984
leafletEvents.notifyCenterChangedToBounds(leafletScope, map);
29792985
});
29802986
});
29812987

29822988
if (centerModel.autoDiscover === true) {
2983-
map.on("locationerror", function() {
2984-
$log.warn("[AngularJS - Leaflet] The Geolocation API is unauthorized on this page.");
2989+
map.on('locationerror', function() {
2990+
$log.warn(errorHeader + " The Geolocation API is unauthorized on this page.");
29852991
if (isValidCenter(centerModel)) {
29862992
map.setView([centerModel.lat, centerModel.lng], centerModel.zoom);
29872993
leafletEvents.notifyCenterChangedToBounds(leafletScope, map);
@@ -3148,7 +3154,7 @@ angular.module("leaflet-directive").directive("decorations", ["$log", "leafletHe
31483154
};
31493155
}]);
31503156

3151-
angular.module("leaflet-directive").directive('eventBroadcast', ["$log", "$rootScope", "leafletHelpers", "leafletEvents", function ($log, $rootScope, leafletHelpers, leafletEvents) {
3157+
angular.module("leaflet-directive").directive('eventBroadcast', ["$log", "$rootScope", "leafletHelpers", "leafletEvents", "leafletIterators", function ($log, $rootScope, leafletHelpers, leafletEvents, leafletIterators) {
31523158
return {
31533159
restrict: "A",
31543160
scope: false,
@@ -3161,14 +3167,12 @@ angular.module("leaflet-directive").directive('eventBroadcast', ["$log", "$rootS
31613167
leafletScope = controller.getLeafletScope(),
31623168
eventBroadcast = leafletScope.eventBroadcast,
31633169
availableMapEvents = leafletEvents.getAvailableMapEvents(),
3164-
genDispatchMapEvent = leafletEvents.genDispatchMapEvent;
3170+
addEvents = leafletEvents.addEvents;
31653171

31663172
controller.getMap().then(function(map) {
31673173

3168-
var mapEvents = [];
3169-
var i;
3170-
var eventName;
3171-
var logic = "broadcast";
3174+
var mapEvents = [],
3175+
logic = "broadcast";
31723176

31733177
// We have a possible valid object
31743178
if (!isDefined(eventBroadcast.map)) {
@@ -3191,23 +3195,18 @@ angular.module("leaflet-directive").directive('eventBroadcast', ["$log", "$rootS
31913195
$log.warn("[AngularJS - Leaflet] event-broadcast.map.enable must be an object check your model.");
31923196
} else {
31933197
// Enable events
3194-
for (i = 0; i < eventBroadcast.map.enable.length; i++) {
3195-
eventName = eventBroadcast.map.enable[i];
3198+
leafletIterators.each(eventBroadcast.map.enable, function(eventName) {
31963199
// Do we have already the event enabled?
31973200
if (mapEvents.indexOf(eventName) === -1 && availableMapEvents.indexOf(eventName) !== -1) {
31983201
mapEvents.push(eventName);
31993202
}
3200-
}
3203+
});
32013204
}
32023205

32033206
}
3204-
3205-
for (i = 0; i < mapEvents.length; i++) {
3206-
eventName = mapEvents[i];
3207-
map.on(eventName, genDispatchMapEvent(leafletScope, eventName, logic), {
3208-
eventName: eventName
3209-
});
3210-
}
3207+
// as long as the map is removed in the root leaflet directive we
3208+
// do not need ot clean up the events as leaflet does it itself
3209+
addEvents(map, mapEvents, "eventName", leafletScope, logic);
32113210
});
32123211
}
32133212
};
@@ -4047,7 +4046,8 @@ angular.module("leaflet-directive").directive('markers',
40474046
leafletMarkerEvents.bindEvents(marker, pathToMarker, model, leafletScope, layerName);
40484047
}
40494048
else {
4050-
updateMarker(model, oldModels[newName], maybeLMarker, pathToMarker, leafletScope, layers, map);
4049+
var oldModel = isDefined(oldModel)? oldModels[newName] : undefined;
4050+
updateMarker(model, oldModel, maybeLMarker, pathToMarker, leafletScope, layers, map);
40514051
}
40524052
}
40534053
};
@@ -4137,7 +4137,8 @@ angular.module("leaflet-directive").directive('markers',
41374137
var _clean = function(models, oldModels){
41384138
if(isNested) {
41394139
$it.each(models, function(markerToMaybeDel, layerName) {
4140-
_destroy(markerToMaybeDel, oldModels[layerName], leafletMarkers[layerName], map, layers);
4140+
var oldModel = isDefined(oldModel)? oldModels[layerName] : undefined;
4141+
_destroy(markerToMaybeDel, oldModel, leafletMarkers[layerName], map, layers);
41414142
});
41424143
return;
41434144
}
@@ -4149,7 +4150,8 @@ angular.module("leaflet-directive").directive('markers',
41494150
var skips = null;
41504151
if(isNested) {
41514152
$it.each(models, function(markersToAdd, layerName) {
4152-
skips = _getNewModelsToSkipp(models[layerName], oldModels[layerName], leafletMarkers[layerName]);
4153+
var oldModel = isDefined(oldModel)? oldModels[layerName] : undefined;
4154+
skips = _getNewModelsToSkipp(models[layerName], oldModel, leafletMarkers[layerName]);
41534155
_addMarkers(markersToAdd, oldModels, map, layers, leafletMarkers, leafletScope,
41544156
watchOptions, layerName, skips);
41554157
});
@@ -4616,7 +4618,7 @@ angular.module("leaflet-directive")
46164618
return EventsHelper;
46174619
}])
46184620
.service('leafletEventsHelpers', ["leafletEventsHelpersFactory", function(leafletEventsHelpersFactory){
4619-
return new leafletEventsHelpersFactory();
4621+
return new leafletEventsHelpersFactory();
46204622
}]);
46214623

46224624
angular.module("leaflet-directive")

dist/angular-leaflet-directive.min.js

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

0 commit comments

Comments
 (0)