Skip to content

Commit

Permalink
rename some options
Browse files Browse the repository at this point in the history
  • Loading branch information
kochis committed Jul 25, 2024
1 parent f991ab6 commit e34b84a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ export interface RadarSearchGeofencesResponse extends RadarResponse {

export interface RadarMapOptions extends Omit<maplibregl.MapOptions, 'transformRequest'> {
language?: string;
showZoom?: boolean;
showZoomControls?: boolean;
}

export interface RadarMarkerPopupOptions extends maplibregl.PopupOptions {
Expand Down
26 changes: 16 additions & 10 deletions src/ui/RadarMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ const RADAR_STYLES = [
'radar-dark-v1',
];

// Radar specific configs
const defaultRadarMapOptions: Partial<RadarMapOptions> = {
showZoomControls: true,
};

const defaultMaplibreOptions: Partial<maplibregl.MapOptions> = {
minZoom: 1,
maxZoom: 20,
Expand Down Expand Up @@ -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 = {
Expand All @@ -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) {
Expand All @@ -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');

Expand Down

0 comments on commit e34b84a

Please sign in to comment.