From 03ec6c06704b40a9ac4c817c32931061409af553 Mon Sep 17 00:00:00 2001 From: Max Kohler Date: Wed, 24 Jun 2026 09:45:20 +0200 Subject: [PATCH 1/3] Build out feature --- .../src/maplibre/Geocoder/Geocoder.svelte | 40 +++++----- .../src/maplibre/Geocoder/GeocoderAPIs.ts | 1 + .../src/maplibre/Geocoder/GeocoderProps.ts | 73 ++++++++++--------- .../maplibre/GeocoderControl/GeocoderAPIs.ts | 1 + .../GeocoderControl.stories.svelte | 22 ++++-- .../GeocoderControl/GeocoderControl.svelte | 31 ++++---- 6 files changed, 96 insertions(+), 72 deletions(-) diff --git a/components/src/maplibre/Geocoder/Geocoder.svelte b/components/src/maplibre/Geocoder/Geocoder.svelte index ebacb64a..f7948892 100644 --- a/components/src/maplibre/Geocoder/Geocoder.svelte +++ b/components/src/maplibre/Geocoder/Geocoder.svelte @@ -1,6 +1,9 @@ -
+
diff --git a/components/src/maplibre/Geocoder/GeocoderAPIs.ts b/components/src/maplibre/Geocoder/GeocoderAPIs.ts index 5cd82931..b7c2152c 100644 --- a/components/src/maplibre/Geocoder/GeocoderAPIs.ts +++ b/components/src/maplibre/Geocoder/GeocoderAPIs.ts @@ -24,6 +24,7 @@ export class MaptilerGeocoderAPI implements MaplibreGeocoderApi { country: config.countries || '', language: config.language || '', types: config.types || '', + bbox: config.bbox || '', key: this.key || '' }).filter(([_, value]) => { return value !== ''; diff --git a/components/src/maplibre/Geocoder/GeocoderProps.ts b/components/src/maplibre/Geocoder/GeocoderProps.ts index 8b1b2a71..1592cc19 100644 --- a/components/src/maplibre/Geocoder/GeocoderProps.ts +++ b/components/src/maplibre/Geocoder/GeocoderProps.ts @@ -1,38 +1,41 @@ -import { Map } from "maplibre-gl"; +import { Map } from 'maplibre-gl'; import { - type GeocodingCountry, - type GeocodingLanguage, - type GeocodingPlaceType, - type GeocodingService - } from '../types'; - + type GeocodingCountry, + type GeocodingLanguage, + type GeocodingPlaceType, + type GeocodingService +} from '../types'; export default interface GeocoderProps { - map?: Map | null - service: GeocodingService; - /** - * API key for selected geocoding `service` - */ - key: string; - /** - * Limit the number of returned suggestions - */ - limit?: number; - /** - * Limit search to one or more countries - */ - countries?: GeocodingCountry | GeocodingCountry[]; - /** - * Limit search to one or more result type. - */ - types?: GeocodingPlaceType | GeocodingPlaceType[]; - /** - * Limit search to one or more languages. The UI is localised to the first language specified if [available](https://github.com/maplibre/maplibre-gl-geocoder/blob/main/lib/localization.ts). - */ - languages?: GeocodingLanguage | GeocodingLanguage[]; - /** - * Overwrite the default input placeholder - */ - placeholder?: string; - size?: "small" | "default" - } + map?: Map | null; + service: GeocodingService; + /** + * API key for selected geocoding `service` + */ + key: string; + /** + * Limit the number of returned suggestions + */ + limit?: number; + /** + * Limit search to one or more countries + */ + countries?: GeocodingCountry | GeocodingCountry[]; + /** + * Limit search to one or more result type + */ + types?: GeocodingPlaceType | GeocodingPlaceType[]; + /** + * Limit search to a [w, s, e, n] bounding box + */ + bbox?: number[]; + /** + * Limit search to one or more languages. The UI is localised to the first language specified if [available](https://github.com/maplibre/maplibre-gl-geocoder/blob/main/lib/localization.ts). + */ + languages?: GeocodingLanguage | GeocodingLanguage[]; + /** + * Overwrite the default input placeholder + */ + placeholder?: string; + size?: 'small' | 'default'; +} diff --git a/components/src/maplibre/GeocoderControl/GeocoderAPIs.ts b/components/src/maplibre/GeocoderControl/GeocoderAPIs.ts index 5cd82931..de565fc0 100644 --- a/components/src/maplibre/GeocoderControl/GeocoderAPIs.ts +++ b/components/src/maplibre/GeocoderControl/GeocoderAPIs.ts @@ -24,6 +24,7 @@ export class MaptilerGeocoderAPI implements MaplibreGeocoderApi { country: config.countries || '', language: config.language || '', types: config.types || '', + bbox: config.bbox?.join(',') || '', key: this.key || '' }).filter(([_, value]) => { return value !== ''; diff --git a/components/src/maplibre/GeocoderControl/GeocoderControl.stories.svelte b/components/src/maplibre/GeocoderControl/GeocoderControl.stories.svelte index 36862a7c..b127cc63 100644 --- a/components/src/maplibre/GeocoderControl/GeocoderControl.stories.svelte +++ b/components/src/maplibre/GeocoderControl/GeocoderControl.stories.svelte @@ -34,11 +34,7 @@
- +
@@ -119,6 +115,22 @@ + + +
+ + + +
+
+
From c55dce840606e67c643bbe40cfdf8808924d4e46 Mon Sep 17 00:00:00 2001 From: Max Kohler Date: Wed, 24 Jun 2026 09:49:50 +0200 Subject: [PATCH 2/3] fix type error --- components/src/maplibre/Geocoder/GeocoderAPIs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/src/maplibre/Geocoder/GeocoderAPIs.ts b/components/src/maplibre/Geocoder/GeocoderAPIs.ts index b7c2152c..de565fc0 100644 --- a/components/src/maplibre/Geocoder/GeocoderAPIs.ts +++ b/components/src/maplibre/Geocoder/GeocoderAPIs.ts @@ -24,7 +24,7 @@ export class MaptilerGeocoderAPI implements MaplibreGeocoderApi { country: config.countries || '', language: config.language || '', types: config.types || '', - bbox: config.bbox || '', + bbox: config.bbox?.join(',') || '', key: this.key || '' }).filter(([_, value]) => { return value !== ''; From b31750c5d531376abf2954122f6e4ceb9204c068 Mon Sep 17 00:00:00 2001 From: Max Kohler Date: Wed, 24 Jun 2026 09:50:40 +0200 Subject: [PATCH 3/3] add missing derived() --- .../src/maplibre/Geocoder/Geocoder.svelte | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/components/src/maplibre/Geocoder/Geocoder.svelte b/components/src/maplibre/Geocoder/Geocoder.svelte index f7948892..3c2d0694 100644 --- a/components/src/maplibre/Geocoder/Geocoder.svelte +++ b/components/src/maplibre/Geocoder/Geocoder.svelte @@ -29,18 +29,20 @@ // Future: initialise a different GeocoderAPI depending on "service" let geocoderAPI: MaplibreGeocoderApi = $derived(new MaptilerGeocoderAPI(key)); - const geocoder = new MaplibreGeocoder(geocoderAPI, { - maplibregl: maplibre, - language: languagesArr.join(','), - countries: countriesArr.join(','), - types: typesArr.join(','), - bbox: bbox, - showResultsWhileTyping: true, - showResultMarkers: false, - debounceSearch: 25, - placeholder, - limit - }); + const geocoder = $derived( + new MaplibreGeocoder(geocoderAPI, { + maplibregl: maplibre, + language: languagesArr.join(','), + countries: countriesArr.join(','), + types: typesArr.join(','), + bbox: bbox, + showResultsWhileTyping: true, + showResultMarkers: false, + debounceSearch: 25, + placeholder, + limit + }) + ); const handleResult = (r: { result: CarmenGeojsonFeature }) => { const res = r.result;