Skip to content

Commit

Permalink
fix(geojson): Shallow watch of the geojson object to accomplish bette…
Browse files Browse the repository at this point in the history
…r performance, as stated by @facultymatt here:

#595
  • Loading branch information
tombatossals committed Jan 13, 2015
1 parent b4e803b commit c893a1a
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/directives/geojson.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ angular.module("leaflet-directive").directive('geojson', function ($log, $rootSc
leafletGeoJSON = {};

controller.getMap().then(function(map) {
leafletScope.$watch("geojson", function(geojson) {

leafletScope.$watchCollection("geojson", function(geojson) {
if (isDefined(leafletGeoJSON) && map.hasLayer(leafletGeoJSON)) {
map.removeLayer(leafletGeoJSON);
}
Expand All @@ -25,7 +24,7 @@ angular.module("leaflet-directive").directive('geojson', function ($log, $rootSc
var resetStyleOnMouseout = geojson.resetStyleOnMouseout;
var onEachFeature;

if (geojson.onEachFeature) {
if (angular.isFunction(geojson.onEachFeature)) {
onEachFeature = geojson.onEachFeature;
} else {
onEachFeature = function(feature, layer) {
Expand Down Expand Up @@ -56,18 +55,20 @@ angular.module("leaflet-directive").directive('geojson', function ($log, $rootSc
};
}

geojson.options = {
style: geojson.style,
filter: geojson.filter,
onEachFeature: onEachFeature,
pointToLayer: geojson.pointToLayer
};
if (!isDefined(geojson.options)) {
geojson.options = {
style: geojson.style,
filter: geojson.filter,
onEachFeature: onEachFeature,
pointToLayer: geojson.pointToLayer
};
}

leafletGeoJSON = L.geoJson(geojson.data, geojson.options);
leafletData.setGeoJSON(leafletGeoJSON, attrs.id);
leafletGeoJSON.addTo(map);

}, true);
});
});
}
};
Expand Down

0 comments on commit c893a1a

Please sign in to comment.