diff --git a/src/directives/geojson.js b/src/directives/geojson.js index cf708975..e4b40f2d 100644 --- a/src/directives/geojson.js +++ b/src/directives/geojson.js @@ -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); } @@ -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) { @@ -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); + }); }); } };