@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
|
@@ -3,7 +3,7 @@ import union from "@turf/union";
|
|
|
3
3
|
import MarkerIcon from "./MarkerIcon.svelte";
|
|
4
4
|
import { setMask } from "./mask";
|
|
5
5
|
const emptyGeojson = featureCollection([]);
|
|
6
|
-
|
|
6
|
+
const defaultGeometryStyle = {
|
|
7
7
|
fill: {
|
|
8
8
|
paint: {
|
|
9
9
|
"fill-color": "#000",
|
|
@@ -22,31 +22,37 @@ export function createMapLibreGlMapController(map, maplibregl, marker = true, sh
|
|
|
22
22
|
},
|
|
23
23
|
filter: ["!", ["has", "isMask"]],
|
|
24
24
|
},
|
|
25
|
-
}
|
|
25
|
+
};
|
|
26
|
+
export function createMapLibreGlMapController(map, maplibregl, marker = true, showResultMarkers = true, flyToOptions = {}, fitBoundsOptions = {}, fullGeometryStyle = defaultGeometryStyle) {
|
|
26
27
|
let eventHandler;
|
|
27
28
|
const markers = [];
|
|
28
29
|
let selectedMarker;
|
|
29
30
|
let reverseMarker;
|
|
30
31
|
let savedData; // used to restore features on style switch
|
|
31
32
|
function addFullGeometryLayer() {
|
|
33
|
+
const effFullGeometryStyle = !fullGeometryStyle
|
|
34
|
+
? undefined
|
|
35
|
+
: fullGeometryStyle === true
|
|
36
|
+
? defaultGeometryStyle
|
|
37
|
+
: fullGeometryStyle;
|
|
32
38
|
if (!map.getSource("full-geom") &&
|
|
33
|
-
(
|
|
39
|
+
(effFullGeometryStyle?.fill || effFullGeometryStyle?.line)) {
|
|
34
40
|
map.addSource("full-geom", {
|
|
35
41
|
type: "geojson",
|
|
36
42
|
data: emptyGeojson,
|
|
37
43
|
});
|
|
38
44
|
}
|
|
39
|
-
if (!map.getLayer("full-geom-fill") &&
|
|
45
|
+
if (!map.getLayer("full-geom-fill") && effFullGeometryStyle?.fill) {
|
|
40
46
|
map.addLayer({
|
|
41
|
-
...
|
|
47
|
+
...effFullGeometryStyle?.fill,
|
|
42
48
|
id: "full-geom-fill",
|
|
43
49
|
type: "fill",
|
|
44
50
|
source: "full-geom",
|
|
45
51
|
});
|
|
46
52
|
}
|
|
47
|
-
if (!map.getLayer("full-geom-line") &&
|
|
53
|
+
if (!map.getLayer("full-geom-line") && effFullGeometryStyle?.line) {
|
|
48
54
|
map.addLayer({
|
|
49
|
-
...
|
|
55
|
+
...effFullGeometryStyle?.line,
|
|
50
56
|
id: "full-geom-line",
|
|
51
57
|
type: "line",
|
|
52
58
|
source: "full-geom",
|
|
@@ -131,18 +137,20 @@ export function createMapLibreGlMapController(map, maplibregl, marker = true, sh
|
|
|
131
137
|
}
|
|
132
138
|
}
|
|
133
139
|
else if (coordinates) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
+
if (marker instanceof Function) {
|
|
141
|
+
reverseMarker = marker(map) ?? undefined;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
reverseMarker = (typeof marker === "object"
|
|
145
|
+
? new maplibregl.Marker(marker)
|
|
146
|
+
: createMarker())
|
|
147
|
+
.setLngLat(coordinates)
|
|
148
|
+
.addTo(map);
|
|
149
|
+
reverseMarker.getElement().classList.add("marker-reverse");
|
|
150
|
+
}
|
|
140
151
|
}
|
|
141
152
|
},
|
|
142
153
|
setMarkers(markedFeatures, picked) {
|
|
143
|
-
if (!marker) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
154
|
for (const marker of markers) {
|
|
147
155
|
marker.remove();
|
|
148
156
|
}
|
|
@@ -190,12 +198,16 @@ export function createMapLibreGlMapController(map, maplibregl, marker = true, sh
|
|
|
190
198
|
setData(picked);
|
|
191
199
|
return; // no pin for (multi)linestrings
|
|
192
200
|
}
|
|
193
|
-
if (marker) {
|
|
194
|
-
|
|
201
|
+
if (marker instanceof Function) {
|
|
202
|
+
const m = marker(map, picked);
|
|
203
|
+
if (m) {
|
|
204
|
+
markers.push(m);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
else if (marker) {
|
|
208
|
+
markers.push(typeof marker === "object"
|
|
195
209
|
? new maplibregl.Marker(marker)
|
|
196
|
-
: createMarker())
|
|
197
|
-
.setLngLat(picked.center)
|
|
198
|
-
.addTo(map));
|
|
210
|
+
: createMarker().setLngLat(picked.center).addTo(map));
|
|
199
211
|
}
|
|
200
212
|
}
|
|
201
213
|
if (showResultMarkers) {
|
|
@@ -203,19 +215,28 @@ export function createMapLibreGlMapController(map, maplibregl, marker = true, sh
|
|
|
203
215
|
if (feature === picked) {
|
|
204
216
|
continue;
|
|
205
217
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
218
|
+
let marker;
|
|
219
|
+
if (showResultMarkers instanceof Function) {
|
|
220
|
+
marker = showResultMarkers(map, feature);
|
|
221
|
+
if (!marker) {
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
marker = (typeof showResultMarkers === "object"
|
|
227
|
+
? new maplibregl.Marker(showResultMarkers)
|
|
228
|
+
: createMarker(true))
|
|
229
|
+
.setLngLat(feature.center)
|
|
230
|
+
.setPopup(new maplibregl.Popup({
|
|
231
|
+
offset: [1, -27],
|
|
232
|
+
closeButton: false,
|
|
233
|
+
closeOnMove: true,
|
|
234
|
+
className: "maptiler-gc-popup",
|
|
235
|
+
}).setText(feature.place_type[0] === "reverse"
|
|
236
|
+
? feature.place_name
|
|
237
|
+
: feature.place_name.replace(/,.*/, "")))
|
|
238
|
+
.addTo(map);
|
|
239
|
+
}
|
|
219
240
|
const element = marker.getElement();
|
|
220
241
|
element.addEventListener("click", (e) => {
|
|
221
242
|
e.stopPropagation();
|
package/svelte/maplibregl.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Map } from "maplibre-gl";
|
|
2
2
|
import * as maplibregl from "maplibre-gl";
|
|
3
|
-
import type
|
|
4
|
-
import { MapLibreBasedGeocodingControl, type MapLibreBaseControlOptions, type Props } from "./MapLibreBasedGeocodingControl";
|
|
3
|
+
import { type MapLibreBaseControlOptions } from "./MapLibreBasedGeocodingControl";
|
|
5
4
|
export { createMapLibreGlMapController } from "./maplibregl-controller";
|
|
6
5
|
type Options = MapLibreBaseControlOptions & {
|
|
7
6
|
/**
|
|
@@ -9,8 +8,33 @@ type Options = MapLibreBaseControlOptions & {
|
|
|
9
8
|
*/
|
|
10
9
|
apiKey: string;
|
|
11
10
|
};
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
declare const Base: {
|
|
12
|
+
new <T extends MapLibreBaseControlOptions>(options?: T): {
|
|
13
|
+
"__#1@#gc"?: import("./GeocodingControl.svelte").default;
|
|
14
|
+
"__#1@#options": T;
|
|
15
|
+
onAddInt(map: Map): HTMLElement;
|
|
16
|
+
setOptions(options: T): void;
|
|
17
|
+
setQuery(value: string, submit?: boolean): void;
|
|
18
|
+
clearMap(): void;
|
|
19
|
+
clearList(): void;
|
|
20
|
+
setReverseMode(value: boolean): void;
|
|
21
|
+
focus(): void;
|
|
22
|
+
blur(): void;
|
|
23
|
+
onRemove(): void;
|
|
24
|
+
_listeners: maplibregl.Listeners;
|
|
25
|
+
_oneTimeListeners: maplibregl.Listeners;
|
|
26
|
+
_eventedParent: maplibregl.Evented;
|
|
27
|
+
_eventedParentData: any | (() => any);
|
|
28
|
+
on(type: string, listener: maplibregl.Listener): any;
|
|
29
|
+
off(type: string, listener: maplibregl.Listener): any;
|
|
30
|
+
once(type: string, listener?: maplibregl.Listener): Promise<any> | any;
|
|
31
|
+
fire(event: {
|
|
32
|
+
readonly type: string;
|
|
33
|
+
} | string, properties?: any): any;
|
|
34
|
+
listens(type: string): boolean;
|
|
35
|
+
setEventedParent(parent?: maplibregl.Evented | null, data?: any | (() => any)): any;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export declare class GeocodingControl extends Base<Options> implements maplibregl.IControl {
|
|
14
39
|
onAdd(map: Map): HTMLElement;
|
|
15
|
-
getExtraProps(): Partial<Props<GeocodingControlComponent>>;
|
|
16
40
|
}
|
package/svelte/maplibregl.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import * as maplibregl from "maplibre-gl";
|
|
2
|
-
import {
|
|
2
|
+
import { crateBaseClass, } from "./MapLibreBasedGeocodingControl";
|
|
3
3
|
export { createMapLibreGlMapController } from "./maplibregl-controller";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return maplibregl;
|
|
7
|
-
}
|
|
4
|
+
const Base = crateBaseClass(maplibregl.Evented, maplibregl);
|
|
5
|
+
export class GeocodingControl extends Base {
|
|
8
6
|
onAdd(map) {
|
|
9
7
|
return super.onAddInt(map);
|
|
10
8
|
}
|
|
11
|
-
getExtraProps() {
|
|
12
|
-
return {};
|
|
13
|
-
}
|
|
14
9
|
}
|
package/svelte/maptilersdk.d.ts
CHANGED
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
import * as maptilersdk from "@maptiler/sdk";
|
|
2
2
|
import type * as maplibregl from "maplibre-gl";
|
|
3
3
|
import type { Map } from "maplibre-gl";
|
|
4
|
-
import type
|
|
5
|
-
import { MapLibreBasedGeocodingControl, type MapLibreBaseControlOptions, type Props } from "./MapLibreBasedGeocodingControl";
|
|
4
|
+
import { type MapLibreBaseControlOptions } from "./MapLibreBasedGeocodingControl";
|
|
6
5
|
export { createMapLibreGlMapController } from "./maplibregl-controller";
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
declare const Base: {
|
|
7
|
+
new <T extends MapLibreBaseControlOptions>(options?: T): {
|
|
8
|
+
"__#1@#gc"?: import("./GeocodingControl.svelte").default;
|
|
9
|
+
"__#1@#options": T;
|
|
10
|
+
onAddInt(map: Map): HTMLElement;
|
|
11
|
+
setOptions(options: T): void;
|
|
12
|
+
setQuery(value: string, submit?: boolean): void;
|
|
13
|
+
clearMap(): void;
|
|
14
|
+
clearList(): void;
|
|
15
|
+
setReverseMode(value: boolean): void;
|
|
16
|
+
focus(): void;
|
|
17
|
+
blur(): void;
|
|
18
|
+
onRemove(): void;
|
|
19
|
+
_listeners: maptilersdk.Listeners;
|
|
20
|
+
_oneTimeListeners: maptilersdk.Listeners;
|
|
21
|
+
_eventedParent: maplibregl.Evented;
|
|
22
|
+
_eventedParentData: any | (() => any);
|
|
23
|
+
on(type: string, listener: maptilersdk.Listener): any;
|
|
24
|
+
off(type: string, listener: maptilersdk.Listener): any;
|
|
25
|
+
once(type: string, listener?: maptilersdk.Listener): Promise<any> | any;
|
|
26
|
+
fire(event: {
|
|
27
|
+
readonly type: string;
|
|
28
|
+
} | string, properties?: any): any;
|
|
29
|
+
listens(type: string): boolean;
|
|
30
|
+
setEventedParent(parent?: maplibregl.Evented | null, data?: any | (() => any)): any;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export declare class GeocodingControl extends Base<MapLibreBaseControlOptions> implements maptilersdk.IControl {
|
|
9
34
|
onAdd(map: maptilersdk.Map): HTMLElement;
|
|
10
|
-
getExtraProps(map: Map, div: HTMLElement): Partial<Props<GeocodingControlComponent>>;
|
|
11
35
|
}
|
package/svelte/maptilersdk.js
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
import * as maptilersdk from "@maptiler/sdk";
|
|
2
|
-
import {
|
|
2
|
+
import { crateBaseClass, } from "./MapLibreBasedGeocodingControl";
|
|
3
3
|
export { createMapLibreGlMapController } from "./maplibregl-controller";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const Base = crateBaseClass(maptilersdk.Evented, maptilersdk, (map, div) => {
|
|
5
|
+
const sdkConfig = {};
|
|
6
|
+
if (!("getSdkConfig" in map && typeof map.getSdkConfig === "function")) {
|
|
7
|
+
throw new Error("MapTiler SDK not detected");
|
|
7
8
|
}
|
|
9
|
+
const { primaryLanguage, apiKey } = map.getSdkConfig();
|
|
10
|
+
sdkConfig.apiKey = apiKey;
|
|
11
|
+
const match = /^([a-z]{2})($|_|-)/.exec(primaryLanguage);
|
|
12
|
+
if (match) {
|
|
13
|
+
sdkConfig.language = match[1];
|
|
14
|
+
}
|
|
15
|
+
div.className += " maptiler-ctrl";
|
|
16
|
+
return sdkConfig;
|
|
17
|
+
});
|
|
18
|
+
export class GeocodingControl extends Base {
|
|
8
19
|
onAdd(map) {
|
|
9
20
|
return super.onAddInt(map);
|
|
10
21
|
}
|
|
11
|
-
getExtraProps(map, div) {
|
|
12
|
-
const sdkConfig = {};
|
|
13
|
-
if (!("getSdkConfig" in map && typeof map.getSdkConfig === "function")) {
|
|
14
|
-
throw new Error("MapTiler SDK not detected");
|
|
15
|
-
}
|
|
16
|
-
const { primaryLanguage, apiKey } = map.getSdkConfig();
|
|
17
|
-
sdkConfig.apiKey = apiKey;
|
|
18
|
-
const match = /^([a-z]{2})($|_|-)/.exec(primaryLanguage);
|
|
19
|
-
if (match) {
|
|
20
|
-
sdkConfig.language = match[1];
|
|
21
|
-
}
|
|
22
|
-
div.className += " maptiler-ctrl";
|
|
23
|
-
return sdkConfig;
|
|
24
|
-
}
|
|
25
22
|
}
|
package/svelte/types.d.ts
CHANGED
|
@@ -207,6 +207,12 @@ export type ControlOptions = {
|
|
|
207
207
|
* Default value is `undefined` - all available feature types are returned.
|
|
208
208
|
*/
|
|
209
209
|
types?: string[];
|
|
210
|
+
/**
|
|
211
|
+
* Use `limit` value for reverse geocoding even if `types` is not an array with a single element.
|
|
212
|
+
* Will work only if enabled on the server.
|
|
213
|
+
* Default value is `false`.
|
|
214
|
+
*/
|
|
215
|
+
exhaustiveReverseGeocoding?: boolean;
|
|
210
216
|
/**
|
|
211
217
|
* If set to `true` then use all types except for those listed in `types`.
|
|
212
218
|
* Default value is `false`.
|
package/types.d.ts
CHANGED
|
@@ -207,6 +207,12 @@ export type ControlOptions = {
|
|
|
207
207
|
* Default value is `undefined` - all available feature types are returned.
|
|
208
208
|
*/
|
|
209
209
|
types?: string[];
|
|
210
|
+
/**
|
|
211
|
+
* Use `limit` value for reverse geocoding even if `types` is not an array with a single element.
|
|
212
|
+
* Will work only if enabled on the server.
|
|
213
|
+
* Default value is `false`.
|
|
214
|
+
*/
|
|
215
|
+
exhaustiveReverseGeocoding?: boolean;
|
|
210
216
|
/**
|
|
211
217
|
* If set to `true` then use all types except for those listed in `types`.
|
|
212
218
|
* Default value is `false`.
|