@maptiler/geocoding-control 0.0.91-git.896be4 → 0.0.91

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,28 @@
1
1
  <script>export let feature;
2
2
  export let selected = false;
3
3
  export let showPlaceType;
4
+ export let missingIconsCache;
4
5
  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;
6
+ let category;
7
+ let imageUrl;
8
+ $: index = categories?.length ?? 0;
9
+ $: {
10
+ do {
11
+ index--;
12
+ category = categories?.[index];
13
+ imageUrl = category
14
+ ? `/icons/${category.replace(/ /g, "_")}.svg`
15
+ : undefined;
16
+ } while (index > -1 && (!imageUrl || missingIconsCache.has(imageUrl)));
17
+ }
10
18
  $: placeType = feature.id.startsWith("poi.")
11
19
  ? feature.properties?.categories?.join(", ")
12
20
  : feature.properties?.place_type_name?.[0] ?? feature.place_type[0];
13
21
  function handleImgError(e) {
14
- if (index > -1) {
15
- index--;
16
- }
17
- else {
18
- e.style.visibility = "hidden";
22
+ if (imageUrl) {
23
+ missingIconsCache.add(imageUrl);
19
24
  }
25
+ index--;
20
26
  }
21
27
  </script>
22
28
 
@@ -5,6 +5,7 @@ declare const __propDef: {
5
5
  feature: Feature;
6
6
  selected?: boolean | undefined;
7
7
  showPlaceType: false | "always" | "ifNeeded";
8
+ missingIconsCache: Set<string>;
8
9
  };
9
10
  events: {
10
11
  mouseenter: MouseEvent;
@@ -71,6 +71,8 @@ let cachedFeatures = [];
71
71
  let abortController;
72
72
  let searchTimeoutRef;
73
73
  let focusedDelayed;
74
+ let prevIdToFly;
75
+ const missingIconsCache = new Set();
74
76
  const dispatch = createEventDispatcher();
75
77
  $: if (!trackProximity) {
76
78
  proximity = undefined;
@@ -81,19 +83,22 @@ $: if (showFullGeometry &&
81
83
  picked.geometry.type === "Point") {
82
84
  search(picked.id, { byId: true }).catch((err) => (error = err));
83
85
  }
84
- $: if (mapController && picked && flyTo) {
85
- if (!picked.bbox ||
86
- (picked.bbox[0] === picked.bbox[2] && picked.bbox[1] === picked.bbox[3])) {
87
- mapController.flyTo(picked.center, picked.id.startsWith("poi.") || picked.id.startsWith("address.")
88
- ? maxZoom
89
- : zoom);
90
- }
91
- else {
92
- mapController.fitBounds(unwrapBbox(picked.bbox), 50, maxZoom);
86
+ $: {
87
+ if (mapController && picked && picked.id !== prevIdToFly && flyTo) {
88
+ if (!picked.bbox ||
89
+ (picked.bbox[0] === picked.bbox[2] && picked.bbox[1] === picked.bbox[3])) {
90
+ mapController.flyTo(picked.center, picked.id.startsWith("poi.") || picked.id.startsWith("address.")
91
+ ? maxZoom
92
+ : zoom);
93
+ }
94
+ else {
95
+ mapController.fitBounds(unwrapBbox(picked.bbox), 50, maxZoom);
96
+ }
97
+ listFeatures = undefined;
98
+ markedFeatures = undefined;
99
+ selectedItemIndex = -1;
93
100
  }
94
- listFeatures = undefined;
95
- markedFeatures = undefined;
96
- selectedItemIndex = -1;
101
+ prevIdToFly = picked?.id;
97
102
  }
98
103
  $: if (markedFeatures !== listFeatures) {
99
104
  markedFeatures = undefined;
@@ -449,13 +454,14 @@ function unwrapBbox(bbox0) {
449
454
  on:mouseleave={() => (selectedItemIndex = -1)}
450
455
  on:blur={() => undefined}
451
456
  >
452
- {#each listFeatures as feature, i (feature.id)}
457
+ {#each listFeatures as feature, i (feature.id + (feature.address ? "," + feature.address : ""))}
453
458
  <FeatureItem
454
459
  {feature}
455
460
  {showPlaceType}
456
461
  selected={selectedItemIndex === i}
457
462
  on:mouseenter={() => (selectedItemIndex = i)}
458
463
  on:focus={() => pick(feature)}
464
+ {missingIconsCache}
459
465
  />
460
466
  {/each}
461
467
  </ul>