@maptiler/geocoding-control 0.0.78 → 0.0.81

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.
Files changed (48) hide show
  1. package/ClearIcon.svelte.d.ts +23 -0
  2. package/GeocodingControl.svelte +685 -0
  3. package/GeocodingControl.svelte.d.ts +66 -0
  4. package/LoadingIcon.svelte.d.ts +23 -0
  5. package/{src/lib/MarkerIcon.svelte → MarkerIcon.svelte} +1 -2
  6. package/MarkerIcon.svelte.d.ts +16 -0
  7. package/ReverseGeocodingIcon.svelte.d.ts +23 -0
  8. package/SearchIcon.svelte.d.ts +23 -0
  9. package/leaflet-controller.js +1 -0
  10. package/leaflet-controller.js.map +1 -0
  11. package/leaflet-controller.umd.js +1 -0
  12. package/leaflet-controller.umd.js.map +1 -0
  13. package/leaflet.js +3998 -4021
  14. package/leaflet.js.map +1 -0
  15. package/leaflet.umd.js +6 -5
  16. package/leaflet.umd.js.map +1 -0
  17. package/maplibregl-controller.js +1 -0
  18. package/maplibregl-controller.js.map +1 -0
  19. package/maplibregl-controller.umd.js +1 -0
  20. package/maplibregl-controller.umd.js.map +1 -0
  21. package/maplibregl.js +4089 -4112
  22. package/maplibregl.js.map +1 -0
  23. package/maplibregl.umd.js +6 -5
  24. package/maplibregl.umd.js.map +1 -0
  25. package/package.json +23 -23
  26. package/react.js +571 -649
  27. package/react.js.map +1 -0
  28. package/react.umd.js +2 -1
  29. package/react.umd.js.map +1 -0
  30. package/style.css +1 -1
  31. package/src/AppLeaflet.svelte +0 -55
  32. package/src/AppMaplibregl.svelte +0 -45
  33. package/src/lib/GeocodingControl.svelte +0 -839
  34. package/src/lib/LeafletGeocodingControl.ts +0 -154
  35. package/src/lib/MaplibreglGeocodingControl.ts +0 -160
  36. package/src/lib/ReactGeocodingControl.ts +0 -158
  37. package/src/lib/leafletMapController.ts +0 -305
  38. package/src/lib/maplibreglMapController.ts +0 -366
  39. package/src/lib/mask.ts +0 -70
  40. package/src/lib/types.ts +0 -235
  41. package/src/main-copy.ts +0 -59
  42. package/src/main.ts +0 -65
  43. package/src/vite-env.d.ts +0 -2
  44. /package/{src/lib/ClearIcon.svelte → ClearIcon.svelte} +0 -0
  45. /package/{src/lib/LoadingIcon.svelte → LoadingIcon.svelte} +0 -0
  46. /package/{src/lib/ReverseGeocodingIcon.svelte → ReverseGeocodingIcon.svelte} +0 -0
  47. /package/{src/lib/SearchIcon.svelte → SearchIcon.svelte} +0 -0
  48. /package/{maplibre.d.ts → maplibregl.d.ts} +0 -0
@@ -1,154 +0,0 @@
1
- import * as L from "leaflet";
2
- import GeocodingControlComponent from "./GeocodingControl.svelte";
3
- import { createLeafletMapController } from "./leafletMapController";
4
- export { createLeafletMapController } from "./leafletMapController";
5
- import type { ControlOptions } from "./types";
6
-
7
- type LeafletControlOptions = ControlOptions &
8
- L.ControlOptions & {
9
- /**
10
- * If `true`, a [Marker](https://leafletjs.com/reference.html#marker) will be added to the map at the location of the user-selected result using a default set of Marker options.
11
- * If the value is an object, the marker will be constructed using these options.
12
- * If `false`, no marker will be added to the map.
13
- *
14
- * @default true
15
- */
16
- marker?: boolean | L.MarkerOptions;
17
-
18
- /**
19
- * If `true`, [Markers](https://leafletjs.com/reference.html#marker) will be added to the map at the location the top results for the query.
20
- * If the value is an object, the marker will be constructed using these options.
21
- * If `false`, no marker will be added to the map.
22
- *
23
- * @default true
24
- */
25
- showResultMarkers?: boolean | L.MarkerOptions;
26
-
27
- /**
28
- * If `false`, animating the map to a selected result is disabled.
29
- * If `true`, animating the map will use the default animation parameters.
30
- * If an object, it will be passed as options to the map `flyTo` or `fitBounds` method providing control over the animation of the transition.
31
- *
32
- * @default true
33
- */
34
- flyTo?: boolean | (L.ZoomPanOptions & L.FitBoundsOptions);
35
-
36
- /**
37
- * Style for full feature geometry GeoJSON.
38
- */
39
- fullGeometryStyle?: L.PathOptions | L.StyleFunction;
40
- };
41
-
42
- export class GeocodingControl extends L.Control {
43
- #gc?: GeocodingControlComponent;
44
-
45
- #options: LeafletControlOptions;
46
-
47
- constructor(options: LeafletControlOptions) {
48
- super();
49
-
50
- this.#options = options;
51
- }
52
-
53
- onAdd(map: L.Map) {
54
- const div = document.createElement("div");
55
-
56
- div.className = "leaflet-ctrl-geocoder";
57
-
58
- L.DomEvent.disableClickPropagation(div);
59
- L.DomEvent.disableScrollPropagation(div);
60
-
61
- const {
62
- marker,
63
- showResultMarkers,
64
- flyTo,
65
- fullGeometryStyle,
66
- ...restOptions
67
- } = this.#options;
68
-
69
- const flyToOptions = typeof flyTo === "boolean" ? {} : flyTo;
70
-
71
- const mapController = createLeafletMapController(
72
- map,
73
- marker,
74
- showResultMarkers,
75
- flyToOptions,
76
- flyToOptions,
77
- fullGeometryStyle
78
- );
79
-
80
- this.#gc = new GeocodingControlComponent({
81
- target: div,
82
- props: {
83
- mapController,
84
- flyTo: flyTo === undefined ? true : !!flyTo,
85
- ...restOptions,
86
- },
87
- });
88
-
89
- for (const eventName of [
90
- "select",
91
- "pick",
92
- "featuresListed",
93
- "featuresMarked",
94
- "response",
95
- "optionsVisibilityChange",
96
- "reverseToggle",
97
- "queryChange",
98
- ]) {
99
- this.#gc.$on(eventName, (event) =>
100
- map.fire(eventName.toLowerCase(), event.detail)
101
- );
102
- }
103
-
104
- return div;
105
- }
106
-
107
- setOptions(options: LeafletControlOptions) {
108
- this.#options = options;
109
-
110
- const {
111
- marker,
112
- showResultMarkers,
113
- flyTo,
114
- fullGeometryStyle,
115
- ...restOptions
116
- } = this.#options;
117
-
118
- this.#gc?.$set(restOptions);
119
- }
120
-
121
- setQuery(value: string, submit: boolean | "always" = true) {
122
- (this.#gc as any)?.setQuery(value, submit);
123
- }
124
-
125
- setReverseMode(value: boolean) {
126
- this.#gc?.$set({ reverseActive: value });
127
- }
128
-
129
- focus() {
130
- (this.#gc as any)?.focus();
131
- }
132
-
133
- blur() {
134
- (this.#gc as any)?.blur();
135
- }
136
-
137
- onRemove() {
138
- (this.#gc as any)?.$destroy();
139
- }
140
- }
141
-
142
- function createControl(
143
- ...params: ConstructorParameters<typeof GeocodingControl>
144
- ) {
145
- return new GeocodingControl(...params);
146
- }
147
-
148
- if (
149
- window.L &&
150
- typeof window.L === "object" &&
151
- typeof window.L.control === "function"
152
- ) {
153
- (window.L.control as any).maptilerGeocoding = createControl;
154
- }
@@ -1,160 +0,0 @@
1
- import type {
2
- Map,
3
- IControl,
4
- MarkerOptions,
5
- FlyToOptions,
6
- FitBoundsOptions,
7
- FillLayerSpecification,
8
- LineLayerSpecification,
9
- } from "maplibre-gl";
10
- import type maplibregl from "maplibre-gl";
11
- import GeocodingControlComponent from "./GeocodingControl.svelte";
12
- import type { ControlOptions } from "./types";
13
- import { createMaplibreglMapController } from "./maplibreglMapController";
14
- export { createMaplibreglMapController } from "./maplibreglMapController";
15
-
16
- type MapLibreGL = typeof maplibregl;
17
-
18
- type MapLibreControlOptions = ControlOptions & {
19
- /**
20
- * A Maplibre GL instance to use when creating [Markers](https://maplibre.org/maplibre-gl-js-docs/api/markers/#marker).
21
- * Required if `options.marker` is `true`.
22
- */
23
- maplibregl?: MapLibreGL;
24
-
25
- /**
26
- * If `true`, a [Marker](https://maplibre.org/maplibre-gl-js-docs/api/markers/#marker) will be added to the map at the location of the user-selected result using a default set of Marker options.
27
- * If the value is an object, the marker will be constructed using these options.
28
- * If `false`, no marker will be added to the map.
29
- * Requires that `options.maplibregl` also be set.
30
- *
31
- * @default true
32
- */
33
- marker?: boolean | MarkerOptions;
34
-
35
- /**
36
- * If `true`, [Markers](https://maplibre.org/maplibre-gl-js-docs/api/markers/#marker) will be added to the map at the location the top results for the query.
37
- * If the value is an object, the marker will be constructed using these options.
38
- * If `false`, no marker will be added to the map.
39
- * Requires that `options.maplibregl` also be set.
40
- *
41
- * @default true
42
- */
43
- showResultMarkers?: boolean | MarkerOptions;
44
-
45
- /**
46
- * If `false`, animating the map to a selected result is disabled.
47
- * If `true`, animating the map will use the default animation parameters.
48
- * If an object, it will be passed as options to the map `flyTo` or `fitBounds` method providing control over the animation of the transition.
49
- *
50
- * @default true
51
- */
52
- flyTo?: boolean | (FlyToOptions & FitBoundsOptions);
53
-
54
- /**
55
- * Style for full feature geometry GeoJSON.
56
- */
57
- fullGeometryStyle?: {
58
- fill: Pick<FillLayerSpecification, "layout" | "paint" | "filter">;
59
- line: Pick<LineLayerSpecification, "layout" | "paint" | "filter">;
60
- };
61
- };
62
-
63
- export class GeocodingControl extends EventTarget implements IControl {
64
- #gc?: GeocodingControlComponent;
65
-
66
- #options: MapLibreControlOptions;
67
-
68
- constructor(options: MapLibreControlOptions) {
69
- super();
70
-
71
- this.#options = options;
72
- }
73
-
74
- onAdd(map: Map) {
75
- const div = document.createElement("div");
76
-
77
- div.className =
78
- "mapboxgl-ctrl-geocoder mapboxgl-ctrl maplibregl-ctrl-geocoder maplibregl-ctrl";
79
-
80
- const {
81
- maplibregl,
82
- marker,
83
- showResultMarkers,
84
- flyTo,
85
- fullGeometryStyle,
86
- ...restOptions
87
- } = this.#options;
88
-
89
- const flyToOptions = typeof flyTo === "boolean" ? {} : flyTo;
90
-
91
- const mapController = createMaplibreglMapController(
92
- map,
93
- maplibregl,
94
- marker,
95
- showResultMarkers,
96
- flyToOptions,
97
- flyToOptions,
98
- fullGeometryStyle
99
- );
100
-
101
- this.#gc = new GeocodingControlComponent({
102
- target: div,
103
- props: {
104
- mapController,
105
- flyTo: flyTo === undefined ? true : !!flyTo,
106
- ...restOptions,
107
- },
108
- });
109
-
110
- for (const eventName of [
111
- "select",
112
- "pick",
113
- "featuresListed",
114
- "featuresMarked",
115
- "response",
116
- "optionsVisibilityChange",
117
- "reverseToggle",
118
- "queryChange",
119
- ]) {
120
- this.#gc.$on(eventName, (event) => this.dispatchEvent(event));
121
- }
122
-
123
- return div;
124
- }
125
-
126
- setOptions(options: MapLibreControlOptions) {
127
- this.#options = options;
128
-
129
- const {
130
- maplibregl,
131
- marker,
132
- showResultMarkers,
133
- flyTo,
134
- fullGeometryStyle,
135
- ...restOptions
136
- } = this.#options;
137
-
138
- this.#gc?.$set(restOptions);
139
- }
140
-
141
- setQuery(value: string, submit: boolean | "always" = true) {
142
- (this.#gc as any)?.setQuery(value, submit);
143
- }
144
-
145
- setReverseMode(value: boolean) {
146
- this.#gc?.$set({ reverseActive: value });
147
- }
148
-
149
- focus() {
150
- (this.#gc as any)?.focus();
151
- }
152
-
153
- blur() {
154
- (this.#gc as any)?.blur();
155
- }
156
-
157
- onRemove() {
158
- (this.#gc as any)?.$destroy();
159
- }
160
- }
@@ -1,158 +0,0 @@
1
- import GeocodingControl from "./GeocodingControl.svelte";
2
- import {
3
- createElement,
4
- forwardRef,
5
- useEffect,
6
- useImperativeHandle,
7
- useRef,
8
- type Ref,
9
- } from "react";
10
- import type { ControlOptions, Feature, MapController } from "./types";
11
-
12
- // TODO this would be nice to be derived from `Parameters<GeocodingControl["$on"]>[0]` but it just doesn't work
13
- type CallbackProperties = {
14
- onSelect?: (feature: Feature | undefined) => void;
15
- onPick?: (feature: Feature | undefined) => void;
16
- onOptionsVisibilityChange?: (visible: boolean) => void;
17
- onFeaturesListed?: (visible: Feature[] | undefined) => void;
18
- onFeaturesMarked?: (visible: Feature[] | undefined) => void;
19
- onResponse?: (onResponse: { url: string; response: Response }) => void;
20
- onReversetoggle?: (reverse: boolean) => void;
21
- onQuerychange?: (query: string) => void;
22
- };
23
-
24
- type EventName<T extends keyof CallbackProperties> = T extends `on${infer U}`
25
- ? Uncapitalize<U>
26
- : never;
27
-
28
- type EventNames = EventName<keyof CallbackProperties>;
29
-
30
- const eventNames = [
31
- "featuresListed",
32
- "featuresMarked",
33
- "optionsVisibilityChange",
34
- "pick",
35
- "querychange",
36
- "response",
37
- "reversetoggle",
38
- "select",
39
- ] as const satisfies readonly EventNames[];
40
-
41
- type MapControllerProp = {
42
- mapController?: MapController;
43
- };
44
-
45
- const propertyNames = [
46
- "apiKey",
47
- "bbox",
48
- "clearButtonTitle",
49
- "clearOnBlur",
50
- "collapsed",
51
- "country",
52
- "debounceSearch",
53
- "enableReverse",
54
- "errorMessage",
55
- "filter",
56
- "fuzzyMatch",
57
- "language",
58
- "limit",
59
- "minLength",
60
- "noResultsMessage",
61
- "placeholder",
62
- "proximity",
63
- "reverseButtonTitle",
64
- "showFullGeometry",
65
- "showPlaceType",
66
- "showResultsWhileTyping",
67
- "trackProximity",
68
- "types",
69
- "zoom",
70
- "mapController",
71
- ] as const satisfies readonly (keyof (ControlOptions & MapControllerProp))[];
72
-
73
- type EventHandlerFnName<T extends EventNames> = `on${Capitalize<T>}`;
74
-
75
- function getEventFnName<T extends EventNames>(name: T): EventHandlerFnName<T> {
76
- return ("on" +
77
- name[0].toUpperCase() +
78
- name.slice(1)) as EventHandlerFnName<T>;
79
- }
80
-
81
- export type Props = ControlOptions & CallbackProperties & MapControllerProp;
82
-
83
- // // not used because it does not integrate well with Svelte
84
- // type MethodNames = "blur" | "focus" | "setQuery";
85
- //
86
- // export type Methods = { [T in MethodNames]: GeocodingControl[T] };
87
-
88
- export type Methods = {
89
- blur: () => void;
90
- focus: () => void;
91
- setQuery: (value: string, submit?: boolean) => void;
92
- };
93
-
94
- const ReactGeocodingControl = forwardRef(function ReactGeocodingControl(
95
- props: Props,
96
- ref: Ref<Methods>
97
- ) {
98
- const divRef = useRef<HTMLDivElement>();
99
-
100
- const controlRef = useRef<GeocodingControl>();
101
-
102
- const options = { ...props };
103
-
104
- for (const eventName of eventNames) {
105
- delete options[getEventFnName(eventName)];
106
- }
107
-
108
- useEffect(() => {
109
- if (!divRef.current) {
110
- throw new Error();
111
- }
112
-
113
- const control = new GeocodingControl({
114
- target: divRef.current,
115
- props: options,
116
- });
117
-
118
- controlRef.current = control;
119
-
120
- return () => control.$destroy();
121
- }, []);
122
-
123
- // watch change on every option
124
- for (const propName of propertyNames) {
125
- useEffect(() => {
126
- if (controlRef.current && props[propName] !== undefined) {
127
- controlRef.current.$set({ [propName]: props[propName] });
128
- }
129
- }, [props[propName]]);
130
- }
131
-
132
- // attach event handlers
133
- for (const eventName of eventNames) {
134
- const eventHandlerFn = props[getEventFnName(eventName)];
135
-
136
- useEffect(() => {
137
- controlRef.current?.$on(
138
- eventName,
139
- !eventHandlerFn
140
- ? undefined
141
- : (e) => {
142
- (eventHandlerFn as any)(e.detail);
143
- }
144
- );
145
- }, [eventHandlerFn]);
146
- }
147
-
148
- useImperativeHandle(ref, () => ({
149
- setQuery: (value: string, submit = true) =>
150
- controlRef.current?.setQuery(value, submit),
151
- focus: () => controlRef.current?.focus(),
152
- blur: () => controlRef.current?.blur(),
153
- }));
154
-
155
- return createElement("div", { ref: divRef });
156
- });
157
-
158
- export { ReactGeocodingControl as GeocodingControl };