@maptiler/geocoding-control 1.4.2-dev.2 → 2.0.0
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/MapLibreBasedGeocodingControl.d.ts +70 -35
- package/leaflet-controller.d.ts +1 -1
- package/leaflet-controller.js +407 -398
- package/leaflet-controller.js.map +1 -1
- package/leaflet-controller.umd.js +3 -3
- package/leaflet-controller.umd.js.map +1 -1
- package/leaflet.d.ts +52 -16
- package/leaflet.js +888 -870
- package/leaflet.js.map +1 -1
- package/leaflet.umd.js +3 -3
- package/leaflet.umd.js.map +1 -1
- package/maplibregl-controller.d.ts +7 -7
- package/maplibregl-controller.js +421 -413
- package/maplibregl-controller.js.map +1 -1
- package/maplibregl-controller.umd.js +3 -3
- package/maplibregl-controller.umd.js.map +1 -1
- package/maplibregl.d.ts +29 -5
- package/maplibregl.js +1244 -1236
- package/maplibregl.js.map +1 -1
- package/maplibregl.umd.js +3 -3
- package/maplibregl.umd.js.map +1 -1
- package/maptilersdk.d.ts +29 -5
- package/maptilersdk.js +1194 -1180
- package/maptilersdk.js.map +1 -1
- package/maptilersdk.umd.js +3 -3
- package/maptilersdk.umd.js.map +1 -1
- package/openlayers.js +694 -692
- package/openlayers.js.map +1 -1
- package/openlayers.umd.js +3 -3
- package/openlayers.umd.js.map +1 -1
- package/package.json +5 -5
- package/react.js +671 -669
- package/react.js.map +1 -1
- package/react.umd.js +1 -1
- package/react.umd.js.map +1 -1
- package/svelte/GeocodingControl.svelte +4 -2
- package/svelte/GeocodingControl.svelte.d.ts +1 -0
- package/svelte/MapLibreBasedGeocodingControl.d.ts +70 -35
- package/svelte/MapLibreBasedGeocodingControl.js +69 -66
- package/svelte/leaflet-controller.d.ts +1 -1
- package/svelte/leaflet-controller.js +47 -24
- package/svelte/leaflet.d.ts +52 -16
- package/svelte/leaflet.js +14 -2
- package/svelte/maplibregl-controller.d.ts +7 -7
- package/svelte/maplibregl-controller.js +55 -34
- package/svelte/maplibregl.d.ts +29 -5
- package/svelte/maplibregl.js +3 -8
- package/svelte/maptilersdk.d.ts +29 -5
- package/svelte/maptilersdk.js +15 -18
- package/svelte/types.d.ts +6 -0
- package/types.d.ts +6 -0
- package/vanilla.js +392 -390
- package/vanilla.js.map +1 -1
- package/vanilla.umd.js +1 -1
- package/vanilla.umd.js.map +1 -1
|
@@ -67,13 +67,14 @@ export let selectFirst = true;
|
|
|
67
67
|
export let flyToSelected = false;
|
|
68
68
|
export let markerOnSelected = true;
|
|
69
69
|
export let types = undefined;
|
|
70
|
+
export let exhaustiveReverseGeocoding = false;
|
|
70
71
|
export let excludeTypes = false;
|
|
71
72
|
export let zoom = ZOOM_DEFAULTS;
|
|
72
73
|
export let maxZoom = undefined;
|
|
73
74
|
export let apiUrl = "https://api.maptiler.com/geocoding";
|
|
74
75
|
export let fetchParameters = {};
|
|
75
76
|
export let iconsBaseUrl = "https://cdn.maptiler.com/maptiler-geocoding-control/v" +
|
|
76
|
-
"
|
|
77
|
+
"2.0.0" +
|
|
77
78
|
"/icons/";
|
|
78
79
|
export let adjustUrlQuery = () => { };
|
|
79
80
|
export function focus() {
|
|
@@ -312,7 +313,8 @@ async function search(searchValue, { byId = false, exact = false, } = {}) {
|
|
|
312
313
|
}
|
|
313
314
|
sp.set("fuzzyMatch", String(fuzzyMatch));
|
|
314
315
|
}
|
|
315
|
-
if (limit !== undefined
|
|
316
|
+
if (limit !== undefined &&
|
|
317
|
+
(exhaustiveReverseGeocoding || !isReverse || types?.length === 1)) {
|
|
316
318
|
sp.set("limit", String(limit));
|
|
317
319
|
}
|
|
318
320
|
sp.set("key", apiKey);
|
|
@@ -33,6 +33,7 @@ declare const __propDef: {
|
|
|
33
33
|
flyToSelected?: boolean;
|
|
34
34
|
markerOnSelected?: boolean;
|
|
35
35
|
types?: string[] | undefined;
|
|
36
|
+
exhaustiveReverseGeocoding?: boolean;
|
|
36
37
|
excludeTypes?: boolean;
|
|
37
38
|
zoom?: number | Record<string, number>;
|
|
38
39
|
maxZoom?: number | undefined;
|
|
@@ -1,54 +1,89 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { FillLayerSpecification, FitBoundsOptions, FlyToOptions, LineLayerSpecification, Map, MarkerOptions } from "maplibre-gl";
|
|
1
|
+
import type { Evented, FitBoundsOptions, FlyToOptions, Map, Marker, MarkerOptions } from "maplibre-gl";
|
|
3
2
|
import type { SvelteComponent } from "svelte";
|
|
4
3
|
import GeocodingControlComponent from "./GeocodingControl.svelte";
|
|
5
|
-
import type
|
|
6
|
-
|
|
4
|
+
import { type FullGeometryStyle, type MapLibreGL } from "./maplibregl-controller";
|
|
5
|
+
import type { ControlOptions, Feature } from "./types";
|
|
6
|
+
export { createMapLibreGlMapController, type MapLibreGL, } from "./maplibregl-controller";
|
|
7
7
|
export type MapLibreBaseControlOptions = Omit<ControlOptions, "apiKey"> & {
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* If `
|
|
9
|
+
* Marker to be added to the map at the location of the user-selected result using a default set of Marker options.
|
|
10
|
+
*
|
|
11
|
+
* - If `true` or `undefined` then a default marker will be used.
|
|
12
|
+
* - If the value is a [MarkerOptions](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MarkerOptions/) then the marker will be constructed using these options.
|
|
13
|
+
* - If the value is a function then it can return instance of the [Marker](https://maplibre.org/maplibre-gl-js/docs/API/classes/Marker/).
|
|
14
|
+
* Function can accept `Feature` as a parameter which is `undefined` for the reverse location marker.
|
|
15
|
+
* - If `false` or `null` then no marker will be added to the map.
|
|
16
|
+
*
|
|
12
17
|
* Requires that `options.maplibregl` also be set.
|
|
18
|
+
*
|
|
13
19
|
* Default value is `true`.
|
|
14
20
|
*/
|
|
15
|
-
marker?: boolean | MarkerOptions;
|
|
21
|
+
marker?: null | boolean | MarkerOptions | ((map: Map, feature?: Feature) => undefined | null | Marker);
|
|
16
22
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* If `
|
|
23
|
+
* Marker be added to the map at the location the geocoding results.
|
|
24
|
+
*
|
|
25
|
+
* - If `true` or `undefined` then a default marker will be used.
|
|
26
|
+
* - If the value is a [MarkerOptions](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MarkerOptions/) then the marker will be constructed using these options.
|
|
27
|
+
* - If the value is a function then it can return instance of the [Marker](https://maplibre.org/maplibre-gl-js/docs/API/classes/Marker/).
|
|
28
|
+
* In this case the default pop-up won't be added to the marker.
|
|
29
|
+
* Function can accept `Feature` as a parameter.
|
|
30
|
+
* - If `false` or `null` then no marker will be added to the map.
|
|
31
|
+
*
|
|
20
32
|
* Requires that `options.maplibregl` also be set.
|
|
33
|
+
*
|
|
21
34
|
* Default value is `true`.
|
|
22
35
|
*/
|
|
23
|
-
showResultMarkers?: boolean | MarkerOptions;
|
|
36
|
+
showResultMarkers?: null | boolean | MarkerOptions | ((map: Map, feature: Feature) => undefined | null | Marker);
|
|
24
37
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* If
|
|
38
|
+
* Animation to selected feature on the map.
|
|
39
|
+
*
|
|
40
|
+
* - If `false` or `null` then animating the map to a selected result is disabled.
|
|
41
|
+
* - If `true` or `undefined` then animating the map will use the default animation parameters.
|
|
42
|
+
* - If an [FlyToOptions](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/FlyToOptions/)
|
|
43
|
+
* ` & `[FitBoundsOptions](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/FitBoundsOptions/)
|
|
44
|
+
* then it will be passed as options to the map [flyTo](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/#flyto)
|
|
45
|
+
* or [fitBounds](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/#fitbounds) method providing control over the animation of the transition.
|
|
46
|
+
*
|
|
28
47
|
* Default value is `true`.
|
|
29
48
|
*/
|
|
30
|
-
flyTo?: boolean | (FlyToOptions & FitBoundsOptions);
|
|
49
|
+
flyTo?: null | boolean | (FlyToOptions & FitBoundsOptions);
|
|
31
50
|
/**
|
|
32
51
|
* Style for full feature geometry GeoJSON.
|
|
52
|
+
*
|
|
53
|
+
* - If `false` or `null` then no full geometry is drawn.
|
|
54
|
+
* - If `true` or `undefined` then default-styled full geometry is drawn.
|
|
55
|
+
* - If an object then it must represent the style and will be used to style the full geometry.
|
|
56
|
+
*
|
|
57
|
+
* Default is the default style.
|
|
33
58
|
*/
|
|
34
|
-
fullGeometryStyle?:
|
|
35
|
-
fill: Pick<FillLayerSpecification, "layout" | "paint" | "filter">;
|
|
36
|
-
line: Pick<LineLayerSpecification, "layout" | "paint" | "filter">;
|
|
37
|
-
};
|
|
59
|
+
fullGeometryStyle?: null | boolean | FullGeometryStyle;
|
|
38
60
|
};
|
|
39
61
|
export type Props<T> = T extends SvelteComponent<infer P> ? P : never;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
62
|
+
type EventedConstructor = new (...args: ConstructorParameters<typeof Evented>) => Evented;
|
|
63
|
+
export declare function crateBaseClass(Evented: EventedConstructor, maplibreGl: MapLibreGL, getExtraProps?: (map: Map, div: HTMLElement) => Partial<Props<GeocodingControlComponent>>): {
|
|
64
|
+
new <T extends MapLibreBaseControlOptions>(options?: T): {
|
|
65
|
+
"__#1@#gc"?: GeocodingControlComponent;
|
|
66
|
+
"__#1@#options": T;
|
|
67
|
+
onAddInt(map: Map): HTMLElement;
|
|
68
|
+
setOptions(options: T): void;
|
|
69
|
+
setQuery(value: string, submit?: boolean): void;
|
|
70
|
+
clearMap(): void;
|
|
71
|
+
clearList(): void;
|
|
72
|
+
setReverseMode(value: boolean): void;
|
|
73
|
+
focus(): void;
|
|
74
|
+
blur(): void;
|
|
75
|
+
onRemove(): void;
|
|
76
|
+
_listeners: import("maplibre-gl").Listeners;
|
|
77
|
+
_oneTimeListeners: import("maplibre-gl").Listeners;
|
|
78
|
+
_eventedParent: Evented;
|
|
79
|
+
_eventedParentData: any | (() => any);
|
|
80
|
+
on(type: string, listener: import("maplibre-gl").Listener): any;
|
|
81
|
+
off(type: string, listener: import("maplibre-gl").Listener): any;
|
|
82
|
+
once(type: string, listener?: import("maplibre-gl").Listener): Promise<any> | any;
|
|
83
|
+
fire(event: {
|
|
84
|
+
readonly type: string;
|
|
85
|
+
} | string, properties?: any): any;
|
|
86
|
+
listens(type: string): boolean;
|
|
87
|
+
setEventedParent(parent?: Evented | null, data?: any | (() => any)): any;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
@@ -1,70 +1,73 @@
|
|
|
1
1
|
import GeocodingControlComponent from "./GeocodingControl.svelte";
|
|
2
|
-
import { createMapLibreGlMapController } from "./maplibregl-controller";
|
|
3
|
-
export { createMapLibreGlMapController } from "./maplibregl-controller";
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
onAddInt(map) {
|
|
12
|
-
const div = document.createElement("div");
|
|
13
|
-
div.className =
|
|
14
|
-
"mapboxgl-ctrl-geocoder mapboxgl-ctrl maplibregl-ctrl-geocoder maplibregl-ctrl mapboxgl-ctrl-group";
|
|
15
|
-
const { marker, showResultMarkers, flyTo, fullGeometryStyle, ...restOptions } = this.#options;
|
|
16
|
-
const flyToOptions = typeof flyTo === "boolean" ? {} : flyTo;
|
|
17
|
-
const extraConfig = this.getExtraProps(map, div);
|
|
18
|
-
const mapController = createMapLibreGlMapController(map, this.getMapLibreGl(), marker, showResultMarkers, flyToOptions, flyToOptions, fullGeometryStyle);
|
|
19
|
-
const props = {
|
|
20
|
-
mapController,
|
|
21
|
-
flyTo: flyTo === undefined ? true : !!flyTo,
|
|
22
|
-
apiKey: "", // just to satisfy apiKey; TODO find a better solution
|
|
23
|
-
...extraConfig,
|
|
24
|
-
...restOptions,
|
|
25
|
-
};
|
|
26
|
-
if (!props.apiKey) {
|
|
27
|
-
throw new Error("no apiKey provided");
|
|
2
|
+
import { createMapLibreGlMapController, } from "./maplibregl-controller";
|
|
3
|
+
export { createMapLibreGlMapController, } from "./maplibregl-controller";
|
|
4
|
+
export function crateBaseClass(Evented, maplibreGl, getExtraProps) {
|
|
5
|
+
return class MapLibreBasedGeocodingControl extends Evented {
|
|
6
|
+
#gc;
|
|
7
|
+
#options;
|
|
8
|
+
constructor(options = {}) {
|
|
9
|
+
super();
|
|
10
|
+
this.#options = options;
|
|
28
11
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
12
|
+
onAddInt(map) {
|
|
13
|
+
const div = document.createElement("div");
|
|
14
|
+
div.className =
|
|
15
|
+
"mapboxgl-ctrl-geocoder mapboxgl-ctrl maplibregl-ctrl-geocoder maplibregl-ctrl mapboxgl-ctrl-group";
|
|
16
|
+
const { marker, showResultMarkers, flyTo, fullGeometryStyle, ...restOptions } = this.#options;
|
|
17
|
+
const flyToOptions = typeof flyTo === "boolean" ? {} : flyTo;
|
|
18
|
+
const mapController = createMapLibreGlMapController(map, maplibreGl, marker, showResultMarkers, flyToOptions, flyToOptions, fullGeometryStyle);
|
|
19
|
+
const props = {
|
|
20
|
+
mapController,
|
|
21
|
+
flyTo: flyTo === undefined ? true : !!flyTo,
|
|
22
|
+
apiKey: "", // just to satisfy apiKey; TODO find a better solution
|
|
23
|
+
...getExtraProps?.(map, div),
|
|
24
|
+
...restOptions,
|
|
25
|
+
};
|
|
26
|
+
if (!props.apiKey) {
|
|
27
|
+
throw new Error("no apiKey provided");
|
|
28
|
+
}
|
|
29
|
+
this.#gc = new GeocodingControlComponent({ target: div, props });
|
|
30
|
+
for (const eventName of [
|
|
31
|
+
"select",
|
|
32
|
+
"pick",
|
|
33
|
+
"featuresListed",
|
|
34
|
+
"featuresMarked",
|
|
35
|
+
"response",
|
|
36
|
+
"optionsVisibilityChange",
|
|
37
|
+
"reverseToggle",
|
|
38
|
+
"queryChange",
|
|
39
|
+
]) {
|
|
40
|
+
this.#gc.$on(eventName, (event) => {
|
|
41
|
+
this.fire(eventName, event.detail);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return div;
|
|
41
45
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
46
|
+
setOptions(options) {
|
|
47
|
+
this.#options = options;
|
|
48
|
+
const { marker, showResultMarkers, flyTo, fullGeometryStyle, ...restOptions } = this.#options;
|
|
49
|
+
this.#gc?.$set(restOptions);
|
|
50
|
+
}
|
|
51
|
+
setQuery(value, submit = true) {
|
|
52
|
+
this.#gc?.setQuery(value, submit);
|
|
53
|
+
}
|
|
54
|
+
clearMap() {
|
|
55
|
+
this.#gc?.clearMap();
|
|
56
|
+
}
|
|
57
|
+
clearList() {
|
|
58
|
+
this.#gc?.clearList();
|
|
59
|
+
}
|
|
60
|
+
setReverseMode(value) {
|
|
61
|
+
this.#gc?.$set({ reverseActive: value });
|
|
62
|
+
}
|
|
63
|
+
focus() {
|
|
64
|
+
this.#gc?.focus();
|
|
65
|
+
}
|
|
66
|
+
blur() {
|
|
67
|
+
this.#gc?.blur();
|
|
68
|
+
}
|
|
69
|
+
onRemove() {
|
|
70
|
+
this.#gc?.$destroy();
|
|
71
|
+
}
|
|
72
|
+
};
|
|
70
73
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as L from "leaflet";
|
|
2
2
|
import type { BBox, Feature, MapEvent, Position } from "./types";
|
|
3
|
-
export declare function createLeafletMapController(map: L.Map, marker?: boolean | L.MarkerOptions, showResultMarkers?: boolean | L.MarkerOptions, flyToOptions?: L.ZoomPanOptions, flyToBounds?: L.FitBoundsOptions, fullGeometryStyle?: L.PathOptions | L.StyleFunction): {
|
|
3
|
+
export declare function createLeafletMapController(map: L.Map, marker?: boolean | null | L.MarkerOptions | ((map: L.Map, feature?: Feature) => L.Marker | undefined | null), showResultMarkers?: boolean | null | L.MarkerOptions | ((map: L.Map, feature: Feature) => L.Marker | undefined | null), flyToOptions?: L.ZoomPanOptions | null, flyToBounds?: L.FitBoundsOptions | null, fullGeometryStyle?: null | boolean | L.PathOptions | L.StyleFunction): {
|
|
4
4
|
setEventHandler(handler: undefined | ((e: MapEvent) => void)): void;
|
|
5
5
|
flyTo(center: Position, zoom?: number): void;
|
|
6
6
|
fitBounds(bbox: BBox, padding: number, maxZoom?: number): void;
|
|
@@ -6,7 +6,7 @@ import * as L from "leaflet";
|
|
|
6
6
|
import { unwrapBbox } from "./geoUtils";
|
|
7
7
|
import MarkerIcon from "./MarkerIcon.svelte";
|
|
8
8
|
import { setMask } from "./mask";
|
|
9
|
-
|
|
9
|
+
const defaultFullGeometryStyle = (feature) => {
|
|
10
10
|
const type = feature?.geometry?.type;
|
|
11
11
|
const weight = feature?.properties?.isMask
|
|
12
12
|
? 0
|
|
@@ -21,13 +21,18 @@ export function createLeafletMapController(map, marker = true, showResultMarkers
|
|
|
21
21
|
dashArray: [weight, weight],
|
|
22
22
|
lineCap: "butt",
|
|
23
23
|
};
|
|
24
|
-
}
|
|
24
|
+
};
|
|
25
|
+
export function createLeafletMapController(map, marker = true, showResultMarkers = true, flyToOptions = {}, flyToBounds = {}, fullGeometryStyle = defaultFullGeometryStyle) {
|
|
25
26
|
let eventHandler;
|
|
26
27
|
const markers = [];
|
|
27
28
|
let selectedMarker;
|
|
28
29
|
let reverseMarker;
|
|
29
30
|
const resultLayer = L.geoJSON(undefined, {
|
|
30
|
-
style: fullGeometryStyle
|
|
31
|
+
style: fullGeometryStyle === true
|
|
32
|
+
? defaultFullGeometryStyle
|
|
33
|
+
: fullGeometryStyle === false
|
|
34
|
+
? undefined
|
|
35
|
+
: (fullGeometryStyle ?? undefined),
|
|
31
36
|
interactive: false,
|
|
32
37
|
}).addTo(map);
|
|
33
38
|
const handleMapClick = (e) => {
|
|
@@ -93,16 +98,18 @@ export function createLeafletMapController(map, marker = true, showResultMarkers
|
|
|
93
98
|
}
|
|
94
99
|
}
|
|
95
100
|
else if (latLng) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
101
|
+
if (marker instanceof Function) {
|
|
102
|
+
reverseMarker = marker(map) ?? undefined;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
reverseMarker = (typeof marker === "object"
|
|
106
|
+
? new L.Marker(latLng, marker)
|
|
107
|
+
: createMarker(latLng)).addTo(map);
|
|
108
|
+
reverseMarker.getElement()?.classList.add("marker-reverse");
|
|
109
|
+
}
|
|
100
110
|
}
|
|
101
111
|
},
|
|
102
112
|
setMarkers(markedFeatures, picked) {
|
|
103
|
-
if (!marker) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
113
|
function setData(data) {
|
|
107
114
|
resultLayer.clearLayers();
|
|
108
115
|
if (data) {
|
|
@@ -170,10 +177,18 @@ export function createLeafletMapController(map, marker = true, showResultMarkers
|
|
|
170
177
|
setData(picked);
|
|
171
178
|
return; // no pin for (multi)linestrings
|
|
172
179
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
180
|
+
if (marker instanceof Function) {
|
|
181
|
+
const m = marker(map, picked);
|
|
182
|
+
if (m) {
|
|
183
|
+
markers.push(m.addTo(map));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
else if (marker) {
|
|
187
|
+
const pos = [picked.center[1], picked.center[0]];
|
|
188
|
+
markers.push(typeof marker === "object"
|
|
189
|
+
? new L.Marker(pos, marker)
|
|
190
|
+
: createMarker(pos).addTo(map));
|
|
191
|
+
}
|
|
177
192
|
}
|
|
178
193
|
if (showResultMarkers) {
|
|
179
194
|
for (const feature of markedFeatures ?? []) {
|
|
@@ -184,16 +199,24 @@ export function createLeafletMapController(map, marker = true, showResultMarkers
|
|
|
184
199
|
feature.center[1],
|
|
185
200
|
feature.center[0],
|
|
186
201
|
];
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
202
|
+
let marker;
|
|
203
|
+
if (showResultMarkers instanceof Function) {
|
|
204
|
+
marker = showResultMarkers(map, feature);
|
|
205
|
+
if (!marker) {
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
marker = (typeof showResultMarkers === "object"
|
|
211
|
+
? new L.Marker(pos, showResultMarkers)
|
|
212
|
+
: createMarker(pos, true))
|
|
213
|
+
.addTo(map)
|
|
214
|
+
.bindTooltip(feature.place_type[0] === "reverse"
|
|
215
|
+
? feature.place_name
|
|
216
|
+
: feature.place_name.replace(/,.*/, ""), {
|
|
217
|
+
direction: "top",
|
|
218
|
+
});
|
|
219
|
+
}
|
|
197
220
|
const element = marker.getElement();
|
|
198
221
|
if (element) {
|
|
199
222
|
element.addEventListener("click", (e) => {
|
package/svelte/leaflet.d.ts
CHANGED
|
@@ -1,34 +1,70 @@
|
|
|
1
1
|
import * as L from "leaflet";
|
|
2
|
-
import type { ControlOptions } from "./types";
|
|
2
|
+
import type { ControlOptions, Feature } from "./types";
|
|
3
3
|
export { createLeafletMapController } from "./leaflet-controller";
|
|
4
4
|
type LeafletControlOptions = ControlOptions & L.ControlOptions & {
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* If `
|
|
6
|
+
* Marker to be added to the map at the location of the user-selected result using a default set of Marker options.
|
|
7
|
+
*
|
|
8
|
+
* - If `true` or `undefined` then a default marker will be used.\
|
|
9
|
+
* - If the value is [MarkerOptions](https://leafletjs.com/reference.html#marker-option) then the marker will be constructed using these options.
|
|
10
|
+
* - If the value is a function then it can create and configure custom [Marker](https://leafletjs.com/reference.html#marker),
|
|
11
|
+
* add it to the [Map](https://leafletjs.com/reference.html#map) and return it.
|
|
12
|
+
* Function accepts [Map](https://leafletjs.com/reference.html#map) and `Feature` as parameters.
|
|
13
|
+
* Feature is `undefined` for the reverse location marker.
|
|
14
|
+
* - If `false` or `null` then no marker will be added to the map.
|
|
15
|
+
*
|
|
9
16
|
* Default value is `true`.
|
|
10
17
|
*/
|
|
11
|
-
marker?: boolean | L.MarkerOptions;
|
|
18
|
+
marker?: null | boolean | L.MarkerOptions | ((map: L.Map, feature?: Feature) => L.Marker | undefined | null);
|
|
12
19
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* If `
|
|
20
|
+
* Marker be added to the map at the location the geocoding results.
|
|
21
|
+
*
|
|
22
|
+
* - If `true` or `undefined` then a default marker will be used.
|
|
23
|
+
* - If the value is [MarkerOptions](https://leafletjs.com/reference.html#marker-option) then the marker will be constructed using these options.
|
|
24
|
+
* - If the value is a function then it can create and configure custom [Marker](https://leafletjs.com/reference.html#marker),
|
|
25
|
+
* add it to the [Map](https://leafletjs.com/reference.html#map) and return it.
|
|
26
|
+
* In this case the default pop-up won't be added to the marker.
|
|
27
|
+
* Function accepts [Map](https://leafletjs.com/reference.html#map) and `Feature` as parameters.
|
|
28
|
+
* - If `false` or `null` then no marker will be added to the map.
|
|
29
|
+
*
|
|
16
30
|
* Default value is `true`.
|
|
17
31
|
*/
|
|
18
|
-
showResultMarkers?: boolean | L.MarkerOptions;
|
|
32
|
+
showResultMarkers?: null | boolean | L.MarkerOptions | ((map: L.Map, feature: Feature) => L.Marker | undefined | null);
|
|
19
33
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* If
|
|
34
|
+
* Animation to selected feature on the map.
|
|
35
|
+
*
|
|
36
|
+
* - If `false` or `null` then animating the map to a selected result is disabled.
|
|
37
|
+
* - If `true` or `undefined` then animating the map will use the default animation parameters.
|
|
38
|
+
* - If an [ZoomPanOptions](https://leafletjs.com/reference.html#zoom/pan-options)
|
|
39
|
+
* ` & `[FitBoundsOptions](https://leafletjs.com/reference.html#fitbounds-options) then it will be passed as options
|
|
40
|
+
* to the map [flyTo](https://leafletjs.com/reference.html#map-flyto)
|
|
41
|
+
* or [fitBounds](https://leafletjs.com/reference.html#map-fitbounds) method providing control over the animation of the transition.
|
|
42
|
+
*
|
|
23
43
|
* Default value is `true`.
|
|
24
44
|
*/
|
|
25
|
-
flyTo?: boolean | (L.ZoomPanOptions & L.FitBoundsOptions);
|
|
45
|
+
flyTo?: null | boolean | (L.ZoomPanOptions & L.FitBoundsOptions);
|
|
26
46
|
/**
|
|
27
|
-
* Style for full feature geometry
|
|
47
|
+
* Style for the full feature geometry.
|
|
48
|
+
*
|
|
49
|
+
* - If `false` or `null` then no full geometry is drawn.
|
|
50
|
+
* - If `true` or `undefined` then default-styled full geometry is drawn.
|
|
51
|
+
* - If an [PathOptions](https://leafletjs.com/reference.html#path-option) then it will be used to style the full geometry.
|
|
52
|
+
* - If a function accepting a `Feature` and returning [PathOptions](https://leafletjs.com/reference.html#path-option)
|
|
53
|
+
* then it must teturn the style and will be used to style the full geometry.
|
|
28
54
|
*/
|
|
29
|
-
fullGeometryStyle?: L.PathOptions | L.StyleFunction;
|
|
55
|
+
fullGeometryStyle?: null | boolean | L.PathOptions | L.StyleFunction;
|
|
30
56
|
};
|
|
31
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Leaflet mixins https://leafletjs.com/reference.html#class
|
|
59
|
+
* for TypeScript https://www.typescriptlang.org/docs/handbook/mixins.html
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
62
|
+
declare class EventedControl {
|
|
63
|
+
constructor(...args: unknown[]);
|
|
64
|
+
}
|
|
65
|
+
interface EventedControl extends L.Control, L.Evented {
|
|
66
|
+
}
|
|
67
|
+
export declare class GeocodingControl extends EventedControl {
|
|
32
68
|
#private;
|
|
33
69
|
constructor(options: LeafletControlOptions);
|
|
34
70
|
onAdd(map: L.Map): HTMLDivElement;
|
package/svelte/leaflet.js
CHANGED
|
@@ -2,7 +2,19 @@ import * as L from "leaflet";
|
|
|
2
2
|
import GeocodingControlComponent from "./GeocodingControl.svelte";
|
|
3
3
|
import { createLeafletMapController } from "./leaflet-controller";
|
|
4
4
|
export { createLeafletMapController } from "./leaflet-controller";
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Leaflet mixins https://leafletjs.com/reference.html#class
|
|
7
|
+
* for TypeScript https://www.typescriptlang.org/docs/handbook/mixins.html
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging, @typescript-eslint/no-extraneous-class
|
|
11
|
+
class EventedControl {
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars
|
|
13
|
+
constructor(...args) { }
|
|
14
|
+
}
|
|
15
|
+
L.Util.extend(EventedControl.prototype, L.Control.prototype);
|
|
16
|
+
L.Util.extend(EventedControl.prototype, L.Evented.prototype);
|
|
17
|
+
export class GeocodingControl extends EventedControl {
|
|
6
18
|
#gc;
|
|
7
19
|
#options;
|
|
8
20
|
constructor(options) {
|
|
@@ -35,7 +47,7 @@ export class GeocodingControl extends L.Control {
|
|
|
35
47
|
"reverseToggle",
|
|
36
48
|
"queryChange",
|
|
37
49
|
]) {
|
|
38
|
-
this.#gc.$on(eventName, (event) =>
|
|
50
|
+
this.#gc.$on(eventName, (event) => this.fire(eventName.toLowerCase(), event.detail));
|
|
39
51
|
}
|
|
40
52
|
return div;
|
|
41
53
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type * as maplibregl from "maplibre-gl";
|
|
2
|
-
import type { FillLayerSpecification, FitBoundsOptions, FlyToOptions, LineLayerSpecification, Map } from "maplibre-gl";
|
|
2
|
+
import type { FillLayerSpecification, FitBoundsOptions, FlyToOptions, LineLayerSpecification, Map, Marker, MarkerOptions } from "maplibre-gl";
|
|
3
3
|
import type { BBox, Position } from "./types";
|
|
4
4
|
import type { Feature, MapEvent } from "./types.js";
|
|
5
|
-
type MapLibreGL = Pick<typeof maplibregl, "Marker" | "Popup">;
|
|
6
|
-
export
|
|
7
|
-
fill
|
|
8
|
-
line
|
|
9
|
-
}
|
|
5
|
+
export type MapLibreGL = Pick<typeof maplibregl, "Marker" | "Popup">;
|
|
6
|
+
export type FullGeometryStyle = {
|
|
7
|
+
fill: Pick<FillLayerSpecification, "layout" | "paint" | "filter">;
|
|
8
|
+
line: Pick<LineLayerSpecification, "layout" | "paint" | "filter">;
|
|
9
|
+
};
|
|
10
|
+
export declare function createMapLibreGlMapController(map: Map, maplibregl?: MapLibreGL | undefined, marker?: boolean | null | MarkerOptions | ((map: Map, feature?: Feature) => Marker | undefined | null), showResultMarkers?: boolean | null | MarkerOptions | ((map: Map, feature: Feature) => Marker | undefined | null), flyToOptions?: FlyToOptions | null, fitBoundsOptions?: FitBoundsOptions | null, fullGeometryStyle?: boolean | null | FullGeometryStyle): {
|
|
10
11
|
setEventHandler(handler: undefined | ((e: MapEvent) => void)): void;
|
|
11
12
|
flyTo(center: Position, zoom?: number): void;
|
|
12
13
|
fitBounds(bbox: BBox, padding: number, maxZoom?: number): void;
|
|
@@ -16,4 +17,3 @@ export declare function createMapLibreGlMapController(map: Map, maplibregl?: Map
|
|
|
16
17
|
setSelectedMarker(index: number): void;
|
|
17
18
|
getCenterAndZoom(): [number, number, number];
|
|
18
19
|
};
|
|
19
|
-
export {};
|