Skip to content

Commit

Permalink
feat(build): 'maxbounds' updated to work with leaflet 0.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tombatossals committed Dec 27, 2013
1 parent b2f541c commit fe57501
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 39 deletions.
18 changes: 7 additions & 11 deletions dist/angular-leaflet-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ angular.module("leaflet-directive", []).directive('leaflet', function ($q, leafl
genDispatchMapEvent = leafletEvents.genDispatchMapEvent,
mapEvents = leafletEvents.getAvailableMapEvents();

// If we are going to set maxbounds, undefine the minZoom property
if (isDefined(scope.maxbounds)) {
defaults.minZoom = undefined;
}

// Set width and height if they are defined
if (isDefined(attrs.width)) {
if (isNaN(attrs.width)) {
Expand Down Expand Up @@ -965,17 +960,18 @@ angular.module("leaflet-directive").directive('maxbounds', function ($log, leafl

controller.getMap().then(function(map) {
leafletScope.$watch("maxbounds", function (maxbounds) {
// Unset any previous maxbounds
map.setMaxBounds();
map.fire("zoomlevelschange");

if (!isValidBounds(maxbounds)) {
// Unset any previous maxbounds
map.setMaxBounds();
return;
}
map.setMaxBounds( [
var bounds = [
[ maxbounds.southWest.lat, maxbounds.southWest.lng ],
[ maxbounds.northEast.lat, maxbounds.northEast.lng ]
]);
];

map.setMaxBounds(bounds);
map.fitBounds(bounds);
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-leaflet-directive.min.js

Large diffs are not rendered by default.

16 changes: 5 additions & 11 deletions examples/maxbounds-example.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<!DOCTYPE html>
<html ng-app="demoapp">
<head>
<script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
<script src="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>
<script src="../dist/angular-leaflet-directive.min.js"></script>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />
<!--[if lte IE 8]>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.ie.css" />
<![endif]-->
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.css" />
<script>
angular.module("demoapp", ["leaflet-directive"]);
function DemoController($scope, leafletData) {
Expand Down Expand Up @@ -45,10 +42,7 @@
};

angular.extend($scope, {
maxbounds: {},
defaults: {
minZoom: 4
}
maxbounds: {}
});

};
Expand All @@ -68,7 +62,7 @@
<button ng-click="maxbounds={}">Unset maxbounds</button>
</form>

<leaflet maxbounds="maxbounds" defaults="defaults"></leaflet>
<leaflet maxbounds="maxbounds"></leaflet>
<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>
</body>
</html>
5 changes: 0 additions & 5 deletions src/directives/leaflet.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ angular.module("leaflet-directive", []).directive('leaflet', function ($q, leafl
genDispatchMapEvent = leafletEvents.genDispatchMapEvent,
mapEvents = leafletEvents.getAvailableMapEvents();

// If we are going to set maxbounds, undefine the minZoom property
if (isDefined(scope.maxbounds)) {
defaults.minZoom = undefined;
}

// Set width and height if they are defined
if (isDefined(attrs.width)) {
if (isNaN(attrs.width)) {
Expand Down
13 changes: 7 additions & 6 deletions src/directives/maxbounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ angular.module("leaflet-directive").directive('maxbounds', function ($log, leafl

controller.getMap().then(function(map) {
leafletScope.$watch("maxbounds", function (maxbounds) {
// Unset any previous maxbounds
map.setMaxBounds();
map.fire("zoomlevelschange");

if (!isValidBounds(maxbounds)) {
// Unset any previous maxbounds
map.setMaxBounds();
return;
}
map.setMaxBounds( [
var bounds = [
[ maxbounds.southWest.lat, maxbounds.southWest.lng ],
[ maxbounds.northEast.lat, maxbounds.northEast.lng ]
]);
];

map.setMaxBounds(bounds);
map.fitBounds(bounds);
});
});
}
Expand Down
11 changes: 6 additions & 5 deletions test/unit/maxboundsDirectiveSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ describe('Directive: leaflet', function() {
$rootScope.$apply();
}));

it('should unset the minzoom if maxbounds specified', function() {
it('should change the center if maxbounds specified', function() {
angular.extend($rootScope, {
defaults: {
minZoom: 4,
},
maxbounds: {
southWest: {
lat: 52.14823737817847,
Expand All @@ -34,6 +31,9 @@ describe('Directive: leaflet', function() {
lat: 52.31645452105213,
lng: 21.233139038085938
}
},
defaults: {
zoomAnimation: false
}
});
var element = angular.element('<leaflet defaults="defaults" maxbounds="maxbounds"></leaflet>');
Expand All @@ -43,7 +43,8 @@ describe('Directive: leaflet', function() {
leafletMap = map;
});
$rootScope.$digest();
expect(leafletMap.getMinZoom()).toEqual(0);
expect(leafletMap.getCenter().lat).toBe(52.23242563023071);
expect(leafletMap.getCenter().lng).toBe(21.013412475585938);
});

});

0 comments on commit fe57501

Please sign in to comment.