--
---
You received this message because you are subscribed to a topic in the Google Groups "Leaflet" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/leaflet-js/G4v3bJUufz4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to leaflet-js+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
OK. This is my first attempt at debugging leaflet code… A quick search through the source shows that it's using the panInsideBounds function to constrain the map to the max bounds. This function is being called repeatedly leading to the jitter.
In the function we see it calling panBy which is tripping a move event which is tripping the panInsideBounds again causing the infinite loop.
Looking at the variables in chrome's console:
viewNe
L.Point {x: 1024, y: 132, clone: function, add: function, _add: function…}
ne
L.Point {x: 1024, y: 132.00000000000006, clone: function, add: function, _add: function…}
viewSw
L.Point {x: 0, y: 892, clone: function, add: function, _add: function…}
sw
L.Point {x: 0, y: 892.0000000000001, clone: function, add: function, _add: function…}
The use of the Math.ceil function is causing a repeated 1px jump in dy.
I'm not sure what the solution to this should be - perhaps we are projecting to pixels, so the project function itself should perhaps handle the rounding. Alternatively we should not be doing the ceiling and floor mapping in the panInsideBounds function.
In either case, rounding the projected values in panInsideBounds fixes the problem as a workaround:
panInsideBounds: function (bounds) {
bounds = L.latLngBounds(bounds);
var viewBounds = this.getPixelBounds(),
viewSw = viewBounds.getBottomLeft(),
viewNe = viewBounds.getTopRight(),
sw = this.project(bounds.getSouthWest()),
ne = this.project(bounds.getNorthEast()),
swx = Math.Round(sw.x),
swy = Math.Round(sw.y),
nex = Math.Round(ne.x),
ney = Math.Round(ne.y),
dx = 0,
dy = 0;
if (viewNe.y < ney) { // north
dy = Math.ceil(ney - viewNe.y);
}
if (viewNe.x > nex) { // east
dx = Math.floor(nex - viewNe.x);
}
if (viewSw.y > swy) { // south
dy = Math.floor(swy - viewSw.y);
}
if (viewSw.x < swx) { // west
dx = Math.ceil(swx - viewSw.x);
}
if (dx || dy) {
return this.panBy([dx, dy]);
}
return this;
Thanks for pointing me in the right direction. I've updated what appears to be a related leaflet issue.
--
---
You received this message because you are subscribed to the Google Groups "Leaflet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leaflet-js+...@googlegroups.com.
--
---
You received this message because you are subscribed to a topic in the Google Groups "Leaflet" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/leaflet-js/G4v3bJUufz4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to leaflet-js+...@googlegroups.com.