Skip to content

Commit

Permalink
Replace expensive GeoJSON copy with watch trap
Browse files Browse the repository at this point in the history
Derived from original commit:

Commit: 936c39c [936c39c]
Parents: f142ead
Author: Nick McCready <nmccready@gmail.com>
Date: 19 November 2015 at 04:34:17 GMT+2
Commit Date: 19 November 2015 at 05:40:15 GMT+2

issue angular-ui#19
fix(geojson clone removed): geojson clone removed infavor of watch
trapp. This should speed geojson up.
  • Loading branch information
kherrala committed Aug 28, 2016
1 parent b4ffbbe commit 2380f78
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/directives/geojson.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
angular.module('ui-leaflet')
.directive('geojson', function (leafletLogger, $rootScope, leafletData, leafletHelpers,
.directive('geojson', function ($rootScope, $timeout,
leafletLogger, leafletData, leafletHelpers,
leafletWatchHelpers, leafletDirectiveControlsHelpers,leafletIterators, leafletGeoJsonEvents) {
var _maybeWatch = leafletWatchHelpers.maybeWatch,
_watchOptions = leafletHelpers.watchOptions,
_extendDirectiveControls = leafletDirectiveControlsHelpers.extend,
hlp = leafletHelpers,
watchTrap = {changeFromDirective: false},
$it = leafletIterators;
// $log = leafletLogger;

Expand Down Expand Up @@ -63,8 +65,7 @@ angular.module('ui-leaflet')
_remove(leafletGeoJSON);
};

var _addGeojson = function(model, maybeName){
var geojson = angular.copy(model);
var _addGeojson = function(geojson, maybeName){
if (!(isDefined(geojson) && isDefined(geojson.data))) {
return;
}
Expand All @@ -74,12 +75,18 @@ angular.module('ui-leaflet')
//right here is why we use a clone / copy (we modify and thus)
//would kick of a watcher.. we need to be more careful everywhere
//for stuff like this
watchTrap.changeFromDirective = true;

geojson.options = {
style: geojson.style,
filter: geojson.filter,
onEachFeature: onEachFeature,
pointToLayer: geojson.pointToLayer
};

$timeout(function () {
watchTrap.changeFromDirective = false;
}, 10);
}

var lObject = L.geoJson(geojson.data, geojson.options);
Expand Down Expand Up @@ -117,6 +124,8 @@ angular.module('ui-leaflet')
_extendDirectiveControls(attrs.id, 'geojson', _create, _clean);

_maybeWatch(leafletScope,'geojson', watchOptions, function(geojson){
if(watchTrap.changeFromDirective)
return;
_create(geojson);
});
});
Expand Down

0 comments on commit 2380f78

Please sign in to comment.