@maptiler/geocoding-control 0.0.83 → 0.0.85

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.
@@ -0,0 +1,14 @@
1
+ import type { Feature, FeatureCollection } from "./types";
2
+ export type DispatcherType = {
3
+ featuresListed: Feature[];
4
+ featuresMarked: Feature[];
5
+ optionsVisibilityChange: boolean;
6
+ pick: Feature;
7
+ queryChange: string;
8
+ response: {
9
+ url: string;
10
+ featureCollection: FeatureCollection;
11
+ };
12
+ reverseToggle: boolean;
13
+ select: Feature;
14
+ };
@@ -1,9 +1,8 @@
1
1
  <script>import { createEventDispatcher } from "svelte";
2
2
  import { onDestroy } from "svelte/internal";
3
- import ReverseGeocodingIcon from "./ReverseGeocodingIcon.svelte";
4
3
  import ClearIcon from "./ClearIcon.svelte";
5
4
  import LoadingIcon from "./LoadingIcon.svelte";
6
- import MarkerIcon from "./MarkerIcon.svelte";
5
+ import ReverseGeocodingIcon from "./ReverseGeocodingIcon.svelte";
7
6
  import SearchIcon from "./SearchIcon.svelte";
8
7
  let className = undefined;
9
8
  export { className as class };
@@ -259,7 +258,10 @@ async function search(searchValue, { byId = false, exact = false, } = {}) {
259
258
  });
260
259
  }
261
260
  catch (e) {
262
- if (e && typeof e === "object" && e.name === "AbortError") {
261
+ if (e &&
262
+ typeof e === "object" &&
263
+ "name" in e &&
264
+ e.name === "AbortError") {
263
265
  return;
264
266
  }
265
267
  throw new Error();
@@ -387,14 +389,13 @@ function unwrapBbox(bbox0) {
387
389
  aria-label={placeholder}
388
390
  />
389
391
 
390
- <div class="clear-button-container">
392
+ <div class="clear-button-container" class:displayable={searchValue !== ""}>
391
393
  <button
392
394
  type="button"
393
395
  on:click={() => {
394
396
  searchValue = "";
395
397
  input.focus();
396
398
  }}
397
- class:displayable={searchValue !== ""}
398
399
  title={clearButtonTitle}
399
400
  >
400
401
  <ClearIcon />
@@ -462,229 +463,214 @@ function unwrapBbox(bbox0) {
462
463
  {/if}
463
464
  </form>
464
465
 
465
- <style>
466
- form,
467
- form *,
468
- form *:after,
469
- form *:before {
470
- box-sizing: border-box;
471
- }
472
-
473
- form {
474
- font-family: "Open Sans", "Ubuntu", "Helvetica Neue", Arial, Helvetica,
475
- sans-serif;
476
- position: relative;
477
- background-color: #fff;
478
- width: 100%;
479
- z-index: 10;
480
- border-radius: 4px;
481
- transition: max-width 0.25s;
482
- box-shadow: 0px 5px 10px rgba(51, 51, 89, 0.15);
483
- --color-text: #444952;
484
- --color-icon-button: #444952;
485
- }
486
-
487
- form.can-collapse {
488
- max-width: 35px;
489
- }
490
-
491
- form,
492
- form:focus-within,
493
- form:hover {
494
- max-width: 240px;
495
- }
496
-
497
- input {
498
- font: inherit;
499
- font-size: 14px;
500
- width: 100%;
501
- border: 0;
502
- background-color: transparent;
503
- margin: 0;
504
- height: 36px;
505
- color: #444952;
506
- white-space: nowrap;
507
- overflow: hidden;
508
- padding: 0;
509
- }
510
-
511
- input:focus {
512
- color: #444952;
513
- outline: 0;
514
- outline: none;
515
- box-shadow: none;
516
- }
517
-
518
- ul,
519
- div.error,
520
- div.no-results {
521
- background-color: #fff;
522
- border-radius: 4px;
523
- left: 0;
524
- list-style: none;
525
- margin: 0;
526
- padding: 0;
527
- position: absolute;
528
- width: 100%;
529
- top: calc(100% + 6px);
530
- font-size: 14px;
531
- box-shadow: 0px 2px 8px rgba(51, 51, 89, 0.15);
532
- line-height: 16px;
533
- overflow: hidden;
534
- }
535
-
536
- :global(.maplibregl-ctrl-bottom-left) ul,
537
- :global(.maplibregl-ctrl-bottom-right) ul {
538
- top: auto;
539
- bottom: 100%;
540
- }
541
-
542
- li {
543
- text-align: left;
544
- cursor: default;
545
- display: grid;
546
- grid-template-columns: 1fr;
547
- color: var(--color-text);
548
- padding: 8px 0px;
549
- font-size: 14px;
550
- line-height: 18px;
551
- }
552
-
553
- li:first-child {
554
- padding-top: 10px;
555
- }
556
-
557
- li:last-child {
558
- padding-bottom: 10px;
559
- }
466
+ <style>form {
467
+ font-family: "Open Sans", "Ubuntu", "Helvetica Neue", Arial, Helvetica, sans-serif;
468
+ position: relative;
469
+ background-color: #fff;
470
+ z-index: 10;
471
+ border-radius: 4px;
472
+ transition: max-width 0.25s;
473
+ /* box-shadow: 0px 5px 10px rgba(51, 51, 89, 0.15); */
474
+ --color-text: #444952;
475
+ --color-icon-button: #444952;
476
+ }
477
+ form, form *, form *:after, form *:before {
478
+ box-sizing: border-box;
479
+ }
480
+ 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;
489
+ }
490
+ form, form:focus-within, form:hover {
491
+ width: 240px;
492
+ max-width: 240px;
493
+ }
560
494
 
561
- .texts {
562
- padding: 0 17px;
563
- }
495
+ input {
496
+ font: inherit;
497
+ font-size: 14px;
498
+ width: 100%;
499
+ border: 0;
500
+ background-color: transparent;
501
+ margin: 0;
502
+ color: #444952;
503
+ white-space: nowrap;
504
+ overflow: hidden;
505
+ padding: 0;
506
+ }
507
+ input:focus {
508
+ color: #444952;
509
+ outline: 0;
510
+ outline: none;
511
+ box-shadow: none;
512
+ }
564
513
 
565
- .texts > * {
566
- white-space: nowrap;
567
- display: block;
568
- min-width: fit-content;
569
- }
514
+ ul,
515
+ div.error,
516
+ div.no-results {
517
+ background-color: #fff;
518
+ border-radius: 4px;
519
+ left: 0;
520
+ list-style: none;
521
+ margin: 0;
522
+ padding: 0;
523
+ position: absolute;
524
+ width: 100%;
525
+ top: calc(100% + 6px);
526
+ font-size: 14px;
527
+ box-shadow: 0px 2px 8px rgba(51, 51, 89, 0.15);
528
+ line-height: 16px;
529
+ overflow: hidden;
530
+ }
570
531
 
571
- li.selected .texts > * {
572
- animation: backAndForth 5s linear infinite;
573
- }
532
+ :global(.maplibregl-ctrl-bottom-left) ul,
533
+ :global(.maplibregl-ctrl-bottom-right) ul {
534
+ top: auto;
535
+ bottom: 100%;
536
+ }
574
537
 
575
- .primary {
576
- font-weight: 600;
577
- }
538
+ li {
539
+ text-align: left;
540
+ cursor: default;
541
+ display: grid;
542
+ grid-template-columns: 1fr;
543
+ color: var(--color-text);
544
+ padding: 8px 0px;
545
+ font-size: 14px;
546
+ line-height: 18px;
547
+ }
548
+ li:first-child {
549
+ padding-top: 10px;
550
+ }
551
+ li:last-child {
552
+ padding-bottom: 10px;
553
+ }
554
+ li.selected {
555
+ background-color: #f3f6ff;
556
+ }
557
+ li.selected .texts > * {
558
+ animation: backAndForth 5s linear infinite;
559
+ }
560
+ li.selected .primary {
561
+ color: #2b8bfb;
562
+ }
578
563
 
579
- li.selected .primary {
580
- color: #2b8bfb;
581
- }
564
+ .texts {
565
+ padding: 0 17px;
566
+ }
567
+ .texts > * {
568
+ white-space: nowrap;
569
+ display: block;
570
+ min-width: fit-content;
571
+ }
582
572
 
583
- .secondary {
584
- color: #aeb6c7;
585
- padding-left: 4px;
586
- }
573
+ .primary {
574
+ font-weight: 600;
575
+ }
587
576
 
588
- .line2 {
589
- color: #aeb6c7;
590
- }
577
+ .secondary {
578
+ color: #aeb6c7;
579
+ padding-left: 4px;
580
+ }
591
581
 
592
- li.selected {
593
- background-color: #f3f6ff;
594
- }
582
+ .line2 {
583
+ color: #aeb6c7;
584
+ }
595
585
 
596
- button:hover {
597
- background-color: transparent;
598
- }
586
+ button {
587
+ padding: 0;
588
+ margin: 0;
589
+ border: 0;
590
+ background-color: transparent;
591
+ width: auto;
592
+ }
593
+ button:hover {
594
+ background-color: transparent;
595
+ }
599
596
 
600
- button:hover :global(svg),
601
- button.active :global(svg) {
602
- fill: #6b7c92;
603
- }
597
+ button:hover :global(svg),
598
+ button.active :global(svg) {
599
+ fill: #3588d4;
600
+ }
604
601
 
605
- button {
606
- padding: 0;
607
- margin: 0;
608
- border: 0;
609
- background-color: transparent;
610
- }
602
+ .input-group {
603
+ display: flex;
604
+ align-items: stretch;
605
+ gap: 7px;
606
+ padding-inline: 8px;
607
+ border-radius: 4px;
608
+ overflow: hidden;
609
+ }
610
+ .input-group:focus-within {
611
+ outline: #2b8bfb solid 2px;
612
+ }
611
613
 
612
- .input-group {
613
- display: flex;
614
- align-items: stretch;
615
- gap: 7px;
616
- padding-inline: 8px;
617
- outline: #c1cfe4 solid 1.5px;
618
- border-radius: 4px;
619
- overflow: hidden;
620
- }
614
+ .clear-button-container.displayable {
615
+ display: flex;
616
+ }
621
617
 
622
- .input-group:hover .displayable {
623
- visibility: visible;
624
- }
618
+ div.error,
619
+ div.no-results {
620
+ font: inherit;
621
+ font-size: 14px;
622
+ padding: 6px 10px;
623
+ }
625
624
 
626
- .input-group:focus-within {
627
- outline: #2b8bfb solid 1.5px;
628
- }
625
+ div.error {
626
+ color: #e25041;
627
+ }
629
628
 
630
- div.error,
631
- div.no-results {
632
- font: inherit;
633
- font-size: 14px;
634
- padding: 6px 10px;
635
- }
629
+ div.no-results {
630
+ color: var(--color-text);
631
+ }
636
632
 
637
- div.error {
638
- color: #e25041;
639
- }
633
+ .clear-button-container {
634
+ display: none;
635
+ position: relative;
636
+ align-items: stretch;
637
+ }
640
638
 
641
- div.no-results {
642
- color: var(--color-text);
639
+ @keyframes backAndForth {
640
+ 0% {
641
+ transform: translateX(0);
643
642
  }
644
-
645
- .clear-button-container {
646
- position: relative;
647
- display: flex;
648
- align-items: stretch;
643
+ 10% {
644
+ transform: translateX(0);
649
645
  }
650
-
651
- .clear-button-container button {
652
- visibility: hidden;
646
+ 45% {
647
+ transform: translateX(calc(-100% + 206px));
653
648
  }
654
-
655
- @keyframes backAndForth {
656
- 0% {
657
- transform: translateX(0);
658
- }
659
- 10% {
660
- transform: translateX(0);
661
- }
662
- 45% {
663
- transform: translateX(calc(-100% + 206px));
664
- }
665
- 55% {
666
- transform: translateX(calc(-100% + 206px));
667
- }
668
- 90% {
669
- transform: translateX(0);
670
- }
671
- 100% {
672
- transform: translateX(0);
673
- }
649
+ 55% {
650
+ transform: translateX(calc(-100% + 206px));
674
651
  }
675
-
676
- form.can-collapse button:not(:nth-of-type(1)) {
677
- opacity: 0;
678
- transition: opacity 0.25s;
652
+ 90% {
653
+ transform: translateX(0);
679
654
  }
680
-
681
- form.can-collapse:focus-within :not(:nth-of-type(1)),
682
- form.can-collapse:hover :not(:nth-of-type(1)) {
683
- opacity: 1;
655
+ 100% {
656
+ transform: translateX(0);
684
657
  }
658
+ }
659
+ :global(.maplibregl-ctrl-geocoder) {
660
+ position: relative;
661
+ z-index: 3;
662
+ }
685
663
 
686
- :global(.maplibregl-ctrl-geocoder) {
687
- position: relative;
688
- z-index: 3;
689
- }
690
- </style>
664
+ :global(.maptiler-ctrl) .input-group:focus-within {
665
+ outline: #2b8bfb solid 1.5px;
666
+ }
667
+ :global(.maptiler-ctrl) form.can-collapse {
668
+ max-width: 34px;
669
+ }
670
+ :global(.maptiler-ctrl) form.can-collapse .input-group {
671
+ padding-inline: 7px;
672
+ }
673
+ :global(.maptiler-ctrl) form, :global(.maptiler-ctrl) form:focus-within, :global(.maptiler-ctrl) form:hover {
674
+ width: 240px;
675
+ max-width: 240px;
676
+ }</style>
@@ -1,5 +1,5 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import type { Feature, FeatureCollection, MapController, Proximity } from "./types";
2
+ import type { Feature, MapController, Proximity } from "./types";
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  class?: string | undefined;
@@ -37,17 +37,14 @@ declare const __propDef: {
37
37
  setQuery?: ((value: string, submit?: boolean) => void) | undefined;
38
38
  };
39
39
  events: {
40
- select: CustomEvent<Feature>;
41
- pick: CustomEvent<Feature>;
42
- optionsVisibilityChange: CustomEvent<boolean>;
43
- featuresListed: CustomEvent<Feature[]>;
44
- featuresMarked: CustomEvent<Feature[]>;
45
- response: CustomEvent<{
46
- url: string;
47
- featureCollection: FeatureCollection;
48
- }>;
49
- reverseToggle: CustomEvent<boolean>;
50
- queryChange: CustomEvent<string>;
40
+ select: CustomEvent<any>;
41
+ pick: CustomEvent<any>;
42
+ optionsVisibilityChange: CustomEvent<any>;
43
+ featuresListed: CustomEvent<any>;
44
+ featuresMarked: CustomEvent<any>;
45
+ reverseToggle: CustomEvent<any>;
46
+ queryChange: CustomEvent<any>;
47
+ response: CustomEvent<any>;
51
48
  } & {
52
49
  [evt: string]: CustomEvent<any>;
53
50
  };
package/README.md CHANGED
@@ -8,6 +8,29 @@ Geocoding control is also provided as [React component](#react-component) and a
8
8
 
9
9
  ## Usage
10
10
 
11
+ ### Example for MapTiler SDK using module bundler
12
+
13
+ ```
14
+ npm install --save @maptiler/geocoding-control @maptiler/sdk
15
+ ```
16
+
17
+ ```js
18
+ import * as maptilersdk from "@maptiler/sdk";
19
+ import { GeocodingControl } from "@maptiler/geocoding-control/maplibregl";
20
+ import "@maptiler/sdk/dist/maptiler-sdk.css";
21
+ import "@maptiler/geocoding-control/style.css";
22
+
23
+ maptilersdk.config.apiKey = "YOUR_MAPTILER_API_KEY_HERE";
24
+
25
+ const map = new maptilersdk.Map({
26
+ container: "map", // id of HTML container element
27
+ });
28
+
29
+ const gc = new GeocodingControl();
30
+
31
+ map.addControl(gc);
32
+ ```
33
+
11
34
  ### Example for MapLibre GL JS using module bundler
12
35
 
13
36
  ```bash
@@ -34,7 +57,7 @@ const gc = new GeocodingControl({ apiKey, maplibregl });
34
57
  map.addControl(gc);
35
58
  ```
36
59
 
37
- ### Example for Leaflet using module bundler
60
+ ### Example for Leaflet using module bundler
38
61
 
39
62
  ```bash
40
63
  npm install --save @maptiler/geocoding-control leaflet
@@ -112,6 +135,7 @@ For examples without using bundler see `demo-maplibregl.html` or `demo-leaflet.h
112
135
  - `focus(): void` - focus the query input box
113
136
  - `blur(): void` - blur the query input box
114
137
  - `setReverseMode(value: boolean | "always"): void` - set reverse mode
138
+ - `setOptions(options: Partial<Options>): void` - change one or more options of existing control
115
139
 
116
140
  ### Events
117
141
 
@@ -123,8 +147,8 @@ Events are implemented using [EventTarget](https://developer.mozilla.org/en-US/d
123
147
  - `featuresListed` - Fired after features are retrieved from the server. Event value contains list of features or `undefined`.
124
148
  - `featuresMarked` - Fired after features are marked on the map. Event value contains list of features or `undefined`.
125
149
  - `response` - Fired after HTTP response of the geocoding server. Event value contains object with requested `url` and responded `featureCollection`.
126
- - `reversetoggle` - Fired if reverse geocoding button is toggled. Event value is `true` if reverse geocoding mode is active, otherwise `false`.
127
- - `querychange` - Fired if query was changed. Event value is the query string.
150
+ - `reverseToggle` - Fired if reverse geocoding button is toggled. Event value is `true` if reverse geocoding mode is active, otherwise `false`.
151
+ - `queryChange` - Fired if query was changed. Event value is the query string.
128
152
 
129
153
  Example:
130
154
 
@@ -175,7 +199,10 @@ export function App() {
175
199
  <div>
176
200
  <GeocodingControl apiKey={apiKey} mapController={mapController} />
177
201
 
178
- <div ref={mapContainerRef} style={{ width: "800px", height: "600px", marginTop: "8px" }} />
202
+ <div
203
+ ref={mapContainerRef}
204
+ style={{ width: "800px", height: "600px", marginTop: "8px" }}
205
+ />
179
206
  </div>
180
207
  );
181
208
  }
@@ -210,7 +237,7 @@ Component API matches API described above where options and events are exposed a
210
237
  });
211
238
 
212
239
  mapController = createMaplibreglMapController(map, maplibregl);
213
- }
240
+ });
214
241
  </script>
215
242
 
216
243
  <div class="map" bind:this={container} />