You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.7 KiB
65 lines
1.7 KiB
/**
|
|
* @module ol/interaction/DoubleClickZoom
|
|
*/
|
|
import Interaction, {zoomByDelta} from './Interaction.js';
|
|
import MapBrowserEventType from '../MapBrowserEventType.js';
|
|
|
|
/**
|
|
* @typedef {Object} Options
|
|
* @property {number} [duration=250] Animation duration in milliseconds.
|
|
* @property {number} [delta=1] The zoom delta applied on each double click.
|
|
*/
|
|
|
|
/**
|
|
* @classdesc
|
|
* Allows the user to zoom by double-clicking on the map.
|
|
* @api
|
|
*/
|
|
class DoubleClickZoom extends Interaction {
|
|
/**
|
|
* @param {Options} [options] Options.
|
|
*/
|
|
constructor(options) {
|
|
super();
|
|
|
|
options = options ? options : {};
|
|
|
|
/**
|
|
* @private
|
|
* @type {number}
|
|
*/
|
|
this.delta_ = options.delta ? options.delta : 1;
|
|
|
|
/**
|
|
* @private
|
|
* @type {number}
|
|
*/
|
|
this.duration_ = options.duration !== undefined ? options.duration : 250;
|
|
}
|
|
|
|
/**
|
|
* Handles the {@link module:ol/MapBrowserEvent~MapBrowserEvent map browser event} (if it was a
|
|
* doubleclick) and eventually zooms the map.
|
|
* @param {import("../MapBrowserEvent.js").default} mapBrowserEvent Map browser event.
|
|
* @return {boolean} `false` to stop event propagation.
|
|
*/
|
|
handleEvent(mapBrowserEvent) {
|
|
let stopEvent = false;
|
|
if (mapBrowserEvent.type == MapBrowserEventType.DBLCLICK) {
|
|
const browserEvent = /** @type {MouseEvent} */ (
|
|
mapBrowserEvent.originalEvent
|
|
);
|
|
const map = mapBrowserEvent.map;
|
|
const anchor = mapBrowserEvent.coordinate;
|
|
const delta = browserEvent.shiftKey ? -this.delta_ : this.delta_;
|
|
const view = map.getView();
|
|
zoomByDelta(view, delta, anchor, this.duration_);
|
|
browserEvent.preventDefault();
|
|
stopEvent = true;
|
|
}
|
|
return !stopEvent;
|
|
}
|
|
}
|
|
|
|
export default DoubleClickZoom;
|