@maptiler/geocoding-control 0.0.38 → 0.0.43
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/dist/leaflet.js +14400 -1384
- package/dist/leaflet.umd.js +6 -3
- package/dist/lib/LeafletGeocodingControl.d.ts +1 -1
- package/dist/lib/MaplibreglGeocodingControl.d.ts +4 -4
- package/dist/lib/mask.d.ts +2 -0
- package/dist/lib/types.d.ts +5 -5
- package/dist/maplibregl.js +14417 -1405
- package/dist/maplibregl.umd.js +6 -3
- package/package.json +19 -7
- package/src/lib/GeocodingControl.svelte +22 -5
- package/src/lib/MaplibreglGeocodingControl.ts +10 -13
- package/src/lib/leafletMapController.ts +9 -5
- package/src/lib/maplibreglMapController.ts +5 -5
- package/src/lib/mask.ts +69 -0
package/package.json
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maptiler/geocoding-control",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.43",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Martin Ždila",
|
|
7
|
+
"email": "martin.zdila@maptiler.com"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/maptiler/maptiler-geocoding-control"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/maptiler/maptiler-geocoding-control/issues"
|
|
15
|
+
},
|
|
5
16
|
"scripts": {
|
|
6
17
|
"dev": "vite",
|
|
7
18
|
"build": "vite build && mv dist/maplibregl.umd.cjs dist/maplibregl.umd.js && FLAVOUR=leaflet vite build && mv dist/leaflet.umd.cjs dist/leaflet.umd.js && tsc --outDir dist --declaration --emitDeclarationOnly",
|
|
@@ -32,19 +43,20 @@
|
|
|
32
43
|
},
|
|
33
44
|
"types": "./dist/lib/index.d.ts",
|
|
34
45
|
"devDependencies": {
|
|
35
|
-
"@sveltejs/vite-plugin-svelte": "^1.
|
|
46
|
+
"@sveltejs/vite-plugin-svelte": "^1.2.0",
|
|
36
47
|
"@tsconfig/svelte": "^3.0.0",
|
|
37
|
-
"@turf/
|
|
48
|
+
"@turf/buffer": "^6.5.0",
|
|
49
|
+
"@turf/difference": "^6.5.0",
|
|
38
50
|
"@turf/union": "^6.5.0",
|
|
39
51
|
"@types/leaflet": "^1.9.0",
|
|
40
52
|
"prettier": "^2.7.1",
|
|
41
|
-
"prettier-plugin-svelte": "^2.8.
|
|
42
|
-
"svelte": "^3.
|
|
53
|
+
"prettier-plugin-svelte": "^2.8.1",
|
|
54
|
+
"svelte": "^3.53.1",
|
|
43
55
|
"svelte-check": "^2.9.2",
|
|
44
56
|
"svelte-preprocess": "^4.10.7",
|
|
45
57
|
"tslib": "^2.4.1",
|
|
46
|
-
"typescript": "^4.
|
|
47
|
-
"vite": "^3.2.
|
|
58
|
+
"typescript": "^4.9.3",
|
|
59
|
+
"vite": "^3.2.4"
|
|
48
60
|
},
|
|
49
61
|
"peerDependencies": {
|
|
50
62
|
"leaflet": "^1.9.2",
|
|
@@ -272,19 +272,17 @@
|
|
|
272
272
|
|
|
273
273
|
const sp = new URLSearchParams();
|
|
274
274
|
|
|
275
|
-
sp.set("key", apiKey);
|
|
276
|
-
|
|
277
275
|
if (language) {
|
|
278
276
|
sp.set("language", String(language));
|
|
279
277
|
}
|
|
280
278
|
|
|
281
279
|
if (!isReverse) {
|
|
282
280
|
if (bbox) {
|
|
283
|
-
sp.set("bbox", bbox.join(","));
|
|
281
|
+
sp.set("bbox", bbox.map((c) => c.toFixed(6)).join(","));
|
|
284
282
|
}
|
|
285
283
|
|
|
286
284
|
if (proximity) {
|
|
287
|
-
sp.set("proximity", proximity.join(","));
|
|
285
|
+
sp.set("proximity", proximity.map((c) => c.toFixed(6)).join(","));
|
|
288
286
|
}
|
|
289
287
|
|
|
290
288
|
// sp.set("autocomplete", String(autocomplete));
|
|
@@ -294,6 +292,8 @@
|
|
|
294
292
|
|
|
295
293
|
// sp.set("limit", String(limit));
|
|
296
294
|
|
|
295
|
+
sp.set("key", apiKey);
|
|
296
|
+
|
|
297
297
|
const url =
|
|
298
298
|
import.meta.env.VITE_API_URL +
|
|
299
299
|
"/" +
|
|
@@ -381,10 +381,27 @@
|
|
|
381
381
|
}
|
|
382
382
|
}
|
|
383
383
|
|
|
384
|
+
// taken from Leaflet
|
|
385
|
+
export function wrapNum(
|
|
386
|
+
x: number,
|
|
387
|
+
range: [number, number],
|
|
388
|
+
includeMax: boolean
|
|
389
|
+
) {
|
|
390
|
+
const max = range[1],
|
|
391
|
+
min = range[0],
|
|
392
|
+
d = max - min;
|
|
393
|
+
|
|
394
|
+
return x === max && includeMax ? x : ((((x - min) % d) + d) % d) + min;
|
|
395
|
+
}
|
|
396
|
+
|
|
384
397
|
function handleReverse(coordinates: [lng: number, lat: number]) {
|
|
385
398
|
reverseActive = enableReverse === "always";
|
|
386
399
|
|
|
387
|
-
setQuery(
|
|
400
|
+
setQuery(
|
|
401
|
+
wrapNum(coordinates[0], [-180, 180], true).toFixed(6) +
|
|
402
|
+
"," +
|
|
403
|
+
coordinates[1].toFixed(6)
|
|
404
|
+
);
|
|
388
405
|
}
|
|
389
406
|
|
|
390
407
|
function handleKeyDown(e: KeyboardEvent) {
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
type LineLayerSpecification,
|
|
1
|
+
import type {
|
|
2
|
+
Map,
|
|
3
|
+
IControl,
|
|
4
|
+
MarkerOptions,
|
|
5
|
+
FlyToOptions,
|
|
6
|
+
FitBoundsOptions,
|
|
7
|
+
FillLayerSpecification,
|
|
8
|
+
LineLayerSpecification,
|
|
10
9
|
} from "maplibre-gl";
|
|
11
10
|
import type maplibregl from "maplibre-gl";
|
|
12
11
|
import GeocodingControlComponent from "./GeocodingControl.svelte";
|
|
@@ -61,7 +60,7 @@ type MapLibreControlOptions = ControlOptions & {
|
|
|
61
60
|
};
|
|
62
61
|
};
|
|
63
62
|
|
|
64
|
-
export class GeocodingControl extends
|
|
63
|
+
export class GeocodingControl extends EventTarget implements IControl {
|
|
65
64
|
#gc?: GeocodingControlComponent;
|
|
66
65
|
|
|
67
66
|
#options: MapLibreControlOptions;
|
|
@@ -118,9 +117,7 @@ export class GeocodingControl extends Evented implements IControl {
|
|
|
118
117
|
"reverseToggle",
|
|
119
118
|
"queryChange",
|
|
120
119
|
]) {
|
|
121
|
-
this.#gc.$on(eventName, (event) =>
|
|
122
|
-
this.fire(eventName.toLowerCase(), event.detail)
|
|
123
|
-
);
|
|
120
|
+
this.#gc.$on(eventName, (event) => this.dispatchEvent(event));
|
|
124
121
|
}
|
|
125
122
|
|
|
126
123
|
return div;
|
|
@@ -7,8 +7,8 @@ import type {
|
|
|
7
7
|
LineString,
|
|
8
8
|
MultiLineString,
|
|
9
9
|
} from "@turf/helpers";
|
|
10
|
-
import mask from "@turf/mask";
|
|
11
10
|
import union from "@turf/union";
|
|
11
|
+
import { setMask } from "./mask";
|
|
12
12
|
|
|
13
13
|
export function createLeafletMapController(
|
|
14
14
|
map: L.Map,
|
|
@@ -19,12 +19,16 @@ export function createLeafletMapController(
|
|
|
19
19
|
fullGeometryStyle: L.PathOptions | L.StyleFunction = (feature) => {
|
|
20
20
|
const type = feature?.geometry?.type;
|
|
21
21
|
|
|
22
|
-
const weight =
|
|
22
|
+
const weight = feature?.properties?.isMask
|
|
23
|
+
? 0
|
|
24
|
+
: type === "LineString" || type === "MultiLineString"
|
|
25
|
+
? 3
|
|
26
|
+
: 2;
|
|
23
27
|
|
|
24
28
|
return {
|
|
25
29
|
color: "#3170fe",
|
|
26
30
|
fillColor: "#000",
|
|
27
|
-
fillOpacity: 0.1,
|
|
31
|
+
fillOpacity: feature?.properties?.isMask ? 0.1 : 0,
|
|
28
32
|
weight,
|
|
29
33
|
dashArray: [weight, weight],
|
|
30
34
|
lineCap: "butt",
|
|
@@ -167,7 +171,7 @@ export function createLeafletMapController(
|
|
|
167
171
|
| MultiPolygon; // union actually returns geometry
|
|
168
172
|
}
|
|
169
173
|
|
|
170
|
-
|
|
174
|
+
setMask({ ...picked, geometry }, setData);
|
|
171
175
|
|
|
172
176
|
handled = true;
|
|
173
177
|
} else {
|
|
@@ -194,7 +198,7 @@ export function createLeafletMapController(
|
|
|
194
198
|
picked.geometry.type === "Polygon" ||
|
|
195
199
|
picked.geometry.type === "MultiPolygon"
|
|
196
200
|
) {
|
|
197
|
-
|
|
201
|
+
setMask(picked as any, setData);
|
|
198
202
|
} else if (
|
|
199
203
|
picked.geometry.type === "LineString" ||
|
|
200
204
|
picked.geometry.type === "MultiLineString"
|
|
@@ -12,7 +12,6 @@ import type {
|
|
|
12
12
|
} from "maplibre-gl";
|
|
13
13
|
import MarkerIcon from "./MarkerIcon.svelte";
|
|
14
14
|
import type { Feature, MapController, Proximity } from "./types";
|
|
15
|
-
import mask from "@turf/mask";
|
|
16
15
|
import union from "@turf/union";
|
|
17
16
|
import type {
|
|
18
17
|
Polygon,
|
|
@@ -20,6 +19,7 @@ import type {
|
|
|
20
19
|
LineString,
|
|
21
20
|
MultiLineString,
|
|
22
21
|
} from "@turf/helpers";
|
|
22
|
+
import { setMask } from "./mask";
|
|
23
23
|
|
|
24
24
|
let emptyGeojson: GeoJSON.FeatureCollection = {
|
|
25
25
|
type: "FeatureCollection",
|
|
@@ -38,11 +38,11 @@ export function createMaplibreglMapController(
|
|
|
38
38
|
line: Pick<LineLayerSpecification, "layout" | "paint" | "filter">;
|
|
39
39
|
} = {
|
|
40
40
|
fill: {
|
|
41
|
-
layout: {},
|
|
42
41
|
paint: {
|
|
43
42
|
"fill-color": "#000",
|
|
44
43
|
"fill-opacity": 0.1,
|
|
45
44
|
},
|
|
45
|
+
filter: ["all", ["==", ["geometry-type"], "Polygon"], ["has", "isMask"]],
|
|
46
46
|
},
|
|
47
47
|
line: {
|
|
48
48
|
layout: {
|
|
@@ -53,6 +53,7 @@ export function createMaplibreglMapController(
|
|
|
53
53
|
"line-dasharray": [1, 1],
|
|
54
54
|
"line-color": "#3170fe",
|
|
55
55
|
},
|
|
56
|
+
filter: ["!", ["has", "isMask"]],
|
|
56
57
|
},
|
|
57
58
|
}
|
|
58
59
|
) {
|
|
@@ -77,7 +78,6 @@ export function createMaplibreglMapController(
|
|
|
77
78
|
id: "full-geom-fill",
|
|
78
79
|
type: "fill",
|
|
79
80
|
source: "full-geom",
|
|
80
|
-
filter: ["==", ["geometry-type"], "Polygon"],
|
|
81
81
|
});
|
|
82
82
|
|
|
83
83
|
map.addLayer({
|
|
@@ -213,7 +213,7 @@ export function createMaplibreglMapController(
|
|
|
213
213
|
| MultiPolygon; // union actually returns geometry
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
|
|
216
|
+
setMask({ ...picked, geometry }, setData);
|
|
217
217
|
|
|
218
218
|
handled = true;
|
|
219
219
|
} else {
|
|
@@ -240,7 +240,7 @@ export function createMaplibreglMapController(
|
|
|
240
240
|
picked.geometry.type === "Polygon" ||
|
|
241
241
|
picked.geometry.type === "MultiPolygon"
|
|
242
242
|
) {
|
|
243
|
-
|
|
243
|
+
setMask(picked as any, setData);
|
|
244
244
|
} else if (
|
|
245
245
|
picked.geometry.type === "LineString" ||
|
|
246
246
|
picked.geometry.type === "MultiLineString"
|
package/src/lib/mask.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Polygon,
|
|
3
|
+
MultiPolygon,
|
|
4
|
+
Feature as TurfFeature,
|
|
5
|
+
Position,
|
|
6
|
+
} from "@turf/helpers";
|
|
7
|
+
import difference from "@turf/difference";
|
|
8
|
+
import buffer from "@turf/buffer";
|
|
9
|
+
|
|
10
|
+
// see https://maplibre.org/maplibre-gl-js-docs/example/line-across-180th-meridian/
|
|
11
|
+
function fixRing(ring: Position[]) {
|
|
12
|
+
let prev: Position | undefined = undefined;
|
|
13
|
+
|
|
14
|
+
for (const c of ring) {
|
|
15
|
+
if (prev && c[0] - prev[0] >= 180) {
|
|
16
|
+
c[0] -= 360;
|
|
17
|
+
} else if (prev && c[0] - prev[0] < -180) {
|
|
18
|
+
c[0] += 360;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
prev = c;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function setMask(
|
|
26
|
+
picked: TurfFeature<Polygon | MultiPolygon>,
|
|
27
|
+
setData: (data: GeoJSON.GeoJSON) => void
|
|
28
|
+
) {
|
|
29
|
+
const diff = difference(
|
|
30
|
+
{
|
|
31
|
+
type: "Polygon",
|
|
32
|
+
coordinates: [
|
|
33
|
+
[
|
|
34
|
+
[180, 90],
|
|
35
|
+
[-180, 90],
|
|
36
|
+
[-180, -90],
|
|
37
|
+
[180, -90],
|
|
38
|
+
[180, 90],
|
|
39
|
+
],
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
picked
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
if (!diff) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
diff.properties = { isMask: "y" };
|
|
50
|
+
|
|
51
|
+
const fixed = buffer(picked, 0);
|
|
52
|
+
|
|
53
|
+
if (fixed.geometry.type === "Polygon") {
|
|
54
|
+
for (const ring of fixed.geometry.coordinates) {
|
|
55
|
+
fixRing(ring);
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
for (const poly of fixed.geometry.coordinates) {
|
|
59
|
+
for (const ring of poly) {
|
|
60
|
+
fixRing(ring);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
setData({
|
|
66
|
+
type: "FeatureCollection",
|
|
67
|
+
features: [fixed, diff],
|
|
68
|
+
});
|
|
69
|
+
}
|