Skip to content

Commit

Permalink
Enforce limits on calls to setCenter. Includes tests. Fixes #56
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Jan 30, 2013
1 parent 2501e70 commit f09f960
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
5 changes: 3 additions & 2 deletions modestmaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2217,6 +2217,7 @@ var MM = com.modestmaps = {

setCenterZoom: function(location, zoom) {
this.coordinate = this.projection.locationCoordinate(location).zoomTo(parseFloat(zoom) || 0);
this.coordinate = this.enforceLimits(this.coordinate);
MM.getFrame(this.getRedraw());
this.dispatchCallback('centered', [location, zoom]);
return this;
Expand Down Expand Up @@ -2282,8 +2283,8 @@ var MM = com.modestmaps = {

setExtent: function(locations, precise) {
this.coordinate = this.extentCoordinate(locations, precise);
this.draw(); // draw calls enforceLimits
// (if you switch to getFrame, call enforceLimits first)
this.coordinate = this.enforceLimits(this.coordinate);
MM.getFrame(this.getRedraw());

this.dispatchCallback('extentset', locations);
return this;
Expand Down
4 changes: 2 additions & 2 deletions modestmaps.min.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@

setCenterZoom: function(location, zoom) {
this.coordinate = this.projection.locationCoordinate(location).zoomTo(parseFloat(zoom) || 0);
this.coordinate = this.enforceLimits(this.coordinate);
MM.getFrame(this.getRedraw());
this.dispatchCallback('centered', [location, zoom]);
return this;
Expand Down Expand Up @@ -282,8 +283,8 @@

setExtent: function(locations, precise) {
this.coordinate = this.extentCoordinate(locations, precise);
this.draw(); // draw calls enforceLimits
// (if you switch to getFrame, call enforceLimits first)
this.coordinate = this.enforceLimits(this.coordinate);
MM.getFrame(this.getRedraw());

this.dispatchCallback('extentset', locations);
return this;
Expand Down
7 changes: 7 additions & 0 deletions test/spec/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ describe('Map', function() {
expect(typeof map.coordinate.zoom).toEqual('number');
});

it('enforces limits when setting an extent', function() {
map.dimensions = { x: 800, y: 800 };
map.zoom(2).center({ lat: 54.5259614, lon:15.2551187 });
expect(map.locationPoint({ lat: 40.7143528, lon: -74.0059731 }).y)
.toBeCloseTo(384.9985102776103);
});

describe('Navigation', function() {
it('binds and calls drawn', function() {
spyOn(sink, 'receive');
Expand Down

0 comments on commit f09f960

Please sign in to comment.