Skip to content

Commit fe57501

Browse files
committed
feat(build): 'maxbounds' updated to work with leaflet 0.7.1
1 parent b2f541c commit fe57501

File tree

6 files changed

+26
-39
lines changed

6 files changed

+26
-39
lines changed

dist/angular-leaflet-directive.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ angular.module("leaflet-directive", []).directive('leaflet', function ($q, leafl
3939
genDispatchMapEvent = leafletEvents.genDispatchMapEvent,
4040
mapEvents = leafletEvents.getAvailableMapEvents();
4141

42-
// If we are going to set maxbounds, undefine the minZoom property
43-
if (isDefined(scope.maxbounds)) {
44-
defaults.minZoom = undefined;
45-
}
46-
4742
// Set width and height if they are defined
4843
if (isDefined(attrs.width)) {
4944
if (isNaN(attrs.width)) {
@@ -965,17 +960,18 @@ angular.module("leaflet-directive").directive('maxbounds', function ($log, leafl
965960

966961
controller.getMap().then(function(map) {
967962
leafletScope.$watch("maxbounds", function (maxbounds) {
968-
// Unset any previous maxbounds
969-
map.setMaxBounds();
970-
map.fire("zoomlevelschange");
971-
972963
if (!isValidBounds(maxbounds)) {
964+
// Unset any previous maxbounds
965+
map.setMaxBounds();
973966
return;
974967
}
975-
map.setMaxBounds( [
968+
var bounds = [
976969
[ maxbounds.southWest.lat, maxbounds.southWest.lng ],
977970
[ maxbounds.northEast.lat, maxbounds.northEast.lng ]
978-
]);
971+
];
972+
973+
map.setMaxBounds(bounds);
974+
map.fitBounds(bounds);
979975
});
980976
});
981977
}

dist/angular-leaflet-directive.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/maxbounds-example.html

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
<!DOCTYPE html>
22
<html ng-app="demoapp">
33
<head>
4-
<script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
5-
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
4+
<script src="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.js"></script>
5+
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>
66
<script src="../dist/angular-leaflet-directive.min.js"></script>
7-
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />
8-
<!--[if lte IE 8]>
9-
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.ie.css" />
10-
<![endif]-->
7+
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.css" />
118
<script>
129
angular.module("demoapp", ["leaflet-directive"]);
1310
function DemoController($scope, leafletData) {
@@ -45,10 +42,7 @@
4542
};
4643

4744
angular.extend($scope, {
48-
maxbounds: {},
49-
defaults: {
50-
minZoom: 4
51-
}
45+
maxbounds: {}
5246
});
5347

5448
};
@@ -68,7 +62,7 @@
6862
<button ng-click="maxbounds={}">Unset maxbounds</button>
6963
</form>
7064

71-
<leaflet maxbounds="maxbounds" defaults="defaults"></leaflet>
65+
<leaflet maxbounds="maxbounds"></leaflet>
7266
<p ng-show="maxbounds.northEast" class="result">Maxbounds: NE(lat: {{ maxbounds.northEast.lat }}, lng: {{ maxbounds.northEast.lng }}) SW(lat: {{ maxbounds.southWest.lat }}, lng: {{ maxbounds.southWest.lng }})</p>
7367
</body>
7468
</html>

src/directives/leaflet.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ angular.module("leaflet-directive", []).directive('leaflet', function ($q, leafl
3535
genDispatchMapEvent = leafletEvents.genDispatchMapEvent,
3636
mapEvents = leafletEvents.getAvailableMapEvents();
3737

38-
// If we are going to set maxbounds, undefine the minZoom property
39-
if (isDefined(scope.maxbounds)) {
40-
defaults.minZoom = undefined;
41-
}
42-
4338
// Set width and height if they are defined
4439
if (isDefined(attrs.width)) {
4540
if (isNaN(attrs.width)) {

src/directives/maxbounds.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@ angular.module("leaflet-directive").directive('maxbounds', function ($log, leafl
1212

1313
controller.getMap().then(function(map) {
1414
leafletScope.$watch("maxbounds", function (maxbounds) {
15-
// Unset any previous maxbounds
16-
map.setMaxBounds();
17-
map.fire("zoomlevelschange");
18-
1915
if (!isValidBounds(maxbounds)) {
16+
// Unset any previous maxbounds
17+
map.setMaxBounds();
2018
return;
2119
}
22-
map.setMaxBounds( [
20+
var bounds = [
2321
[ maxbounds.southWest.lat, maxbounds.southWest.lng ],
2422
[ maxbounds.northEast.lat, maxbounds.northEast.lng ]
25-
]);
23+
];
24+
25+
map.setMaxBounds(bounds);
26+
map.fitBounds(bounds);
2627
});
2728
});
2829
}

test/unit/maxboundsDirectiveSpec.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ describe('Directive: leaflet', function() {
2020
$rootScope.$apply();
2121
}));
2222

23-
it('should unset the minzoom if maxbounds specified', function() {
23+
it('should change the center if maxbounds specified', function() {
2424
angular.extend($rootScope, {
25-
defaults: {
26-
minZoom: 4,
27-
},
2825
maxbounds: {
2926
southWest: {
3027
lat: 52.14823737817847,
@@ -34,6 +31,9 @@ describe('Directive: leaflet', function() {
3431
lat: 52.31645452105213,
3532
lng: 21.233139038085938
3633
}
34+
},
35+
defaults: {
36+
zoomAnimation: false
3737
}
3838
});
3939
var element = angular.element('<leaflet defaults="defaults" maxbounds="maxbounds"></leaflet>');
@@ -43,7 +43,8 @@ describe('Directive: leaflet', function() {
4343
leafletMap = map;
4444
});
4545
$rootScope.$digest();
46-
expect(leafletMap.getMinZoom()).toEqual(0);
46+
expect(leafletMap.getCenter().lat).toBe(52.23242563023071);
47+
expect(leafletMap.getCenter().lng).toBe(21.013412475585938);
4748
});
4849

4950
});

0 commit comments

Comments
 (0)