mirror of
https://github.com/Leaflet/Leaflet.git
synced 2025-07-23 00:34:55 +00:00
Rename TouchZoom handler to PinchZoom (keep TouchZoom as alias for backward compatibility) (#9642)
Co-authored-by: Florian Bischof <design.falke@gmail.com>
This commit is contained in:

committed by
GitHub

parent
c1d74dc61c
commit
07252ebffb
@ -377,7 +377,7 @@ describe('Map.Drag', () => {
|
||||
});
|
||||
map.setView([0, 0], 1);
|
||||
|
||||
// Change default events order to make the tap comming before the touchzoom.
|
||||
// Change default events order to make the tap comming before the pinchZoom.
|
||||
// See #4315
|
||||
map.dragging.disable();
|
||||
map.dragging.enable();
|
||||
|
@ -4,13 +4,13 @@ import Hand from 'prosthetic-hand';
|
||||
import sinon from 'sinon';
|
||||
import {createContainer, removeMapContainer, touchEventType} from '../../SpecHelper.js';
|
||||
|
||||
describe('Map.TouchZoom', () => {
|
||||
describe('Map.PinchZoom', () => {
|
||||
let container, map;
|
||||
|
||||
beforeEach(() => {
|
||||
container = createContainer();
|
||||
map = new Map(container, {
|
||||
touchZoom: true,
|
||||
pinchZoom: true,
|
||||
inertia: false,
|
||||
zoomAnimation: false // If true, the test has to wait extra 250msec
|
||||
});
|
||||
@ -133,11 +133,11 @@ describe('Map.TouchZoom', () => {
|
||||
|
||||
});
|
||||
|
||||
it.skipIfNotTouch('TouchZoom works with disabled map dragging', (done) => {
|
||||
it.skipIfNotTouch('PinchZoom works with disabled map dragging', (done) => {
|
||||
map.remove();
|
||||
|
||||
map = new Map(container, {
|
||||
touchZoom: true,
|
||||
pinchZoom: true,
|
||||
inertia: false,
|
||||
zoomAnimation: false, // If true, the test has to wait extra 250msec,
|
||||
dragging: false
|
||||
@ -167,7 +167,7 @@ describe('Map.TouchZoom', () => {
|
||||
map.remove();
|
||||
|
||||
map = new Map(container, {
|
||||
touchZoom: true,
|
||||
pinchZoom: true,
|
||||
inertia: false,
|
||||
zoomAnimation: true
|
||||
});
|
||||
@ -220,16 +220,16 @@ describe('Map.TouchZoom', () => {
|
||||
|
||||
hand.sync(5);
|
||||
f1.wait(100).moveTo(75, 300, 0)
|
||||
.down().moveBy(200, 0, 500);
|
||||
.down().moveBy(200, 0, 500).up();
|
||||
f2.wait(100).moveTo(525, 300, 0)
|
||||
.down().moveBy(-200, 0, 500);
|
||||
.down().moveBy(-200, 0, 500).up();
|
||||
});
|
||||
|
||||
it.skipIfNotTouch('Layer is rendered correctly while pinch zoom when zoomAnim is false', (done) => {
|
||||
map.remove();
|
||||
|
||||
map = new Map(container, {
|
||||
touchZoom: true,
|
||||
pinchZoom: true,
|
||||
inertia: false,
|
||||
zoomAnimation: false
|
||||
});
|
||||
@ -243,47 +243,74 @@ describe('Map.TouchZoom', () => {
|
||||
[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);
|
||||
}
|
||||
map.pinchZoom._onTouchStart({
|
||||
touches: [
|
||||
{clientX: 75, clientY: 300},
|
||||
{clientX: 525, clientY: 300}
|
||||
],
|
||||
});
|
||||
map.pinchZoom._onTouchMove({
|
||||
touches: [
|
||||
{clientX: 275, clientY: 300},
|
||||
{clientX: 325, clientY: 300}
|
||||
],
|
||||
});
|
||||
|
||||
const f1 = hand.growFinger(touchEventType);
|
||||
const f2 = hand.growFinger(touchEventType);
|
||||
setTimeout(() => {
|
||||
map.pinchZoom._onTouchEnd();
|
||||
|
||||
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);
|
||||
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(297, 300);
|
||||
expect(y).to.be.within(270, 280);
|
||||
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it.skipIfNotTouch('disables pinchZoom when touchZoom is false (backward compatibility)', () => {
|
||||
const warnSpy = sinon.spy(console, 'warn');
|
||||
|
||||
const localContainer = createContainer();
|
||||
const localMap = new Map(localContainer, {
|
||||
touchZoom: false
|
||||
});
|
||||
|
||||
expect(localMap.pinchZoom.enabled()).to.be.false;
|
||||
expect(warnSpy.calledOnce).to.be.true;
|
||||
expect(warnSpy.firstCall.args[0]).to.eq('Map: touchZoom option is deprecated and will be removed in future versions. Use pinchZoom instead.');
|
||||
|
||||
warnSpy.restore();
|
||||
removeMapContainer(localMap, localContainer);
|
||||
});
|
||||
|
||||
|
||||
it.skipIfNotTouch('enables pinchZoom when touchZoom is true and pinchZoom is false (touchZoom takes precedence)', () => {
|
||||
const warnSpy = sinon.spy(console, 'warn');
|
||||
|
||||
const localContainer = createContainer();
|
||||
const localMap = new Map(localContainer, {
|
||||
touchZoom: true,
|
||||
pinchZoom: false
|
||||
});
|
||||
|
||||
expect(localMap.pinchZoom.enabled()).to.be.true;
|
||||
expect(warnSpy.calledOnce).to.be.true;
|
||||
expect(warnSpy.firstCall.args[0]).to.eq('Map: touchZoom option is deprecated and will be removed in future versions. Use pinchZoom instead.');
|
||||
|
||||
warnSpy.restore();
|
||||
removeMapContainer(localMap, localContainer);
|
||||
});
|
||||
|
||||
});
|
Reference in New Issue
Block a user