Skip to content

Commit

Permalink
zoomable doesn't work, fix #579
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzhenn committed Jan 9, 2018
1 parent d5c59df commit 72d8aa2
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/map/Map.Zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/map/handler/Map.ScrollWheelZoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/map/handler/Map.TouchZoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 16 additions & 0 deletions test/map/MapAnimSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions test/map/MapScrollZoomSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

});
8 changes: 8 additions & 0 deletions test/map/MapSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
28 changes: 27 additions & 1 deletion test/map/MapTouchZoomSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
});
});

});

0 comments on commit 72d8aa2

Please sign in to comment.