/
MapBrowserEvent.js
115 lines (104 loc) · 3.08 KB
/
MapBrowserEvent.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
* @module ol/MapBrowserEvent
*/
import MapEvent from './MapEvent.js';
/**
* @classdesc
* Events emitted as map browser events are instances of this type.
* See {@link module:ol/Map~Map} for which events trigger a map browser event.
* @template {UIEvent} EVENT
*/
class MapBrowserEvent extends MapEvent {
/**
* @param {string} type Event type.
* @param {import("./Map.js").default} map Map.
* @param {EVENT} originalEvent Original event.
* @param {boolean} [dragging] Is the map currently being dragged?
* @param {import("./Map.js").FrameState} [frameState] Frame state.
* @param {Array<PointerEvent>} [activePointers] Active pointers.
*/
constructor(type, map, originalEvent, dragging, frameState, activePointers) {
super(type, map, frameState);
/**
* The original browser event.
* @const
* @type {EVENT}
* @api
*/
this.originalEvent = originalEvent;
/**
* The map pixel relative to the viewport corresponding to the original browser event.
* @type {?import("./pixel.js").Pixel}
*/
this.pixel_ = null;
/**
* The coordinate in the user projection corresponding to the original browser event.
* @type {?import("./coordinate.js").Coordinate}
*/
this.coordinate_ = null;
/**
* Indicates if the map is currently being dragged. Only set for
* `POINTERDRAG` and `POINTERMOVE` events. Default is `false`.
*
* @type {boolean}
* @api
*/
this.dragging = dragging !== undefined ? dragging : false;
/**
* @type {Array<PointerEvent>|undefined}
*/
this.activePointers = activePointers;
}
/**
* The map pixel relative to the viewport corresponding to the original event.
* @type {import("./pixel.js").Pixel}
* @api
*/
get pixel() {
if (!this.pixel_) {
this.pixel_ = this.map.getEventPixel(this.originalEvent);
}
return this.pixel_;
}
set pixel(pixel) {
this.pixel_ = pixel;
}
/**
* The coordinate corresponding to the original browser event. This will be in the user
* projection if one is set. Otherwise it will be in the view projection.
* @type {import("./coordinate.js").Coordinate}
* @api
*/
get coordinate() {
if (!this.coordinate_) {
this.coordinate_ = this.map.getCoordinateFromPixel(this.pixel);
}
return this.coordinate_;
}
set coordinate(coordinate) {
this.coordinate_ = coordinate;
}
/**
* Prevents the default browser action.
* See https://developer.mozilla.org/en-US/docs/Web/API/event.preventDefault.
* @api
*/
preventDefault() {
super.preventDefault();
if ('preventDefault' in this.originalEvent) {
/** @type {UIEvent} */ (this.originalEvent).preventDefault();
}
}
/**
* Prevents further propagation of the current event.
* See https://developer.mozilla.org/en-US/docs/Web/API/event.stopPropagation.
* @api
*/
stopPropagation() {
super.stopPropagation();
if ('stopPropagation' in this.originalEvent) {
/** @type {UIEvent} */ (this.originalEvent).stopPropagation();
}
}
}
export default MapBrowserEvent;