Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix vector drifts when zoomAnimation is false and zooming via flyTo or pinch #8794

Merged
merged 2 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions debug/vector/vector-drift.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html>
<head>
<title>Leaflet debug page</title>
<link rel="stylesheet" href="../../dist/leaflet.css" />
<link rel="stylesheet" href="../css/screen.css" />
<script src="../../dist/leaflet-src.js"></script>
</head>
<body>
<button id="btn-1">A</button>
<button id="btn-2">B</button>
<div id="map"></div>

<script>
var map = L.map('map', {
zoomAnimation: false,
// preferCanvas: true
}).setView([0, 0], 7);

var markerA = L.marker([1, 0]).addTo(map);
var markerB = L.marker([1, 2]).addTo(map);
L.polygon([
[0, 0],
[2, 0],
[2, 2],
[0, 2],
[0, 0],
])
.bindPopup('Hello world')
.addTo(map);

// or pinch zoom in mobile
document.getElementById('btn-1').addEventListener('click', function () {
map.flyTo(markerA.getLatLng(), 6);
});
document.getElementById('btn-2').addEventListener('click', function () {
map.flyTo(markerB.getLatLng(), 7);
});
</script>
</body>
</html>
64 changes: 63 additions & 1 deletion spec/suites/map/handler/Map.TouchZoomSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe('Map.TouchZoom', () => {
.down().moveBy(-200, 0, 500).up(100);
});

it.skipIfNotTouch("Layer is rendered correctly while pinch zoom when zoomAnim is true", (done) => {
it.skipIfNotTouch('Layer is rendered correctly while pinch zoom when zoomAnim is true', (done) => {
map.remove();

map = new L.Map(container, {
Expand Down Expand Up @@ -218,4 +218,66 @@ describe('Map.TouchZoom', () => {
f2.wait(100).moveTo(525, 300, 0)
.down().moveBy(-200, 0, 500);
});

it.skipIfNotTouch('Layer is rendered correctly while pinch zoom when zoomAnim is false', (done) => {
map.remove();

map = new L.Map(container, {
touchZoom: true,
inertia: false,
zoomAnimation: false
});

map.setView([0, 0], 8);

const polygon = L.polygon([
[0, 0],
[0, 1],
[1, 1],
[1, 0]
]).addTo(map);

let alreadyCalled = false;
const hand = new Hand({
timing: 'fastframe',
onStop() {
setTimeout(() => {
if (alreadyCalled) {
return; // Will recursivly call itself otherwise
}
alreadyCalled = true;

const renderedRect = polygon._path.getBoundingClientRect();

const width = renderedRect.width;
const height = renderedRect.height;

expect(height < 50).to.be(true);
expect(width < 50).to.be(true);
expect(height + width > 0).to.be(true);

const x = renderedRect.x;
const y = renderedRect.y;

expect(x).to.be.within(299, 301);
expect(y).to.be.within(270, 280);

// Fingers lifted after expects as bug goes away when lifted
this._fingers[0].up();
this._fingers[1].up();

done();
}, 100);
}
});

const f1 = hand.growFinger(touchEventType);
const f2 = hand.growFinger(touchEventType);

hand.sync(5);
f1.wait(100).moveTo(75, 300, 0)
.down().moveBy(200, 0, 500);
f2.wait(100).moveTo(525, 300, 0)
.down().moveBy(-200, 0, 500);
});
});
5 changes: 2 additions & 3 deletions src/layer/vector/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ export const Renderer = Layer.extend({
if (!this._container) {
this._initContainer(); // defined by renderer implementations

if (this._zoomAnimated) {
this._container.classList.add('leaflet-zoom-animated');
}
// always keep transform-origin as 0 0
this._container.classList.add('leaflet-zoom-animated');
}

this.getPane().appendChild(this._container);
Expand Down