mirror of
https://github.com/Leaflet/Leaflet.git
synced 2025-07-29 11:53:03 +00:00
Workaround for flyTo bug
* test for flyTo start latlng == end latlng condition * workaround for flyTo infinite loop * expect for zoomend values Close #4226
This commit is contained in:
@ -56,7 +56,7 @@
|
||||
|
||||
var map = L.map('map', {
|
||||
zoomSnap: 0.25
|
||||
}).setView(dc, 10);
|
||||
}).setView(dc, 14);
|
||||
|
||||
var positron = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', {
|
||||
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>'
|
||||
@ -73,7 +73,7 @@
|
||||
|
||||
var nullIslandKitten = L.imageOverlay('http://placekitten.com/300/400?image=6', [[-0.2,-0.15], [0.2, 0.15]]).addTo(map);
|
||||
|
||||
document.getElementById('dc').onclick = function () { map.flyTo(dc, 10); };
|
||||
document.getElementById('dc').onclick = function () { map.flyTo(dc, 4); };
|
||||
document.getElementById('sf').onclick = function () { map.setView(sf, 10, {duration: 5, animate: true}); };
|
||||
document.getElementById('trd').onclick = function () { map.flyTo(trd, 10, {duration: 20}); };
|
||||
document.getElementById('lnd').onclick = function () { map.flyTo(lnd, 9.25); };
|
||||
|
@ -609,8 +609,26 @@ describe("Map", function () {
|
||||
});
|
||||
|
||||
describe('#flyTo', function () {
|
||||
var div;
|
||||
|
||||
beforeEach(function () {
|
||||
div = document.createElement('div');
|
||||
div.style.width = '800px';
|
||||
div.style.height = '600px';
|
||||
div.style.visibility = 'hidden';
|
||||
|
||||
document.body.appendChild(div);
|
||||
|
||||
map = L.map(div);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
document.body.removeChild(div);
|
||||
});
|
||||
|
||||
it.skipInPhantom('move to requested center and zoom, and call zoomend once', function (done) {
|
||||
this.timeout(10000); // This test takes longer than usual due to frames
|
||||
|
||||
it('move to requested center and zoom, and call zoomend once', function (done) {
|
||||
var spy = sinon.spy(),
|
||||
newCenter = new L.LatLng(10, 11),
|
||||
newZoom = 12;
|
||||
@ -622,7 +640,22 @@ describe("Map", function () {
|
||||
done();
|
||||
};
|
||||
map.setView([0, 0], 0);
|
||||
map.once('zoomend', callback).flyTo(newCenter, newZoom);
|
||||
map.on('zoomend', callback).flyTo(newCenter, newZoom);
|
||||
});
|
||||
|
||||
it.skipInPhantom('flyTo start latlng == end latlng', function (done) {
|
||||
this.timeout(10000); // This test takes longer than usual due to frames
|
||||
|
||||
var dc = new L.LatLng(38.91, -77.04);
|
||||
map.setView(dc, 14);
|
||||
|
||||
map.on('zoomend', function () {
|
||||
expect(map.getCenter()).to.eql(dc);
|
||||
expect(map.getZoom()).to.eql(4);
|
||||
done();
|
||||
});
|
||||
|
||||
map.flyTo(dc, 4);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -29,8 +29,18 @@ L.Map.include({
|
||||
rho2 = rho * rho;
|
||||
|
||||
function r(i) {
|
||||
var b = (w1 * w1 - w0 * w0 + (i ? -1 : 1) * rho2 * rho2 * u1 * u1) / (2 * (i ? w1 : w0) * rho2 * u1);
|
||||
return Math.log(Math.sqrt(b * b + 1) - b);
|
||||
var s1 = i ? -1 : 1,
|
||||
s2 = i ? w1 : w0,
|
||||
t1 = w1 * w1 - w0 * w0 + s1 * rho2 * rho2 * u1 * u1,
|
||||
b1 = 2 * s2 * rho2 * u1,
|
||||
b = t1 / b1,
|
||||
sq = Math.sqrt(b * b + 1) - b;
|
||||
|
||||
// workaround for floating point precision bug when sq = 0, log = -Infinite,
|
||||
// thus triggering an infinite loop in flyTo
|
||||
var log = sq < 0.000000001 ? -18 : Math.log(sq);
|
||||
|
||||
return log;
|
||||
}
|
||||
|
||||
function sinh(n) { return (Math.exp(n) - Math.exp(-n)) / 2; }
|
||||
|
Reference in New Issue
Block a user