Skip to content

Commit

Permalink
RadarMarker popup improvements (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspk06 authored May 31, 2024
1 parent 32a1280 commit 0ec50cd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,16 @@ export interface RadarMarkerImage {
height?: number;
}

export interface RadarMarkerPopupOptions extends maplibregl.PopupOptions {
text?: string;
html?: string;
}

export interface RadarMarkerOptions extends maplibregl.MarkerOptions {
text?: string;
html?: string;
image?: RadarMarkerImage;
popup?: RadarMarkerPopupOptions;
}

export interface RadarAutocompleteUIOptions {
Expand Down
27 changes: 21 additions & 6 deletions src/ui/RadarMarker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type RadarMap from './RadarMap';

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

const defaultMarkerOptions: maplibregl.MarkerOptions = {
const defaultMarkerOptions: RadarMarkerOptions = {
color: '#000257',
};

Expand Down Expand Up @@ -93,12 +93,27 @@ class RadarMarker extends maplibregl.Marker {
}
}

// set popup text or HTML
// handle deprecated popup options
if (markerOptions.text) {
const popup = new maplibregl.Popup({ offset: 35 }).setText(markerOptions.text);
this.setPopup(popup);
} else if (markerOptions.html) {
const popup = new maplibregl.Popup({ offset: 35 }).setHTML(markerOptions.html);
markerOptions.popup = markerOptions.popup || {};
markerOptions.popup!.text = markerOptions.text;
}
if (markerOptions.html) {
markerOptions.popup = markerOptions.popup || {};
markerOptions.popup!.html = markerOptions.html;
}

// set popup text or HTML
if (markerOptions.popup) {
const popup = new maplibregl.Popup(markerOptions.popup)

if (markerOptions.popup.text) {
popup.setText(markerOptions.popup.text);
}
if (markerOptions.popup.html) {
popup.setHTML(markerOptions.popup.html);
}

this.setPopup(popup);
}
}
Expand Down

0 comments on commit 0ec50cd

Please sign in to comment.