共计 1299 个字符,预计需要花费 4 分钟才能阅读完成。
本文次要学习 openlayers 的 Event 模块相干源码
BaseEvent
Openlayers 依据 W3C DOM Level 2 Event 接口简化实现了本人的事件类, 它只提供了 type
和target
属性以及 preventDefault
和stopPropagation
办法。
class BaseEvent {
/**
* @param {string} type Type.
*/
constructor(type) {
/**
* @type {boolean}
*/
this.propagationStopped;
/**
* @type {boolean}
*/
this.defaultPrevented;
/**
* The event type.
* @type {string}
* @api
*/
this.type = type;
/**
* The event target.
* @type {Object}
* @api
*/
this.target = null;
}
/**
* Prevent default. This means that no emulated `click`, `singleclick` or `doubleclick` events
* will be fired.
* @api
*/
preventDefault() {this.defaultPrevented = true;}
/**
* Stop event propagation.
* @api
*/
stopPropagation() {this.propagationStopped = true;}
}
EventType
EventType
对象保留了所有触发地图事件的事件名称。
/**
* @enum {string}
* @const
*/
export default {
/**
* Generic change event. Triggered when the revision counter is increased.
* @event module:ol/events/Event~BaseEvent#change
* @api
*/
CHANGE: 'change',
/**
* Generic error event. Triggered when an error occurs.
* @event module:ol/events/Event~BaseEvent#error
* @api
*/
ERROR: 'error',
BLUR: 'blur',
CLEAR: 'clear',
CONTEXTMENU: 'contextmenu',
CLICK: 'click',
DBLCLICK: 'dblclick',
DRAGENTER: 'dragenter',
DRAGOVER: 'dragover',
DROP: 'drop',
FOCUS: 'focus',
KEYDOWN: 'keydown',
KEYPRESS: 'keypress',
LOAD: 'load',
RESIZE: 'resize',
TOUCHMOVE: 'touchmove',
WHEEL: 'wheel',
};
KeyCode
KeyCode
对象只记录了上下左右键盘方向键的 keycode,便于事件监听。
export default {
LEFT: 37,
UP: 38,
RIGHT: 39,
DOWN: 40,
};
正文完
发表至: openlayers
2022-11-28