From 72d8aa20005d7b9c12b3e84f60a47a8166dfdcca Mon Sep 17 00:00:00 2001 From: fuzhenn Date: Tue, 9 Jan 2018 17:40:39 +0800 Subject: [PATCH] zoomable doesn't work, fix #579 --- src/map/Map.Zoom.js | 3 +++ src/map/handler/Map.ScrollWheelZoom.js | 2 +- src/map/handler/Map.TouchZoom.js | 2 +- test/map/MapAnimSpec.js | 16 +++++++++++++++ test/map/MapScrollZoomSpec.js | 11 ++++++++++ test/map/MapSpec.js | 8 ++++++++ test/map/MapTouchZoomSpec.js | 28 +++++++++++++++++++++++++- 7 files changed, 67 insertions(+), 3 deletions(-) diff --git a/src/map/Map.Zoom.js b/src/map/Map.Zoom.js index 66da8a87e..e0caa933a 100644 --- a/src/map/Map.Zoom.js +++ b/src/map/Map.Zoom.js @@ -48,6 +48,7 @@ Map.include(/** @lends Map.prototype */{ }, onZoomStart(nextZoom, origin) { + if (!this.options['zoomable'] || this.isZooming()) { return; } this._zooming = true; this._startZoomVal = this.getZoom(); this._startZoomCoord = this._containerPointToPrj(origin); @@ -64,6 +65,7 @@ Map.include(/** @lends Map.prototype */{ }, onZooming(nextZoom, origin, startScale) { + if (!this.options['zoomable']) { return; } const frameZoom = this._frameZoom; if (frameZoom === nextZoom) { return; @@ -109,6 +111,7 @@ Map.include(/** @lends Map.prototype */{ }, onZoomEnd(nextZoom, origin) { + if (!this.options['zoomable']) { return; } const startZoomVal = this._startZoomVal; this._zoomTo(nextZoom, origin); this._zooming = false; diff --git a/src/map/handler/Map.ScrollWheelZoom.js b/src/map/handler/Map.ScrollWheelZoom.js index 0ea4f73c5..537104b12 100644 --- a/src/map/handler/Map.ScrollWheelZoom.js +++ b/src/map/handler/Map.ScrollWheelZoom.js @@ -14,7 +14,7 @@ class MapScrollWheelZoomHandler extends Handler { _onWheelScroll(evt) { const map = this.target; - if (map._ignoreEvent(evt)) { + if (map._ignoreEvent(evt) || !map.options['zoomable']) { return false; } preventDefault(evt); diff --git a/src/map/handler/Map.TouchZoom.js b/src/map/handler/Map.TouchZoom.js index 44ac70c6e..d9fe30c40 100644 --- a/src/map/handler/Map.TouchZoom.js +++ b/src/map/handler/Map.TouchZoom.js @@ -15,7 +15,7 @@ class MapTouchZoomHandler extends Handler { _onTouchStart(event) { const map = this.target; - if (!event.touches || event.touches.length !== 2 || map.isZooming()) { + if (!event.touches || event.touches.length !== 2 || map.isZooming() || !map.options['zoomable']) { return; } const container = map.getContainer(); diff --git a/test/map/MapAnimSpec.js b/test/map/MapAnimSpec.js index adfd8d6c5..0c88ef034 100644 --- a/test/map/MapAnimSpec.js +++ b/test/map/MapAnimSpec.js @@ -81,6 +81,22 @@ describe('Map.Anim', function () { }); }); + it('disable zoom by zoomable', function (done) { + map.config('zoomable', false); + var cur = map.getZoom(); + var zoom = map.getZoom() - 5; + map.getBaseLayer().config('durationToAnimate', 300); + map.on('animateend', function () { + expect(map.getZoom()).to.be.eql(cur); + done(); + }); + map.animateTo({ + zoom : zoom + }, { + 'duration' : 300 + }); + }); + it('interupt animateTo', function (done) { var center = map.getCenter().add(0.1, 0.1); var zoom = map.getZoom() - 4; diff --git a/test/map/MapScrollZoomSpec.js b/test/map/MapScrollZoomSpec.js index 042c0f90f..810580e4b 100644 --- a/test/map/MapScrollZoomSpec.js +++ b/test/map/MapScrollZoomSpec.js @@ -64,6 +64,17 @@ describe('Map.ScrollZoom', function () { done(); }, delay + 41); }); + + it('disables by zoomable', function (done) { + map.config('zoomable', false); + var spy = sinon.spy(); + map.on('zoomend', spy); + scrollMap(-100); + setTimeout(function () { + expect(spy.called).not.to.be.ok(); + done(); + }, delay + 41); + }); }); }); diff --git a/test/map/MapSpec.js b/test/map/MapSpec.js index 614c9bb51..92f3c3e8e 100644 --- a/test/map/MapSpec.js +++ b/test/map/MapSpec.js @@ -314,6 +314,14 @@ describe('Map.Spec', function () { }); map.setZoom(13); }); + + it('disable zoom by zoomable', function () { + map.config('zoomable', false); + var cur = map.getZoom(); + + expect(map.zoomIn().getZoom()).to.equal(cur); + expect(map.zoomOut().getZoom()).to.equal(cur); + }); }); describe('#setView', function () { diff --git a/test/map/MapTouchZoomSpec.js b/test/map/MapTouchZoomSpec.js index 3f8525149..8c6b69f9e 100644 --- a/test/map/MapTouchZoomSpec.js +++ b/test/map/MapTouchZoomSpec.js @@ -92,7 +92,7 @@ describe('Map.TouchZoom', function () { done(); }); }); - it('disables scrollZoom', function (done) { + it('disables touchZoom', function (done) { this.timeout(5000); map.config('touchZoom', false); var spy = sinon.spy(); @@ -117,6 +117,32 @@ describe('Map.TouchZoom', function () { done(); }, map.options['zoomAnimationDuration'] + 100); }); + + it('disables touchZoom by zoomable', function (done) { + this.timeout(5000); + map.config('zoomable', false); + var spy = sinon.spy(); + testTouchZoom([{ + clientX : centerPoint.x - 10, + clientY : centerPoint.y - 10, + }, + { + clientX : centerPoint.x + 10, + clientY : centerPoint.y + 10, + }], [{ + clientX : centerPoint.x - 1, + clientY : centerPoint.y - 1, + }, + { + clientX : centerPoint.x + 1, + clientY : centerPoint.y + 1, + }], spy); + + setTimeout(function () { + expect(spy.called).not.to.be.ok(); + done(); + }, map.options['zoomAnimationDuration'] + 100); + }); }); });