Skip to content

Commit 8d7d1ff

Browse files
committed
Improve ContextMenuEvent to extend MapBrowserEvent
1 parent c602f66 commit 8d7d1ff

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

src/main.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ export default class ContextMenu extends Control {
268268
this.dispatchEvent(
269269
new ContextMenuEvent({
270270
type: CustomEventTypes.BEFOREOPEN,
271-
pixel: this.pixel,
272-
coordinate: this.coordinate,
271+
map: this.map,
272+
originalEvent: evt
273273
})
274274
);
275275

@@ -281,7 +281,7 @@ export default class ContextMenu extends Control {
281281
}
282282

283283
setTimeout(() => {
284-
this.openMenu();
284+
this.openMenu(evt);
285285
});
286286

287287
evt.target?.addEventListener(
@@ -296,7 +296,7 @@ export default class ContextMenu extends Control {
296296
);
297297
}
298298

299-
protected openMenu() {
299+
protected openMenu(evt: MouseEvent) {
300300
if (this.menuEntries.size === 0) return;
301301

302302
this.opened = true;
@@ -306,8 +306,8 @@ export default class ContextMenu extends Control {
306306
this.dispatchEvent(
307307
new ContextMenuEvent({
308308
type: CustomEventTypes.OPEN,
309-
pixel: this.pixel,
310-
coordinate: this.coordinate,
309+
map: this.map,
310+
originalEvent: evt
311311
})
312312
);
313313
}

src/types.ts

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import type { Coordinate } from 'ol/coordinate';
2-
import type { Pixel } from 'ol/pixel';
3-
import { Map as OlMap } from 'ol';
4-
import BaseEvent from 'ol/events/Event.js';
2+
import { Map as OlMap, MapBrowserEvent } from 'ol';
53

64
export enum EventTypes {
75
CONTEXTMENU = 'contextmenu',
@@ -16,18 +14,13 @@ export enum CustomEventTypes {
1614
ADD_MENU_ENTRY = 'add-menu-entry',
1715
}
1816

19-
export class ContextMenuEvent extends BaseEvent {
20-
public coordinate: Coordinate;
21-
public pixel: Pixel;
22-
17+
export class ContextMenuEvent extends MapBrowserEvent<MouseEvent> {
2318
constructor(options: {
2419
type: `${CustomEventTypes.BEFOREOPEN}` | `${CustomEventTypes.OPEN}`;
25-
coordinate: Coordinate;
26-
pixel: Pixel;
20+
map: OlMap;
21+
originalEvent: MouseEvent;
2722
}) {
28-
super(options.type);
29-
this.pixel = options.pixel;
30-
this.coordinate = options.coordinate;
23+
super(options.type, options.map, options.originalEvent);
3124
}
3225
}
3326

0 commit comments

Comments
 (0)