Skip to content

Commit

Permalink
Merge branch 'release-4.3' into jasonliu/maps-1070-programmatic-langu…
Browse files Browse the repository at this point in the history
…age-adjustment-detect-local-language
  • Loading branch information
jaspk06 committed May 15, 2024
2 parents 9582f1c + f804d3f commit 12fbe46
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/ui/RadarMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const defaultMaplibreOptions: Partial<maplibregl.MapOptions> = {
maplibreLogo: false,
};

const defaultFitMarkersOptions: maplibregl.FitBoundsOptions = {
padding: 50,
};

const createStyleURL = (options: RadarOptions, mapOptions: RadarMapOptions) => {
let url = `${options.host}/maps/styles/${mapOptions.style}?publishableKey=${options.publishableKey}`
if (mapOptions.language) {
Expand Down Expand Up @@ -140,6 +144,22 @@ class RadarMap extends maplibregl.Map {
getMarkers(): RadarMarker[] {
return this._markers;
}

fitToMarkers(fitBoundsOptions: maplibregl.FitBoundsOptions = {}, overrideMarkers?: RadarMarker[]) {
const markers = overrideMarkers || this.getMarkers();

if (markers.length === 0) {
return;
}

const bounds = new maplibregl.LngLatBounds();
markers.forEach((marker) => {
bounds.extend(marker.getLngLat());
});

const options = Object.assign(defaultFitMarkersOptions, fitBoundsOptions);
this.fitBounds(bounds, options);
}
};

export default RadarMap;

0 comments on commit 12fbe46

Please sign in to comment.