@maptiler/geocoding-control 0.0.88 → 0.0.89

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.
package/ClearIcon.svelte CHANGED
@@ -1,6 +1,6 @@
1
- <svg viewBox="0 0 18 18" width="16" height="16">
1
+ <svg viewBox="0 0 14 14" width="13" height="13">
2
2
  <path
3
- d="M3.8 2.5c-.6 0-1.3.7-1.3 1.3 0 .3.2.7.5.8L7.2 9 3 13.2c-.3.3-.5.7-.5 1 0 .6.7 1.3 1.3 1.3.3 0 .7-.2 1-.5L9 10.8l4.2 4.2c.2.3.7.3 1 .3.6 0 1.3-.7 1.3-1.3 0-.3-.2-.7-.3-1l-4.4-4L15 4.6c.3-.2.5-.5.5-.8 0-.7-.7-1.3-1.3-1.3-.3 0-.7.2-1 .3L9 7.1 4.8 2.8c-.3-.1-.7-.3-1-.3z"
3
+ d="M13.12.706a.982.982 0 0 0-1.391 0L6.907 5.517 2.087.696a.982.982 0 1 0-1.391 1.39l4.821 4.821L.696 11.73a.982.982 0 1 0 1.39 1.39l4.821-4.821 4.822 4.821a.982.982 0 1 0 1.39-1.39L8.298 6.908l4.821-4.822a.988.988 0 0 0 0-1.38Z"
4
4
  />
5
5
  </svg>
6
6
 
@@ -0,0 +1,12 @@
1
+ <svg viewBox="0 0 30 30" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path
3
+ d="M15 0C6.705 0 0 6.705 0 15C0 23.295 6.705 30 15 30C23.295 30 30 23.295 30 15C30 6.705 23.295 0 15 0ZM22.5 20.385L20.385 22.5L15 17.115L9.615 22.5L7.5 20.385L12.885 15L7.5 9.615L9.615 7.5L15 12.885L20.385 7.5L22.5 9.615L17.115 15L22.5 20.385Z"
4
+ />
5
+ </svg>
6
+
7
+ <style>
8
+ svg {
9
+ display: block;
10
+ fill: #e15042;
11
+ }
12
+ </style>
@@ -0,0 +1,23 @@
1
+ /** @typedef {typeof __propDef.props} FailIconProps */
2
+ /** @typedef {typeof __propDef.events} FailIconEvents */
3
+ /** @typedef {typeof __propDef.slots} FailIconSlots */
4
+ export default class FailIcon extends SvelteComponentTyped<{
5
+ [x: string]: never;
6
+ }, {
7
+ [evt: string]: CustomEvent<any>;
8
+ }, {}> {
9
+ }
10
+ export type FailIconProps = typeof __propDef.props;
11
+ export type FailIconEvents = typeof __propDef.events;
12
+ export type FailIconSlots = typeof __propDef.slots;
13
+ import { SvelteComponentTyped } from "svelte";
14
+ declare const __propDef: {
15
+ props: {
16
+ [x: string]: never;
17
+ };
18
+ events: {
19
+ [evt: string]: CustomEvent<any>;
20
+ };
21
+ slots: {};
22
+ };
23
+ export {};
@@ -0,0 +1,95 @@
1
+ <script>export let feature;
2
+ export let selected = false;
3
+ export let showPlaceType = false;
4
+ </script>
5
+
6
+ <!-- svelte-ignore a11y-no-noninteractive-tabindex -->
7
+ <li tabindex="0" data-selected={selected} class:selected on:mouseenter on:focus>
8
+ <!-- <MarkerIcon displayIn="list" /> -->
9
+ <span class="texts">
10
+ <span>
11
+ <span class="primary">
12
+ {feature.place_name.replace(/,.*/, "")}
13
+ </span>
14
+
15
+ <span class="secondary">
16
+ {feature.place_name.replace(/[^,]*,?\s*/, "")}
17
+ </span>
18
+ </span>
19
+
20
+ {#if showPlaceType}
21
+ <span class="line2">
22
+ {feature.properties?.place_type_name?.[0] ?? feature.place_type[0]}
23
+ </span>
24
+ {/if}
25
+ </span>
26
+ </li>
27
+
28
+ <style>li {
29
+ text-align: left;
30
+ cursor: default;
31
+ display: grid;
32
+ grid-template-columns: 1fr;
33
+ color: var(--color-text);
34
+ padding: 8px 0px;
35
+ font-size: 14px;
36
+ line-height: 18px;
37
+ }
38
+ li:first-child {
39
+ padding-top: 10px;
40
+ }
41
+ li:last-child {
42
+ padding-bottom: 10px;
43
+ }
44
+ li.selected {
45
+ background-color: #f3f6ff;
46
+ }
47
+ li.selected .texts > * {
48
+ animation: backAndForth 5s linear infinite;
49
+ }
50
+ li.selected .primary {
51
+ color: #2b8bfb;
52
+ }
53
+
54
+ .texts {
55
+ padding: 0 17px;
56
+ }
57
+ .texts > * {
58
+ white-space: nowrap;
59
+ display: block;
60
+ min-width: fit-content;
61
+ }
62
+
63
+ .primary {
64
+ font-weight: 600;
65
+ }
66
+
67
+ .secondary {
68
+ color: #aeb6c7;
69
+ padding-left: 4px;
70
+ }
71
+
72
+ .line2 {
73
+ color: #aeb6c7;
74
+ }
75
+
76
+ @keyframes backAndForth {
77
+ 0% {
78
+ transform: translateX(0);
79
+ }
80
+ 10% {
81
+ transform: translateX(0);
82
+ }
83
+ 45% {
84
+ transform: translateX(calc(-100% + 236px));
85
+ }
86
+ 55% {
87
+ transform: translateX(calc(-100% + 236px));
88
+ }
89
+ 90% {
90
+ transform: translateX(0);
91
+ }
92
+ 100% {
93
+ transform: translateX(0);
94
+ }
95
+ }</style>
@@ -0,0 +1,22 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ import type { Feature } from "./types";
3
+ declare const __propDef: {
4
+ props: {
5
+ feature: Feature;
6
+ selected?: boolean | undefined;
7
+ showPlaceType?: boolean | undefined;
8
+ };
9
+ events: {
10
+ mouseenter: MouseEvent;
11
+ focus: FocusEvent;
12
+ } & {
13
+ [evt: string]: CustomEvent<any>;
14
+ };
15
+ slots: {};
16
+ };
17
+ export type FeatureItemProps = typeof __propDef.props;
18
+ export type FeatureItemEvents = typeof __propDef.events;
19
+ export type FeatureItemSlots = typeof __propDef.slots;
20
+ export default class FeatureItem extends SvelteComponentTyped<FeatureItemProps, FeatureItemEvents, FeatureItemSlots> {
21
+ }
22
+ export {};
@@ -1,6 +1,8 @@
1
1
  <script>import { createEventDispatcher } from "svelte";
2
2
  import { onDestroy } from "svelte/internal";
3
3
  import ClearIcon from "./ClearIcon.svelte";
4
+ import FailIcon from "./FailIcon.svelte";
5
+ import FeatureItem from "./FeatureItem.svelte";
4
6
  import LoadingIcon from "./LoadingIcon.svelte";
5
7
  import ReverseGeocodingIcon from "./ReverseGeocodingIcon.svelte";
6
8
  import SearchIcon from "./SearchIcon.svelte";
@@ -14,7 +16,7 @@ export let collapsed = false;
14
16
  export let country = undefined;
15
17
  export let debounceSearch = 200;
16
18
  export let enableReverse = false;
17
- export let errorMessage = "Searching failed";
19
+ export let errorMessage = "Something went wrong…";
18
20
  export let filter = () => true;
19
21
  export let flyTo = true;
20
22
  export let fuzzyMatch = true;
@@ -22,7 +24,7 @@ export let language = undefined;
22
24
  export let limit = undefined;
23
25
  export let mapController = undefined;
24
26
  export let minLength = 2;
25
- export let noResultsMessage = "No results found";
27
+ export let noResultsMessage = "Oops! Looks like you're trying to predict something that's not quite right. We can't seem to find what you're looking for. Maybe try double-checking your spelling or try a different search term. Keep on typing - we'll do our best to get you where you need to go!";
26
28
  export let placeholder = "Search";
27
29
  export let proximity = undefined;
28
30
  export let reverseActive = enableReverse === "always";
@@ -338,10 +340,14 @@ function handleKeyDown(e) {
338
340
  }
339
341
  }
340
342
  function handleInput(debounce = true) {
341
- if (showResultsWhileTyping && searchValue.length > minLength) {
343
+ error = undefined;
344
+ if (showResultsWhileTyping) {
342
345
  if (searchTimeoutRef) {
343
346
  clearTimeout(searchTimeoutRef);
344
347
  }
348
+ if (searchValue.length <= minLength) {
349
+ return;
350
+ }
345
351
  const sv = searchValue;
346
352
  searchTimeoutRef = window.setTimeout(() => {
347
353
  search(sv).catch((err) => (error = err));
@@ -374,7 +380,7 @@ function unwrapBbox(bbox0) {
374
380
  class={className}
375
381
  >
376
382
  <div class="input-group">
377
- <button type="button" on:click={() => input.focus()}>
383
+ <button class="search-button" type="button" on:click={() => input.focus()}>
378
384
  <SearchIcon />
379
385
  </button>
380
386
 
@@ -421,43 +427,36 @@ function unwrapBbox(bbox0) {
421
427
  </div>
422
428
 
423
429
  {#if error}
424
- <div class="error">{errorMessage}</div>
430
+ <div class="error">
431
+ <FailIcon />
432
+
433
+ <div>{errorMessage}</div>
434
+
435
+ <button on:click={() => (error = undefined)}>
436
+ <ClearIcon />
437
+ </button>
438
+ </div>
425
439
  {:else if !focusedDelayed}
426
440
  {""}
427
441
  {:else if listFeatures?.length === 0}
428
- <div class="no-results">{noResultsMessage}</div>
442
+ <div class="no-results">
443
+ <FailIcon />
444
+
445
+ <div>{noResultsMessage}</div>
446
+ </div>
429
447
  {:else if focusedDelayed && listFeatures?.length}
430
448
  <ul
431
449
  on:mouseleave={() => (selectedItemIndex = -1)}
432
450
  on:blur={() => undefined}
433
451
  >
434
452
  {#each listFeatures as feature, i}
435
- <!-- svelte-ignore a11y-no-noninteractive-tabindex -->
436
- <li
437
- tabindex="0"
438
- data-selected={selectedItemIndex === i}
439
- class:selected={selectedItemIndex === i}
453
+ <FeatureItem
454
+ {feature}
455
+ {showPlaceType}
456
+ selected={selectedItemIndex === i}
440
457
  on:mouseenter={() => (selectedItemIndex = i)}
441
458
  on:focus={() => pick(feature)}
442
- >
443
- <!-- <MarkerIcon displayIn="list" /> -->
444
- <span class="texts">
445
- <span class="line1">
446
- <span class="primary">
447
- {feature.place_name.replace(/,.*/, "")}
448
- </span>
449
- <span class="secondary">
450
- {feature.place_name.replace(/[^,]*,?\s*/, "")}
451
- </span>
452
- </span>
453
- {#if showPlaceType}
454
- <span class="line2">
455
- {feature.properties?.place_type_name?.[0] ??
456
- feature.place_type[0]}
457
- </span>
458
- {/if}
459
- </span>
460
- </li>
459
+ />
461
460
  {/each}
462
461
  </ul>
463
462
  {/if}
@@ -470,7 +469,7 @@ function unwrapBbox(bbox0) {
470
469
  z-index: 10;
471
470
  border-radius: 4px;
472
471
  transition: max-width 0.25s;
473
- /* box-shadow: 0px 5px 10px rgba(51, 51, 89, 0.15); */
472
+ box-shadow: 0px 2px 5px rgba(51, 51, 89, 0.15);
474
473
  --color-text: #444952;
475
474
  --color-icon-button: #444952;
476
475
  }
@@ -478,31 +477,24 @@ form, form *, form *:after, form *:before {
478
477
  box-sizing: border-box;
479
478
  }
480
479
  form.can-collapse {
481
- max-width: 30px;
482
- }
483
- form.can-collapse .input-group {
484
- padding-inline: 5px;
485
- transition: padding-inline 0.25s;
486
- }
487
- form.can-collapse:focus-within .input-group, form.can-collapse:hover .input-group {
488
- padding-inline: 8px;
480
+ max-width: 29px;
489
481
  }
490
482
  form, form:focus-within, form:hover {
491
- width: 240px;
492
- max-width: 240px;
483
+ width: 270px;
484
+ max-width: 270px;
493
485
  }
494
486
 
495
487
  input {
496
488
  font: inherit;
497
489
  font-size: 14px;
498
- width: 100%;
499
- min-height: 28px;
500
- border: 0;
490
+ flex-grow: 1;
491
+ min-height: 29px;
501
492
  background-color: transparent;
502
- margin: 0;
503
493
  color: #444952;
504
494
  white-space: nowrap;
505
495
  overflow: hidden;
496
+ border: 0;
497
+ margin: 0;
506
498
  padding: 0;
507
499
  }
508
500
  input:focus {
@@ -524,64 +516,68 @@ div.no-results {
524
516
  position: absolute;
525
517
  width: 100%;
526
518
  top: calc(100% + 6px);
527
- font-size: 14px;
528
- box-shadow: 0px 2px 8px rgba(51, 51, 89, 0.15);
529
- line-height: 16px;
530
519
  overflow: hidden;
531
520
  }
532
521
 
533
- :global(.maplibregl-ctrl-bottom-left) ul,
534
- :global(.maplibregl-ctrl-bottom-right) ul {
535
- top: auto;
536
- bottom: 100%;
522
+ ul {
523
+ font-size: 14px;
524
+ line-height: 16px;
525
+ box-shadow: 0px 5px 10px rgba(51, 51, 89, 0.15);
537
526
  }
538
527
 
539
- li {
540
- text-align: left;
541
- cursor: default;
542
- display: grid;
543
- grid-template-columns: 1fr;
544
- color: var(--color-text);
545
- padding: 8px 0px;
546
- font-size: 14px;
528
+ div.error,
529
+ div.no-results {
530
+ font: inherit;
547
531
  line-height: 18px;
532
+ font-size: 12px;
533
+ display: flex;
534
+ gap: 16px;
548
535
  }
549
- li:first-child {
550
- padding-top: 10px;
536
+
537
+ div.error {
538
+ padding: 16px;
539
+ font-weight: 600;
540
+ color: #e25041;
541
+ background-color: #fbeae8;
551
542
  }
552
- li:last-child {
553
- padding-bottom: 10px;
543
+ div.error div {
544
+ flex-grow: 1;
554
545
  }
555
- li.selected {
556
- background-color: #f3f6ff;
546
+ div.error :global(svg) {
547
+ flex-shrink: 0;
548
+ width: 20px;
549
+ height: 20px;
557
550
  }
558
- li.selected .texts > * {
559
- animation: backAndForth 5s linear infinite;
551
+ div.error button {
552
+ flex-shrink: 0;
560
553
  }
561
- li.selected .primary {
562
- color: #2b8bfb;
554
+ div.error button > :global(svg) {
555
+ width: 13px;
556
+ fill: #e25041;
563
557
  }
564
-
565
- .texts {
566
- padding: 0 17px;
567
- }
568
- .texts > * {
569
- white-space: nowrap;
570
- display: block;
571
- min-width: fit-content;
558
+ div.error button:hover :global(svg), div.error button:active :global(svg) {
559
+ fill: #444952;
572
560
  }
573
561
 
574
- .primary {
575
- font-weight: 600;
576
- }
577
-
578
- .secondary {
579
- color: #aeb6c7;
580
- padding-left: 4px;
562
+ div.no-results {
563
+ padding: 14px 24px 14px 16px;
564
+ font-weight: 400;
565
+ color: #6b7c93;
566
+ box-shadow: 0px 5px 10px rgba(51, 51, 89, 0.15);
567
+ }
568
+ div.no-results :global(svg) {
569
+ margin-top: 4px;
570
+ flex-shrink: 0;
571
+ width: 20px;
572
+ height: 20px;
573
+ width: 30px;
574
+ height: 30px;
581
575
  }
582
576
 
583
- .line2 {
584
- color: #aeb6c7;
577
+ :global(.maplibregl-ctrl-bottom-left) ul,
578
+ :global(.maplibregl-ctrl-bottom-right) ul {
579
+ top: auto;
580
+ bottom: 100%;
585
581
  }
586
582
 
587
583
  button {
@@ -589,6 +585,7 @@ button {
589
585
  margin: 0;
590
586
  border: 0;
591
587
  background-color: transparent;
588
+ height: auto;
592
589
  width: auto;
593
590
  }
594
591
  button:hover {
@@ -596,7 +593,7 @@ button:hover {
596
593
  }
597
594
 
598
595
  button:hover :global(svg),
599
- button.active :global(svg) {
596
+ button:active :global(svg) {
600
597
  fill: #2b8bfb;
601
598
  }
602
599
 
@@ -612,66 +609,42 @@ button.active :global(svg) {
612
609
  outline: #2b8bfb solid 2px;
613
610
  }
614
611
 
615
- .clear-button-container.displayable {
616
- display: flex;
617
- }
618
-
619
- div.error,
620
- div.no-results {
621
- font: inherit;
622
- font-size: 14px;
623
- padding: 6px 10px;
624
- }
625
-
626
- div.error {
627
- color: #e25041;
628
- }
629
-
630
- div.no-results {
631
- color: var(--color-text);
612
+ .search-button {
613
+ flex-shrink: 0;
632
614
  }
633
615
 
634
616
  .clear-button-container {
617
+ display: flex;
635
618
  display: none;
636
619
  position: relative;
637
620
  align-items: stretch;
638
621
  }
639
-
640
- @keyframes backAndForth {
641
- 0% {
642
- transform: translateX(0);
643
- }
644
- 10% {
645
- transform: translateX(0);
646
- }
647
- 45% {
648
- transform: translateX(calc(-100% + 206px));
649
- }
650
- 55% {
651
- transform: translateX(calc(-100% + 206px));
652
- }
653
- 90% {
654
- transform: translateX(0);
655
- }
656
- 100% {
657
- transform: translateX(0);
658
- }
622
+ .clear-button-container.displayable {
623
+ display: flex;
624
+ flex-shrink: 0;
659
625
  }
626
+
660
627
  :global(.maplibregl-ctrl-geocoder) {
661
628
  position: relative;
662
629
  z-index: 3;
663
630
  }
664
631
 
632
+ :global(.maptiler-ctrl):not(:empty) {
633
+ box-shadow: none;
634
+ }
635
+ :global(.maptiler-ctrl) .input-group {
636
+ padding-inline: 8px;
637
+ border: white solid 2px;
638
+ }
665
639
  :global(.maptiler-ctrl) .input-group:focus-within {
666
- outline: #2b8bfb solid 1.5px;
640
+ border: #2b8bfb solid 2px;
641
+ outline: 0;
642
+ outline: none;
667
643
  }
668
644
  :global(.maptiler-ctrl) form.can-collapse {
669
645
  max-width: 34px;
670
646
  }
671
- :global(.maptiler-ctrl) form.can-collapse .input-group {
672
- padding-inline: 7px;
673
- }
674
647
  :global(.maptiler-ctrl) form, :global(.maptiler-ctrl) form:focus-within, :global(.maptiler-ctrl) form:hover {
675
- width: 240px;
676
- max-width: 240px;
648
+ width: 270px;
649
+ max-width: 270px;
677
650
  }</style>
package/README.md CHANGED
@@ -104,8 +104,8 @@ For examples without using bundler see `demo-maplibregl.html` or `demo-leaflet.h
104
104
  - `debounceSearch`: `number` - Sets the amount of time, in milliseconds, to wait before querying the server when a user types into the Geocoder input box. This parameter may be useful for reducing the total number of API calls made for a single query. Default `200`.
105
105
  - `proximity`: `[number, number]` - A proximity argument: this is a geographical point given as an object with latitude and longitude properties. Search results closer to this point will be given higher priority.
106
106
  - `placeholder`: `string` - Override the default placeholder attribute value. Default `"Search"`.
107
- - `errorMessage`: `string` - Override the default error message. Default `"Searching failed"`.
108
- - `noResultsMessage`: `string` - Override the default message if no results are found. Default `"No results found"`.
107
+ - `errorMessage`: `string` - Override the default error message. Default `"Something went wrong…"`.
108
+ - `noResultsMessage`: `string` - Override the default message if no results are found. Default `"Oops! Looks like you're trying to predict something that's not quite right. We can't seem to find what you're looking for. Maybe try double-checking your spelling or try a different search term. Keep on typing - we'll do our best to get you where you need to go!"`.
109
109
  - `trackProximity`: `boolean` - If true, the geocoder proximity will automatically update based on the map view. Default `true`.
110
110
  - `minLength`: `number` - Minimum number of characters to enter before results are shown. Default `2`.
111
111
  - `bbox`: `[number, number, number, number]` - A bounding box argument: this is a bounding box given as an array in the format [minX, minY, maxX, maxY]. Search results will be limited to the bounding box.
package/SearchIcon.svelte CHANGED
@@ -1,6 +1,6 @@
1
- <svg viewBox="0 0 18 18" xml:space="preserve" width="20">
1
+ <svg width="14" height="14" viewBox="0 0 15 15">
2
2
  <path
3
- d="M7.4 2.5c-2.7 0-4.9 2.2-4.9 4.9s2.2 4.9 4.9 4.9c1 0 1.8-.2 2.5-.8l3.7 3.7c.2.2.4.3.8.3.7 0 1.1-.4 1.1-1.1 0-.3-.1-.5-.3-.8L11.4 10c.4-.8.8-1.6.8-2.5.1-2.8-2.1-5-4.8-5zm0 1.6c1.8 0 3.2 1.4 3.2 3.2s-1.4 3.2-3.2 3.2-3.3-1.3-3.3-3.1 1.4-3.3 3.3-3.3z"
3
+ d="M13.101 14.261 8.74 9.899a4.797 4.797 0 0 1-1.425.748 5.165 5.165 0 0 1-1.603.248c-1.446 0-2.677-.5-3.693-1.503S.495 7.164.495 5.717c0-1.446.508-2.678 1.524-3.693C3.035 1.008 4.266.5 5.712.5c1.448 0 2.672.508 3.675 1.524 1.002 1.015 1.503 2.247 1.503 3.693 0 .558-.08 1.092-.239 1.603-.159.512-.411.98-.757 1.405l4.382 4.4a.74.74 0 0 1 .229.568.81.81 0 0 1-.249.568.787.787 0 0 1-.577.239.787.787 0 0 1-.578-.239ZM5.712 9.223c.97 0 1.796-.342 2.48-1.026a3.378 3.378 0 0 0 1.026-2.48c0-.982-.34-1.818-1.016-2.509-.677-.69-1.507-1.035-2.49-1.035a3.42 3.42 0 0 0-2.509 1.035 3.42 3.42 0 0 0-1.035 2.51c0 .982.345 1.812 1.035 2.488.691.678 1.527 1.017 2.51 1.017Z"
4
4
  />
5
5
  </svg>
6
6