Skip to content

Commit

Permalink
fix lots of maxBounds issues, close #1491, close #1475, close #1194, c…
Browse files Browse the repository at this point in the history
…lose #900, #1333
  • Loading branch information
mourner committed Apr 18, 2013
1 parent 0b1bc7a commit db6d689
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
26 changes: 18 additions & 8 deletions src/map/Map.js
Expand Up @@ -119,34 +119,40 @@ L.Map = L.Class.extend({
}
}

this.on('moveend', this._panInsideMaxBounds, this);

return this;
},

panInsideBounds: function (bounds) {
bounds = L.latLngBounds(bounds);

var viewBounds = this.getBounds(),
viewSw = this.project(viewBounds.getSouthWest()),
viewNe = this.project(viewBounds.getNorthEast()),
var viewBounds = this.getPixelBounds(),
viewSw = viewBounds.getBottomLeft(),
viewNe = viewBounds.getTopRight(),
sw = this.project(bounds.getSouthWest()),
ne = this.project(bounds.getNorthEast()),
dx = 0,
dy = 0;

if (viewNe.y < ne.y) { // north
dy = ne.y - viewNe.y;
dy = Math.ceil(ne.y - viewNe.y);
}
if (viewNe.x > ne.x) { // east
dx = ne.x - viewNe.x;
dx = Math.floor(ne.x - viewNe.x);
}
if (viewSw.y > sw.y) { // south
dy = sw.y - viewSw.y;
dy = Math.floor(sw.y - viewSw.y);
}
if (viewSw.x < sw.x) { // west
dx = sw.x - viewSw.x;
dx = Math.ceil(sw.x - viewSw.x);
}

if (dx || dy) {
return this.panBy(new L.Point(dx, dy));
}

return this.panBy(new L.Point(dx, dy, true));
return this;
},

addLayer: function (layer) {
Expand Down Expand Up @@ -609,6 +615,10 @@ L.Map = L.Class.extend({
}
},

_panInsideMaxBounds: function () {
this.panInsideBounds(this.options.maxBounds);
},

_checkIfLoaded: function () {
if (!this._loaded) {
throw new Error('Set map center and zoom first.');
Expand Down
9 changes: 0 additions & 9 deletions src/map/handler/Map.Drag.js
Expand Up @@ -140,15 +140,6 @@ L.Map.Drag = L.Handler.extend({
});
}
}

if (options.maxBounds) {
// TODO predrag validation instead of animation
L.Util.requestAnimFrame(this._panInsideMaxBounds, map, true, map._container);
}
},

_panInsideMaxBounds: function () {
this.panInsideBounds(this.options.maxBounds);
}
});

Expand Down

0 comments on commit db6d689

Please sign in to comment.