Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow map event propagation on marker click #172

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/ui/RadarMarker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,28 @@ import type RadarMap from './RadarMap';

import type { RadarMarkerOptions } from '../types';

class RadarMarkerMouseEvent {
type: 'click';
target: RadarMarker;
originalEvent: MouseEvent;
lngLat: maplibregl.LngLat;
point: maplibregl.Point2D;

constructor(type: 'click', marker: RadarMarker, originalEvent: MouseEvent) {
this.target = marker;
this.originalEvent = originalEvent;
this.point = marker._pos;
this.lngLat = marker.getLngLat();
this.type = type;
}
}

interface ImageOptions {
url?: string;
width?: number | string;
height?: number | string;
}


const createImageElement = (options: ImageOptions) => {
const element = document.createElement('img');
element.src = options.url!;
Expand Down Expand Up @@ -145,11 +160,7 @@ class RadarMarker extends maplibregl.Marker {
const element = this.getElement();
if (element) {
element.addEventListener('click', (e) => {
e.stopPropagation(); // stop propagation to map
if (this._popup) {
this.togglePopup();
}
this.fire('click', e);
this.fire('click', new RadarMarkerMouseEvent('click', this, e));
});
}
}
Expand Down
Loading