Skip to content

Commit

Permalink
fix: allow to use mapLibreOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
oterral committed Nov 18, 2024
1 parent ad68865 commit a065154
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion doc/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4518,7 +4518,7 @@ mkdirp@^0.5.1:
minimist "^1.2.6"

mobility-toolbox-js@./../build:
version "3.0.0-beta.34"
version "3.0.0-beta.35"
dependencies:
"@geoblocks/ol-maplibre-layer" "^1.0.1"
"@turf/helpers" "7.1.0"
Expand Down
13 changes: 10 additions & 3 deletions src/ol/layers/MaplibreLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import MobilityLayerMixin, {
MobilityLayerOptions,
} from '../mixins/MobilityLayerMixin';

import type { MapLibreOptions } from '@geoblocks/ol-maplibre-layer/lib/types/MapLibreLayer';
import type {
MapLibreLayerOptions,
MapLibreOptions,
} from '@geoblocks/ol-maplibre-layer/lib/types/MapLibreLayer';
import type { QueryRenderedFeaturesOptions } from 'maplibre-gl';
import type { Options as LayerOptions } from 'ol/layer/Layer';

export type MaplibreLayerOptions = {
apiKey?: string;
Expand All @@ -19,7 +21,7 @@ export type MaplibreLayerOptions = {
queryRenderedFeaturesOptions?: QueryRenderedFeaturesOptions | undefined;
style?: maplibregl.StyleSpecification | null | string;
url?: string;
} & LayerOptions &
} & MapLibreLayerOptions &
MobilityLayerOptions;

const buildStyleUrl = (
Expand Down Expand Up @@ -179,6 +181,11 @@ class MaplibreLayer extends MobilityLayerMixin(MapLibreLayer) {
return this.url;
}

// If the style is defined by the maplibreOptions, we use it directly
if (this.get('mapLibreOptions')?.style) {
return this.get('mapLibreOptions').style;
}

/// Otherwise build the complete style url.
return buildStyleUrl(this.url, this.style, this.apiKey, this.apiKeyName);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ol/mixins/PropertiesLayerMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function PropertiesLayerMixin<TBase extends Layerable>(Base: TBase) {
}

get key(): string {
return this.get('key') || this.get('name') || getUid(this);
return this.get('key') || this.get('name');
}

get map(): Map {
Expand Down

0 comments on commit a065154

Please sign in to comment.