@maptiler/geocoding-control 0.0.91-git.9f388b → 0.0.92

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +1,29 @@
1
1
  <script>export let feature;
2
2
  export let selected = false;
3
3
  export let showPlaceType;
4
+ export let missingIconsCache;
5
+ export let iconsBaseUrl;
4
6
  const categories = feature.properties?.categories;
5
- $: index = (categories?.length ?? 0) - 1;
6
- $: category = categories?.[index];
7
- $: imageUrl = category
8
- ? `/icons/${category.replace(/ /g, "_")}.svg`
9
- : undefined;
7
+ let category;
8
+ let imageUrl;
9
+ $: index = categories?.length ?? 0;
10
+ $: {
11
+ do {
12
+ index--;
13
+ category = categories?.[index];
14
+ imageUrl = category
15
+ ? iconsBaseUrl + category.replace(/ /g, "_") + ".svg"
16
+ : undefined;
17
+ } while (index > -1 && (!imageUrl || missingIconsCache.has(imageUrl)));
18
+ }
10
19
  $: placeType = feature.id.startsWith("poi.")
11
20
  ? feature.properties?.categories?.join(", ")
12
21
  : feature.properties?.place_type_name?.[0] ?? feature.place_type[0];
13
22
  function handleImgError(e) {
14
- if (index > -1) {
15
- index--;
16
- }
17
- else {
18
- e.style.visibility = "hidden";
23
+ if (imageUrl) {
24
+ missingIconsCache.add(imageUrl);
19
25
  }
26
+ index--;
20
27
  }
21
28
  </script>
22
29
 
@@ -29,17 +36,17 @@ function handleImgError(e) {
29
36
  on:error={(e) => handleImgError(e.currentTarget)}
30
37
  />
31
38
  {:else if feature.address}
32
- <img src="/icons/housenumber.svg" alt={placeType} />
39
+ <img src={iconsBaseUrl + "housenumber.svg"} alt={placeType} />
33
40
  {:else if feature.properties?.kind === "road" || feature.properties?.kind === "road_relation"}
34
- <img src="/icons/road.svg" alt={placeType} />
41
+ <img src={iconsBaseUrl + "road.svg"} alt={placeType} />
35
42
  {:else if feature.id.startsWith("address.")}
36
- <img src="/icons/street.svg" alt={placeType} />
43
+ <img src={iconsBaseUrl + "street.svg"} alt={placeType} />
37
44
  {:else if feature.id.startsWith("postal_code.")}
38
- <img src="/icons/postal_code.svg" alt={placeType} />
45
+ <img src={iconsBaseUrl + "postal_code.svg"} alt={placeType} />
39
46
  {:else if feature.id.startsWith("poi.")}
40
- <img src="/icons/poi.svg" alt={placeType} />
47
+ <img src={iconsBaseUrl + "poi.svg"} alt={placeType} />
41
48
  {:else}
42
- <img src="/icons/area.svg" alt={placeType} />
49
+ <img src={iconsBaseUrl + "area.svg"} alt={placeType} />
43
50
  {/if}
44
51
 
45
52
  <span class="texts">
@@ -5,6 +5,8 @@ declare const __propDef: {
5
5
  feature: Feature;
6
6
  selected?: boolean | undefined;
7
7
  showPlaceType: false | "always" | "ifNeeded";
8
+ missingIconsCache: Set<string>;
9
+ iconsBaseUrl: string;
8
10
  };
9
11
  events: {
10
12
  mouseenter: MouseEvent;
@@ -39,6 +39,7 @@ export let zoom = 16;
39
39
  export let maxZoom = 18;
40
40
  export let apiUrl = import.meta.env.VITE_API_URL;
41
41
  export let fetchParameters = {};
42
+ export let iconsBaseUrl = "icons/";
42
43
  export function focus() {
43
44
  input.focus();
44
45
  }
@@ -72,6 +73,7 @@ let abortController;
72
73
  let searchTimeoutRef;
73
74
  let focusedDelayed;
74
75
  let prevIdToFly;
76
+ const missingIconsCache = new Set();
75
77
  const dispatch = createEventDispatcher();
76
78
  $: if (!trackProximity) {
77
79
  proximity = undefined;
@@ -460,6 +462,8 @@ function unwrapBbox(bbox0) {
460
462
  selected={selectedItemIndex === i}
461
463
  on:mouseenter={() => (selectedItemIndex = i)}
462
464
  on:focus={() => pick(feature)}
465
+ {missingIconsCache}
466
+ {iconsBaseUrl}
463
467
  />
464
468
  {/each}
465
469
  </ul>
@@ -34,6 +34,7 @@ declare const __propDef: {
34
34
  maxZoom?: number | undefined;
35
35
  apiUrl?: string | undefined;
36
36
  fetchParameters?: RequestInit | undefined;
37
+ iconsBaseUrl?: string | undefined;
37
38
  focus?: (() => void) | undefined;
38
39
  blur?: (() => void) | undefined;
39
40
  setQuery?: ((value: string, submit?: boolean) => void) | undefined;
package/README.md CHANGED
@@ -128,6 +128,9 @@ For examples without using bundler see `demo-maplibregl.html` or `demo-leaflet.h
128
128
  - `limit`: `number` - Maximum number of results to show. Default `5`.
129
129
  - `country`: `string | string[]` - Limit search to specified country(ies). Default `undefined` (use all countries). Specify as [alpha-2 ISO 3166](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) lowercase code.
130
130
  - `types`: `string[]` - Filter of feature types to return. Default `undefined` (all available feature types are returned).
131
+ - `apiUrl`: `string` - Geocoding API URL. Default MapTiler Geocoding API URL.
132
+ - `fetchParameters`: `RequestInit` - Extra fetch parameters. Default `undefined`.
133
+ - `iconsBaseUrl`: `string` - Base URL for POI icons. Default `"icons/"`.
131
134
 
132
135
  ### Methods
133
136