Skip to content

Commit

Permalink
fix(build): Solved some performance and functional issues with the "b…
Browse files Browse the repository at this point in the history
…ounds" attribute.
  • Loading branch information
tombatossals committed Dec 26, 2013
1 parent eac699a commit 901259a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
18 changes: 10 additions & 8 deletions dist/angular-leaflet-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ angular.module("leaflet-directive").directive('bounds', function ($log, leafletH
leafletScope = controller.getLeafletScope();

controller.getMap().then(function(map) {
var initializing = true;

map.whenReady(function() {
leafletScope.$watch('bounds', function(newBounds) {
Expand All @@ -573,16 +574,19 @@ angular.module("leaflet-directive").directive('bounds', function ($log, leafletH
return;
}

initializing = false;
var leafletBounds = createLeafletBounds(newBounds);
if (leafletBounds && !map.getBounds().equals(leafletBounds)) {
map.fitBounds(leafletBounds);
}
}, true);
});

map.on('moveend', updateBoundsInScope, leafletScope, map);
map.on('dragend', updateBoundsInScope, leafletScope, map);
map.on('zoomend', updateBoundsInScope, leafletScope, map);
map.on('dragend zoomend', function() {
if (!initializing) {
updateBoundsInScope(leafletScope, map);
}
});
});

});
}
Expand Down Expand Up @@ -1499,10 +1503,10 @@ angular.module("leaflet-directive").factory('leafletBoundsHelpers', function ($l
createBoundsFromArray: function(boundsArray) {
if (!(isArray(boundsArray) && boundsArray.length === 2 &&
isArray(boundsArray[0]) && isArray(boundsArray[1]) &&
boundsArray[0].length === 2 && boundsArray[1].lenth === 2 &&
boundsArray[0].length === 2 && boundsArray[1].length === 2 &&
isNumber(boundsArray[0][0]) && isNumber(boundsArray[0][1]) &&
isNumber(boundsArray[1][0]) && isNumber(boundsArray[1][1]))) {
$log.warn("[AngularJS - Leaflet] The bounds array is not valid.");
$log.error("[AngularJS - Leaflet] The bounds array is not valid.");
return;
}

Expand All @@ -1520,8 +1524,6 @@ angular.module("leaflet-directive").factory('leafletBoundsHelpers', function ($l
},

updateBoundsInScope: function(leafletScope, map) {
if(!leafletScope.bounds) { return; }

var mapBounds = map.getBounds();
var newScopeBounds = {
northEast: {
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-leaflet-directive.min.js

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions src/directives/bounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ angular.module("leaflet-directive").directive('bounds', function ($log, leafletH
leafletScope = controller.getLeafletScope();

controller.getMap().then(function(map) {
var initializing = true;

map.whenReady(function() {
leafletScope.$watch('bounds', function(newBounds) {
Expand All @@ -20,16 +21,19 @@ angular.module("leaflet-directive").directive('bounds', function ($log, leafletH
return;
}

initializing = false;
var leafletBounds = createLeafletBounds(newBounds);
if (leafletBounds && !map.getBounds().equals(leafletBounds)) {
map.fitBounds(leafletBounds);
}
}, true);
});

map.on('moveend', updateBoundsInScope, leafletScope, map);
map.on('dragend', updateBoundsInScope, leafletScope, map);
map.on('zoomend', updateBoundsInScope, leafletScope, map);
map.on('dragend zoomend', function() {
if (!initializing) {
updateBoundsInScope(leafletScope, map);
}
});
});

});
}
Expand Down
18 changes: 9 additions & 9 deletions test/e2e/03-bounds-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ describe('Loading bounds-example.html', function() {
return ptor.isElementPresent(by.css('img.leaflet-tile-loaded'));
});

expect(element(by.model("bounds.southWest.lat")).getAttribute("value")).toBe("39.232253141714885");
expect(element(by.model("bounds.southWest.lng")).getAttribute("value")).toBe("-28.212890625");
expect(element(by.model("bounds.northEast.lat")).getAttribute("value")).toBe("61.18562468142283");
expect(element(by.model("bounds.northEast.lng")).getAttribute("value")).toBe("28.037109375");
expect(element(by.model("bounds.southWest.lat")).getAttribute("value")).toBe("51.508074696286876");
expect(element(by.model("bounds.southWest.lng")).getAttribute("value")).toBe("-0.08960723876953125");
expect(element(by.model("bounds.northEast.lat")).getAttribute("value")).toBe("51.509410211532874");
expect(element(by.model("bounds.northEast.lng")).getAttribute("value")).toBe("-0.08617401123046874");

element(by.xpath('.//*[@title="Zoom in"]')).click().then(function() {
element(by.xpath('.//*[@title="Zoom out"]')).click().then(function() {
ptor.sleep(400);
expect(element(by.model("bounds.southWest.lat")).getAttribute("value")).toBe("45.706179285330855");
expect(element(by.model("bounds.southWest.lng")).getAttribute("value")).toBe("-14.150390625");
expect(element(by.model("bounds.northEast.lat")).getAttribute("value")).toBe("56.65622649350222");
expect(element(by.model("bounds.northEast.lng")).getAttribute("value")).toBe("13.974609375");
expect(element(by.model("bounds.southWest.lat")).getAttribute("value")).toBe("51.507406923983446");
expect(element(by.model("bounds.southWest.lng")).getAttribute("value")).toBe("-0.0913238525390625");
expect(element(by.model("bounds.northEast.lat")).getAttribute("value")).toBe("51.510077954475555");
expect(element(by.model("bounds.northEast.lng")).getAttribute("value")).toBe("-0.0844573974609375");
});

});
Expand Down

0 comments on commit 901259a

Please sign in to comment.