From e34b84a41c9b53d4837791bfc169e91db8939d45 Mon Sep 17 00:00:00 2001 From: Craig Kochis Date: Thu, 25 Jul 2024 11:49:33 -0400 Subject: [PATCH] rename some options --- src/types.ts | 2 +- src/ui/RadarMap.ts | 26 ++++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/types.ts b/src/types.ts index 293fca3..8864fb7 100644 --- a/src/types.ts +++ b/src/types.ts @@ -461,7 +461,7 @@ export interface RadarSearchGeofencesResponse extends RadarResponse { export interface RadarMapOptions extends Omit { language?: string; - showZoom?: boolean; + showZoomControls?: boolean; } export interface RadarMarkerPopupOptions extends maplibregl.PopupOptions { diff --git a/src/ui/RadarMap.ts b/src/ui/RadarMap.ts index 630233c..e867a9d 100644 --- a/src/ui/RadarMap.ts +++ b/src/ui/RadarMap.ts @@ -17,6 +17,11 @@ const RADAR_STYLES = [ 'radar-dark-v1', ]; +// Radar specific configs +const defaultRadarMapOptions: Partial = { + showZoomControls: true, +}; + const defaultMaplibreOptions: Partial = { minZoom: 1, maxZoom: 20, @@ -65,26 +70,27 @@ const getStyle = (options: RadarOptions, mapOptions: RadarMapOptions) => { class RadarMap extends maplibregl.Map { _markers: RadarMarker[] = []; - constructor(mapOptions: RadarMapOptions) { + constructor(radarMapOptions: RadarMapOptions) { const config = Config.get(); if (!config.publishableKey) { Logger.warn('publishableKey not set. Call Radar.initialize() with key before creating a new map.'); } - // configure maplibre options - const style = getStyle(config, mapOptions); - const maplibreOptions: RadarMapOptions = Object.assign({}, + // configure map options + const style = getStyle(config, radarMapOptions); + const mapOptions: RadarMapOptions = Object.assign({}, + defaultRadarMapOptions, defaultMaplibreOptions, - mapOptions, + radarMapOptions, { style }, ); - Logger.debug(`initialize map with options: ${JSON.stringify(maplibreOptions)}`); + Logger.debug(`initialize map with options: ${JSON.stringify(mapOptions)}`); - (maplibreOptions as maplibregl.MapOptions).transformRequest = (url, resourceType) => { + (mapOptions as maplibregl.MapOptions).transformRequest = (url, resourceType) => { // this handles when a style is switched if (resourceType === 'Style' && isRadarStyle(url)) { - url = createStyleURL(config, { ...maplibreOptions, style: url }); + url = createStyleURL(config, { ...mapOptions, style: url }); } let headers = { @@ -99,7 +105,7 @@ class RadarMap extends maplibregl.Map { return { url, headers }; }; - super(maplibreOptions); + super(mapOptions); // initialize MapLibre instance const container = this.getContainer(); if (!container.style.width && !container.style.height) { @@ -117,7 +123,7 @@ class RadarMap extends maplibregl.Map { // add zoom controls const nav = new maplibregl.NavigationControl({ showCompass: false, - showZoom: maplibreOptions.showZoom ?? true, + showZoom: mapOptions.showZoomControls, }); this.addControl(nav, 'bottom-right');