Skip to content

Commit bc89461

Browse files
committed
Added the leafletData.getGeoJSON promise
1 parent 04d5339 commit bc89461

File tree

5 files changed

+40
-10
lines changed

5 files changed

+40
-10
lines changed

dist/angular-leaflet-directive.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ angular.module("leaflet-directive").directive('legend', function ($log) {
496496
};
497497
});
498498

499-
angular.module("leaflet-directive").directive('geojson', function ($log, $rootScope) {
499+
angular.module("leaflet-directive").directive('geojson', function ($log, $rootScope, leafletData) {
500500
return {
501501
restrict: "A",
502502
scope: false,
@@ -506,7 +506,7 @@ angular.module("leaflet-directive").directive('geojson', function ($log, $rootSc
506506

507507
link: function($scope, element, attrs, controller) {
508508
var map = controller.getMap();
509-
var leafletGeoJSON;
509+
var leafletGeoJSON = {};
510510

511511
controller.getMap().then(function(map) {
512512
$scope.$watch("geojson", function(geojson) {
@@ -547,7 +547,9 @@ angular.module("leaflet-directive").directive('geojson', function ($log, $rootSc
547547
}
548548
});
549549
}
550-
}).addTo(map);
550+
});
551+
leafletData.setGeoJSON(leafletGeoJSON);
552+
leafletGeoJSON.addTo(map);
551553
}
552554
});
553555
});
@@ -1873,7 +1875,7 @@ angular.module("leaflet-directive").directive('maxbounds', function ($log) {
18731875
link: function($scope, element, attrs, controller) {
18741876
var defaults = parseMapDefaults($scope.defaults);
18751877
controller.getMap().then(function(map) {
1876-
var maxBounds = $scope.maxBounds;
1878+
var maxBounds = $scope.maxBounds;
18771879
if (isDefined(maxBounds) && isDefined(maxBounds.southWest) && isDefined(maxBounds.northEast)) {
18781880
$scope.$watch("maxBounds", function (maxBounds) {
18791881
if (isDefined(maxBounds.southWest) && isDefined(maxBounds.northEast) && isNumber(maxBounds.southWest.lat) && isNumber(maxBounds.southWest.lng) && isNumber(maxBounds.northEast.lat) && isNumber(maxBounds.northEast.lng)) {
@@ -1909,6 +1911,9 @@ angular.module("leaflet-directive").service('leafletData', function ($log, $q) {
19091911
var markers = {
19101912
main: $q.defer()
19111913
};
1914+
var geoJSON = {
1915+
main: $q.defer()
1916+
};
19121917
var defaults = {};
19131918

19141919
function getDefer(d, scopeId) {
@@ -1982,6 +1987,16 @@ angular.module("leaflet-directive").service('leafletData', function ($log, $q) {
19821987
var tile = getDefer(tiles, scopeId);
19831988
return tile.promise;
19841989
};
1990+
1991+
this.setGeoJSON = function(leafletGeoJSON, scopeId) {
1992+
var geoJSONLayer = getDefer(geoJSON, scopeId);
1993+
geoJSONLayer.resolve(leafletGeoJSON);
1994+
};
1995+
1996+
this.getGeoJSON = function(scopeId) {
1997+
var geoJSONLayer = getDefer(geoJSON, scopeId);
1998+
return geoJSONLayer.promise;
1999+
};
19852000
});
19862001

19872002
}());

dist/angular-leaflet-directive.min.js

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

src/directives/geojson.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
angular.module("leaflet-directive").directive('geojson', function ($log, $rootScope) {
1+
angular.module("leaflet-directive").directive('geojson', function ($log, $rootScope, leafletData) {
22
return {
33
restrict: "A",
44
scope: false,
@@ -8,7 +8,7 @@ angular.module("leaflet-directive").directive('geojson', function ($log, $rootSc
88

99
link: function($scope, element, attrs, controller) {
1010
var map = controller.getMap();
11-
var leafletGeoJSON;
11+
var leafletGeoJSON = {};
1212

1313
controller.getMap().then(function(map) {
1414
$scope.$watch("geojson", function(geojson) {
@@ -49,7 +49,9 @@ angular.module("leaflet-directive").directive('geojson', function ($log, $rootSc
4949
}
5050
});
5151
}
52-
}).addTo(map);
52+
});
53+
leafletData.setGeoJSON(leafletGeoJSON);
54+
leafletGeoJSON.addTo(map);
5355
}
5456
});
5557
});

src/directives/maxBounds.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ angular.module("leaflet-directive").directive('maxbounds', function ($log) {
99
link: function($scope, element, attrs, controller) {
1010
var defaults = parseMapDefaults($scope.defaults);
1111
controller.getMap().then(function(map) {
12-
var maxBounds = $scope.maxBounds;
12+
var maxBounds = $scope.maxBounds;
1313
if (isDefined(maxBounds) && isDefined(maxBounds.southWest) && isDefined(maxBounds.northEast)) {
1414
$scope.$watch("maxBounds", function (maxBounds) {
1515
if (isDefined(maxBounds.southWest) && isDefined(maxBounds.northEast) && isNumber(maxBounds.southWest.lat) && isNumber(maxBounds.southWest.lng) && isNumber(maxBounds.northEast.lat) && isNumber(maxBounds.northEast.lng)) {

src/services/leafletData.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ angular.module("leaflet-directive").service('leafletData', function ($log, $q) {
1414
var markers = {
1515
main: $q.defer()
1616
};
17+
var geoJSON = {
18+
main: $q.defer()
19+
};
1720
var defaults = {};
1821

1922
function getDefer(d, scopeId) {
@@ -87,4 +90,14 @@ angular.module("leaflet-directive").service('leafletData', function ($log, $q) {
8790
var tile = getDefer(tiles, scopeId);
8891
return tile.promise;
8992
};
93+
94+
this.setGeoJSON = function(leafletGeoJSON, scopeId) {
95+
var geoJSONLayer = getDefer(geoJSON, scopeId);
96+
geoJSONLayer.resolve(leafletGeoJSON);
97+
};
98+
99+
this.getGeoJSON = function(scopeId) {
100+
var geoJSONLayer = getDefer(geoJSON, scopeId);
101+
return geoJSONLayer.promise;
102+
};
90103
});

0 commit comments

Comments
 (0)