Add zoomDelta option to MapOptions
This commit is contained in:
@@ -136,6 +136,12 @@ olx.MapOptionsExtern.prototype.userProjection;
|
|||||||
olx.MapOptionsExtern.prototype.zoom;
|
olx.MapOptionsExtern.prototype.zoom;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {number|undefined}
|
||||||
|
*/
|
||||||
|
olx.MapOptionsExtern.prototype.zoomDelta;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {number|undefined}
|
* @type {number|undefined}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -9,8 +9,15 @@ goog.require('ol.interaction.Interaction');
|
|||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.interaction.Interaction}
|
* @extends {ol.interaction.Interaction}
|
||||||
|
* @param {number} delta The zoom delta applied on each double click.
|
||||||
*/
|
*/
|
||||||
ol.interaction.DblClickZoom = function() {
|
ol.interaction.DblClickZoom = function(delta) {
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
this.delta_ = delta;
|
||||||
|
|
||||||
goog.base(this);
|
goog.base(this);
|
||||||
};
|
};
|
||||||
goog.inherits(ol.interaction.DblClickZoom, ol.interaction.Interaction);
|
goog.inherits(ol.interaction.DblClickZoom, ol.interaction.Interaction);
|
||||||
@@ -26,7 +33,8 @@ ol.interaction.DblClickZoom.prototype.handleMapBrowserEvent =
|
|||||||
mapBrowserEvent.isMouseActionButton()) {
|
mapBrowserEvent.isMouseActionButton()) {
|
||||||
var map = mapBrowserEvent.map;
|
var map = mapBrowserEvent.map;
|
||||||
var anchor = mapBrowserEvent.getCoordinate();
|
var anchor = mapBrowserEvent.getCoordinate();
|
||||||
var delta = mapBrowserEvent.browserEvent.shiftKey ? -4 : 4;
|
var delta = mapBrowserEvent.browserEvent.shiftKey ?
|
||||||
|
-this.delta_ : this.delta_;
|
||||||
map.zoom(delta, anchor);
|
map.zoom(delta, anchor);
|
||||||
mapBrowserEvent.preventDefault();
|
mapBrowserEvent.preventDefault();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ ol.DEFAULT_RENDERER_HINTS = [
|
|||||||
* shiftDragZoom: (boolean|undefined),
|
* shiftDragZoom: (boolean|undefined),
|
||||||
* userProjection: (ol.Projection|string|undefined),
|
* userProjection: (ol.Projection|string|undefined),
|
||||||
* zoom: (number|undefined),
|
* zoom: (number|undefined),
|
||||||
|
* zoomDelta: (number|undefined),
|
||||||
* zoomFactor: (number|undefined)}}
|
* zoomFactor: (number|undefined)}}
|
||||||
*/
|
*/
|
||||||
ol.MapOptionsLiteral;
|
ol.MapOptionsLiteral;
|
||||||
@@ -223,7 +224,9 @@ ol.MapOptions.createInteractions_ = function(mapOptionsLiteral) {
|
|||||||
var doubleClickZoom = goog.isDef(mapOptionsLiteral.doubleClickZoom) ?
|
var doubleClickZoom = goog.isDef(mapOptionsLiteral.doubleClickZoom) ?
|
||||||
mapOptionsLiteral.doubleClickZoom : true;
|
mapOptionsLiteral.doubleClickZoom : true;
|
||||||
if (doubleClickZoom) {
|
if (doubleClickZoom) {
|
||||||
interactions.push(new ol.interaction.DblClickZoom());
|
var zoomDelta = goog.isDef(mapOptionsLiteral.zoomDelta) ?
|
||||||
|
mapOptionsLiteral.zoomDelta : 4;
|
||||||
|
interactions.push(new ol.interaction.DblClickZoom(zoomDelta));
|
||||||
}
|
}
|
||||||
|
|
||||||
var dragPan = goog.isDef(mapOptionsLiteral.dragPan) ?
|
var dragPan = goog.isDef(mapOptionsLiteral.dragPan) ?
|
||||||
|
|||||||
@@ -92,6 +92,31 @@ describe('ol.MapOptions', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
|
describe('create double click interaction', function() {
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
options.doubleClickZoom = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('default zoomDelta', function() {
|
||||||
|
it('create double click interaction with default delta', function() {
|
||||||
|
var interactions = ol.MapOptions.createInteractions_(options);
|
||||||
|
expect(interactions.getLength()).toEqual(1);
|
||||||
|
expect(interactions.getAt(0)).toBeA(ol.interaction.DblClickZoom);
|
||||||
|
expect(interactions.getAt(0).delta_).toEqual(4);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('set mouseWheelZoomDelta', function() {
|
||||||
|
it('create double click interaction with set delta', function() {
|
||||||
|
options.zoomDelta = 7;
|
||||||
|
var interactions = ol.MapOptions.createInteractions_(options);
|
||||||
|
expect(interactions.getLength()).toEqual(1);
|
||||||
|
expect(interactions.getAt(0)).toBeA(ol.interaction.DblClickZoom);
|
||||||
|
expect(interactions.getAt(0).delta_).toEqual(7);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user