@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.
- package/ClearIcon.svelte.d.ts +23 -0
- package/GeocodingControl.svelte +685 -0
- package/GeocodingControl.svelte.d.ts +66 -0
- package/LoadingIcon.svelte.d.ts +23 -0
- package/{src/lib/MarkerIcon.svelte → MarkerIcon.svelte} +1 -2
- package/MarkerIcon.svelte.d.ts +16 -0
- package/ReverseGeocodingIcon.svelte.d.ts +23 -0
- package/SearchIcon.svelte.d.ts +23 -0
- package/leaflet-controller.js +1 -0
- package/leaflet-controller.js.map +1 -0
- package/leaflet-controller.umd.js +1 -0
- package/leaflet-controller.umd.js.map +1 -0
- package/leaflet.js +3998 -4021
- package/leaflet.js.map +1 -0
- package/leaflet.umd.js +6 -5
- package/leaflet.umd.js.map +1 -0
- package/maplibregl-controller.js +1 -0
- package/maplibregl-controller.js.map +1 -0
- package/maplibregl-controller.umd.js +1 -0
- package/maplibregl-controller.umd.js.map +1 -0
- package/maplibregl.js +4089 -4112
- package/maplibregl.js.map +1 -0
- package/maplibregl.umd.js +6 -5
- package/maplibregl.umd.js.map +1 -0
- package/package.json +23 -23
- package/react.js +571 -649
- package/react.js.map +1 -0
- package/react.umd.js +2 -1
- package/react.umd.js.map +1 -0
- package/style.css +1 -1
- package/src/AppLeaflet.svelte +0 -55
- package/src/AppMaplibregl.svelte +0 -45
- package/src/lib/GeocodingControl.svelte +0 -839
- package/src/lib/LeafletGeocodingControl.ts +0 -154
- package/src/lib/MaplibreglGeocodingControl.ts +0 -160
- package/src/lib/ReactGeocodingControl.ts +0 -158
- package/src/lib/leafletMapController.ts +0 -305
- package/src/lib/maplibreglMapController.ts +0 -366
- package/src/lib/mask.ts +0 -70
- package/src/lib/types.ts +0 -235
- package/src/main-copy.ts +0 -59
- package/src/main.ts +0 -65
- package/src/vite-env.d.ts +0 -2
- /package/{src/lib/ClearIcon.svelte → ClearIcon.svelte} +0 -0
- /package/{src/lib/LoadingIcon.svelte → LoadingIcon.svelte} +0 -0
- /package/{src/lib/ReverseGeocodingIcon.svelte → ReverseGeocodingIcon.svelte} +0 -0
- /package/{src/lib/SearchIcon.svelte → SearchIcon.svelte} +0 -0
- /package/{maplibre.d.ts → maplibregl.d.ts} +0 -0
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
import * as L from "leaflet";
|
|
2
|
-
import MarkerIcon from "./MarkerIcon.svelte";
|
|
3
|
-
import type { Feature, MapController, MapEvent, Proximity } from "./types";
|
|
4
|
-
import type {
|
|
5
|
-
Polygon,
|
|
6
|
-
MultiPolygon,
|
|
7
|
-
LineString,
|
|
8
|
-
MultiLineString,
|
|
9
|
-
} from "@turf/helpers";
|
|
10
|
-
import union from "@turf/union";
|
|
11
|
-
import { setMask } from "./mask";
|
|
12
|
-
import type { GeoJSON } from "geojson";
|
|
13
|
-
|
|
14
|
-
export function createLeafletMapController(
|
|
15
|
-
map: L.Map,
|
|
16
|
-
marker: boolean | L.MarkerOptions = true,
|
|
17
|
-
showResultMarkers: boolean | L.MarkerOptions = true,
|
|
18
|
-
flyToOptions: L.ZoomPanOptions = {},
|
|
19
|
-
flyToBounds: L.FitBoundsOptions = {},
|
|
20
|
-
fullGeometryStyle: L.PathOptions | L.StyleFunction = (feature) => {
|
|
21
|
-
const type = feature?.geometry?.type;
|
|
22
|
-
|
|
23
|
-
const weight = feature?.properties?.isMask
|
|
24
|
-
? 0
|
|
25
|
-
: type === "LineString" || type === "MultiLineString"
|
|
26
|
-
? 3
|
|
27
|
-
: 2;
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
color: "#3170fe",
|
|
31
|
-
fillColor: "#000",
|
|
32
|
-
fillOpacity: feature?.properties?.isMask ? 0.1 : 0,
|
|
33
|
-
weight,
|
|
34
|
-
dashArray: [weight, weight],
|
|
35
|
-
lineCap: "butt",
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
) {
|
|
39
|
-
let eventHandler: ((e: MapEvent) => void) | undefined;
|
|
40
|
-
|
|
41
|
-
let prevProximity: Proximity = undefined;
|
|
42
|
-
|
|
43
|
-
let markers: L.Marker[] = [];
|
|
44
|
-
|
|
45
|
-
let selectedMarker: L.Marker | undefined;
|
|
46
|
-
|
|
47
|
-
let reverseMarker: L.Marker | undefined;
|
|
48
|
-
|
|
49
|
-
let resultLayer = L.geoJSON(undefined, {
|
|
50
|
-
style: fullGeometryStyle,
|
|
51
|
-
interactive: false,
|
|
52
|
-
}).addTo(map);
|
|
53
|
-
|
|
54
|
-
const handleMoveEnd = () => {
|
|
55
|
-
let c: L.LatLng;
|
|
56
|
-
|
|
57
|
-
const proximity =
|
|
58
|
-
map.getZoom() > 10
|
|
59
|
-
? ([(c = map.getCenter().wrap()).lng, c.lat] as [number, number])
|
|
60
|
-
: undefined;
|
|
61
|
-
|
|
62
|
-
if (prevProximity !== proximity) {
|
|
63
|
-
prevProximity = proximity;
|
|
64
|
-
|
|
65
|
-
eventHandler?.({ type: "proximityChange", proximity });
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const handleMapClick = (e: L.LeafletMouseEvent) => {
|
|
70
|
-
eventHandler?.({
|
|
71
|
-
type: "mapClick",
|
|
72
|
-
coordinates: [e.latlng.lng, e.latlng.lat],
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
function createMarker(pos: L.LatLngExpression, interactive = false) {
|
|
77
|
-
const element = document.createElement("div");
|
|
78
|
-
|
|
79
|
-
new MarkerIcon({ props: { displayIn: "leaflet" }, target: element });
|
|
80
|
-
|
|
81
|
-
return new L.Marker(pos, {
|
|
82
|
-
interactive,
|
|
83
|
-
icon: new L.DivIcon({
|
|
84
|
-
html: element,
|
|
85
|
-
className: "",
|
|
86
|
-
iconAnchor: [12, 26],
|
|
87
|
-
iconSize: [25, 30],
|
|
88
|
-
tooltipAnchor: [1, -24],
|
|
89
|
-
}),
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const ctrl: MapController = {
|
|
94
|
-
setEventHandler(handler: undefined | ((e: MapEvent) => void)): void {
|
|
95
|
-
if (handler) {
|
|
96
|
-
eventHandler = handler;
|
|
97
|
-
|
|
98
|
-
map.on("moveend", handleMoveEnd);
|
|
99
|
-
|
|
100
|
-
handleMoveEnd();
|
|
101
|
-
|
|
102
|
-
map.on("click", handleMapClick);
|
|
103
|
-
} else {
|
|
104
|
-
map.off("moveend", handleMoveEnd);
|
|
105
|
-
|
|
106
|
-
eventHandler?.({ type: "proximityChange", proximity: undefined });
|
|
107
|
-
|
|
108
|
-
eventHandler = undefined;
|
|
109
|
-
|
|
110
|
-
map.off("click", handleMapClick);
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
|
|
114
|
-
flyTo(center: [number, number], zoom: number) {
|
|
115
|
-
map.flyTo([center[1], center[0]], zoom, { duration: 2, ...flyToOptions });
|
|
116
|
-
},
|
|
117
|
-
|
|
118
|
-
fitBounds(bbox: [number, number, number, number], padding: number): void {
|
|
119
|
-
map.flyToBounds(
|
|
120
|
-
[
|
|
121
|
-
[bbox[1], bbox[0]],
|
|
122
|
-
[bbox[3], bbox[2]],
|
|
123
|
-
],
|
|
124
|
-
{ padding: [padding, padding], duration: 2, ...flyToBounds }
|
|
125
|
-
);
|
|
126
|
-
},
|
|
127
|
-
|
|
128
|
-
indicateReverse(reverse: boolean): void {
|
|
129
|
-
map.getContainer().style.cursor = reverse ? "crosshair" : "";
|
|
130
|
-
},
|
|
131
|
-
|
|
132
|
-
setReverseMarker(coordinates: [number, number]) {
|
|
133
|
-
if (!marker) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const latLng =
|
|
138
|
-
coordinates && ([coordinates[1], coordinates[0]] as [number, number]);
|
|
139
|
-
|
|
140
|
-
if (reverseMarker) {
|
|
141
|
-
if (!latLng) {
|
|
142
|
-
reverseMarker.remove();
|
|
143
|
-
|
|
144
|
-
reverseMarker = undefined;
|
|
145
|
-
} else {
|
|
146
|
-
reverseMarker.setLatLng(latLng);
|
|
147
|
-
}
|
|
148
|
-
} else if (latLng) {
|
|
149
|
-
reverseMarker = (
|
|
150
|
-
typeof marker === "object"
|
|
151
|
-
? new L.Marker(latLng, marker)
|
|
152
|
-
: createMarker(latLng)
|
|
153
|
-
).addTo(map);
|
|
154
|
-
|
|
155
|
-
reverseMarker.getElement()?.classList.add("marker-reverse");
|
|
156
|
-
}
|
|
157
|
-
},
|
|
158
|
-
|
|
159
|
-
setMarkers(
|
|
160
|
-
markedFeatures: Feature[] | undefined,
|
|
161
|
-
picked: Feature | undefined
|
|
162
|
-
): void {
|
|
163
|
-
if (!marker) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function setData(data?: GeoJSON) {
|
|
168
|
-
resultLayer.clearLayers();
|
|
169
|
-
|
|
170
|
-
if (data) {
|
|
171
|
-
resultLayer.addData(data);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
for (const marker of markers) {
|
|
176
|
-
marker.remove();
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
markers.length = 0;
|
|
180
|
-
|
|
181
|
-
setData();
|
|
182
|
-
|
|
183
|
-
if (picked) {
|
|
184
|
-
let handled = false;
|
|
185
|
-
|
|
186
|
-
if (picked.geometry.type === "GeometryCollection") {
|
|
187
|
-
const geoms = picked.geometry.geometries.filter(
|
|
188
|
-
(geometry) =>
|
|
189
|
-
geometry.type === "Polygon" || geometry.type === "MultiPolygon"
|
|
190
|
-
) as (Polygon | MultiPolygon)[];
|
|
191
|
-
|
|
192
|
-
if (geoms.length > 0) {
|
|
193
|
-
let geometry = geoms.pop()!;
|
|
194
|
-
|
|
195
|
-
for (const geom of geoms) {
|
|
196
|
-
geometry = union(geometry, geom) as unknown as
|
|
197
|
-
| Polygon
|
|
198
|
-
| MultiPolygon; // union actually returns geometry
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
setMask({ ...picked, geometry }, setData);
|
|
202
|
-
|
|
203
|
-
handled = true;
|
|
204
|
-
} else {
|
|
205
|
-
const geometries = picked.geometry.geometries.filter(
|
|
206
|
-
(geometry) =>
|
|
207
|
-
geometry.type === "LineString" ||
|
|
208
|
-
geometry.type === "MultiLineString"
|
|
209
|
-
) as (LineString | MultiLineString)[];
|
|
210
|
-
|
|
211
|
-
if (geometries.length > 0) {
|
|
212
|
-
setData({
|
|
213
|
-
...picked,
|
|
214
|
-
geometry: { type: "GeometryCollection", geometries },
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
handled = true;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (handled) {
|
|
223
|
-
// nothing
|
|
224
|
-
} else if (
|
|
225
|
-
picked.geometry.type === "Polygon" ||
|
|
226
|
-
picked.geometry.type === "MultiPolygon"
|
|
227
|
-
) {
|
|
228
|
-
setMask(picked as any, setData);
|
|
229
|
-
} else if (
|
|
230
|
-
picked.geometry.type === "LineString" ||
|
|
231
|
-
picked.geometry.type === "MultiLineString"
|
|
232
|
-
) {
|
|
233
|
-
setData(picked as any);
|
|
234
|
-
|
|
235
|
-
return; // no pin for (multi)linestrings
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
const pos: L.LatLngExpression = [picked.center[1], picked.center[0]];
|
|
239
|
-
|
|
240
|
-
markers.push(
|
|
241
|
-
(typeof marker === "object"
|
|
242
|
-
? new L.Marker(pos, marker)
|
|
243
|
-
: createMarker(pos)
|
|
244
|
-
).addTo(map)
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
if (showResultMarkers) {
|
|
249
|
-
for (const feature of markedFeatures ?? []) {
|
|
250
|
-
if (feature === picked) {
|
|
251
|
-
continue;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const pos: L.LatLngExpression = [
|
|
255
|
-
feature.center[1],
|
|
256
|
-
feature.center[0],
|
|
257
|
-
];
|
|
258
|
-
|
|
259
|
-
const marker =
|
|
260
|
-
typeof showResultMarkers === "object"
|
|
261
|
-
? new L.Marker(pos, showResultMarkers)
|
|
262
|
-
: createMarker(pos, true);
|
|
263
|
-
|
|
264
|
-
marker.addTo(map).bindTooltip(feature.place_name.replace(/,.*/, ""), {
|
|
265
|
-
direction: "top",
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
const element = marker.getElement();
|
|
269
|
-
|
|
270
|
-
if (element) {
|
|
271
|
-
element.addEventListener("click", (e) => {
|
|
272
|
-
e.stopPropagation();
|
|
273
|
-
|
|
274
|
-
eventHandler?.({ type: "markerClick", id: feature.id });
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
element.addEventListener("mouseenter", () => {
|
|
278
|
-
eventHandler?.({ type: "markerMouseEnter", id: feature.id });
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
element.addEventListener("mouseleave", () => {
|
|
282
|
-
eventHandler?.({ type: "markerMouseLeave", id: feature.id });
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
element.classList.toggle("marker-fuzzy", !!feature.matching_text);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
markers.push(marker);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
},
|
|
292
|
-
|
|
293
|
-
setSelectedMarker(index: number): void {
|
|
294
|
-
if (selectedMarker) {
|
|
295
|
-
selectedMarker.getElement()?.classList.toggle("marker-selected", false);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
selectedMarker = index > -1 ? markers[index] : undefined;
|
|
299
|
-
|
|
300
|
-
selectedMarker?.getElement()?.classList.toggle("marker-selected", true);
|
|
301
|
-
},
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
return ctrl;
|
|
305
|
-
}
|
|
@@ -1,366 +0,0 @@
|
|
|
1
|
-
import type MapLibreGL from "maplibre-gl";
|
|
2
|
-
import type {
|
|
3
|
-
FitBoundsOptions,
|
|
4
|
-
MapMouseEvent,
|
|
5
|
-
LngLat,
|
|
6
|
-
Map,
|
|
7
|
-
Marker,
|
|
8
|
-
FlyToOptions,
|
|
9
|
-
GeoJSONSource,
|
|
10
|
-
FillLayerSpecification,
|
|
11
|
-
LineLayerSpecification,
|
|
12
|
-
} from "maplibre-gl";
|
|
13
|
-
import MarkerIcon from "./MarkerIcon.svelte";
|
|
14
|
-
import type { Feature, MapController, MapEvent, Proximity } from "./types.js";
|
|
15
|
-
import union from "@turf/union";
|
|
16
|
-
import type {
|
|
17
|
-
Polygon,
|
|
18
|
-
MultiPolygon,
|
|
19
|
-
LineString,
|
|
20
|
-
MultiLineString,
|
|
21
|
-
} from "@turf/helpers";
|
|
22
|
-
import { setMask } from "./mask";
|
|
23
|
-
import type { FeatureCollection, GeoJSON } from "geojson";
|
|
24
|
-
|
|
25
|
-
let emptyGeojson: FeatureCollection = {
|
|
26
|
-
type: "FeatureCollection",
|
|
27
|
-
features: [],
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export function createMaplibreglMapController(
|
|
31
|
-
map: Map,
|
|
32
|
-
maplibregl?: typeof MapLibreGL | undefined,
|
|
33
|
-
marker: boolean | maplibregl.MarkerOptions = true,
|
|
34
|
-
showResultMarkers: boolean | maplibregl.MarkerOptions = true,
|
|
35
|
-
flyToOptions: FlyToOptions = {},
|
|
36
|
-
fitBoundsOptions: FitBoundsOptions = {},
|
|
37
|
-
fullGeometryStyle:
|
|
38
|
-
| undefined
|
|
39
|
-
| {
|
|
40
|
-
fill?: Pick<FillLayerSpecification, "layout" | "paint" | "filter">;
|
|
41
|
-
line?: Pick<LineLayerSpecification, "layout" | "paint" | "filter">;
|
|
42
|
-
} = {
|
|
43
|
-
fill: {
|
|
44
|
-
paint: {
|
|
45
|
-
"fill-color": "#000",
|
|
46
|
-
"fill-opacity": 0.1,
|
|
47
|
-
},
|
|
48
|
-
filter: ["all", ["==", ["geometry-type"], "Polygon"], ["has", "isMask"]],
|
|
49
|
-
},
|
|
50
|
-
line: {
|
|
51
|
-
layout: {
|
|
52
|
-
"line-cap": "square",
|
|
53
|
-
},
|
|
54
|
-
paint: {
|
|
55
|
-
"line-width": ["case", ["==", ["geometry-type"], "Polygon"], 2, 3],
|
|
56
|
-
"line-dasharray": [1, 1],
|
|
57
|
-
"line-color": "#3170fe",
|
|
58
|
-
},
|
|
59
|
-
filter: ["!", ["has", "isMask"]],
|
|
60
|
-
},
|
|
61
|
-
}
|
|
62
|
-
) {
|
|
63
|
-
let eventHandler: ((e: MapEvent) => void) | undefined;
|
|
64
|
-
|
|
65
|
-
let prevProximity: Proximity = undefined;
|
|
66
|
-
|
|
67
|
-
let markers: Marker[] = [];
|
|
68
|
-
|
|
69
|
-
let selectedMarker: maplibregl.Marker | undefined;
|
|
70
|
-
|
|
71
|
-
let reverseMarker: maplibregl.Marker | undefined;
|
|
72
|
-
|
|
73
|
-
function addFullGeometryLayer() {
|
|
74
|
-
if (fullGeometryStyle?.fill || fullGeometryStyle?.line) {
|
|
75
|
-
map.addSource("full-geom", {
|
|
76
|
-
type: "geojson",
|
|
77
|
-
data: emptyGeojson,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (fullGeometryStyle?.fill) {
|
|
82
|
-
map.addLayer({
|
|
83
|
-
...fullGeometryStyle?.fill,
|
|
84
|
-
id: "full-geom-fill",
|
|
85
|
-
type: "fill",
|
|
86
|
-
source: "full-geom",
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (fullGeometryStyle?.line) {
|
|
91
|
-
map.addLayer({
|
|
92
|
-
...fullGeometryStyle?.line,
|
|
93
|
-
id: "full-geom-line",
|
|
94
|
-
type: "line",
|
|
95
|
-
source: "full-geom",
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (map.loaded()) {
|
|
101
|
-
addFullGeometryLayer();
|
|
102
|
-
} else {
|
|
103
|
-
map.once("load", () => {
|
|
104
|
-
addFullGeometryLayer();
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const handleMapClick = (e: MapMouseEvent) => {
|
|
109
|
-
eventHandler?.({
|
|
110
|
-
type: "mapClick",
|
|
111
|
-
coordinates: [e.lngLat.lng, e.lngLat.lat],
|
|
112
|
-
});
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const handleMoveEnd = () => {
|
|
116
|
-
let c: LngLat;
|
|
117
|
-
|
|
118
|
-
const proximity =
|
|
119
|
-
map.getZoom() > 9
|
|
120
|
-
? ([(c = map.getCenter().wrap()).lng, c.lat] as [number, number])
|
|
121
|
-
: undefined;
|
|
122
|
-
|
|
123
|
-
if (prevProximity !== proximity) {
|
|
124
|
-
prevProximity = proximity;
|
|
125
|
-
|
|
126
|
-
eventHandler?.({ type: "proximityChange", proximity });
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
function createMarker(interactive = false) {
|
|
131
|
-
if (!maplibregl) {
|
|
132
|
-
throw new Error();
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const element = document.createElement("div");
|
|
136
|
-
|
|
137
|
-
if (interactive) {
|
|
138
|
-
element.classList.add("marker-interactive");
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
new MarkerIcon({
|
|
142
|
-
props: { displayIn: "maplibre" },
|
|
143
|
-
target: element,
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
return new maplibregl.Marker({ element, offset: [1, -13] });
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const ctrl: MapController = {
|
|
150
|
-
setEventHandler(handler: undefined | ((e: MapEvent) => void)): void {
|
|
151
|
-
if (handler) {
|
|
152
|
-
eventHandler = handler;
|
|
153
|
-
|
|
154
|
-
map.on("moveend", handleMoveEnd);
|
|
155
|
-
|
|
156
|
-
handleMoveEnd();
|
|
157
|
-
|
|
158
|
-
map.on("click", handleMapClick);
|
|
159
|
-
} else {
|
|
160
|
-
map.off("moveend", handleMoveEnd);
|
|
161
|
-
|
|
162
|
-
eventHandler?.({ type: "proximityChange", proximity: undefined });
|
|
163
|
-
|
|
164
|
-
eventHandler = undefined;
|
|
165
|
-
|
|
166
|
-
map.off("click", handleMapClick);
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
|
|
170
|
-
flyTo(center: [number, number], zoom: number): void {
|
|
171
|
-
map.flyTo({ center, zoom, ...flyToOptions });
|
|
172
|
-
},
|
|
173
|
-
|
|
174
|
-
fitBounds(bbox: [number, number, number, number], padding: number): void {
|
|
175
|
-
map.fitBounds(
|
|
176
|
-
[
|
|
177
|
-
[bbox[0], bbox[1]],
|
|
178
|
-
[bbox[2], bbox[3]],
|
|
179
|
-
],
|
|
180
|
-
{ padding, ...fitBoundsOptions }
|
|
181
|
-
);
|
|
182
|
-
},
|
|
183
|
-
|
|
184
|
-
indicateReverse(reverse: boolean): void {
|
|
185
|
-
map.getCanvasContainer().style.cursor = reverse ? "crosshair" : "";
|
|
186
|
-
},
|
|
187
|
-
|
|
188
|
-
setReverseMarker(coordinates: [number, number]) {
|
|
189
|
-
if (!maplibregl || !marker) {
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (reverseMarker) {
|
|
194
|
-
if (!coordinates) {
|
|
195
|
-
reverseMarker.remove();
|
|
196
|
-
|
|
197
|
-
reverseMarker = undefined;
|
|
198
|
-
} else {
|
|
199
|
-
reverseMarker.setLngLat(coordinates);
|
|
200
|
-
}
|
|
201
|
-
} else if (coordinates) {
|
|
202
|
-
reverseMarker = (
|
|
203
|
-
typeof marker === "object"
|
|
204
|
-
? new maplibregl.Marker(marker)
|
|
205
|
-
: createMarker()
|
|
206
|
-
)
|
|
207
|
-
.setLngLat(coordinates)
|
|
208
|
-
.addTo(map);
|
|
209
|
-
|
|
210
|
-
reverseMarker.getElement().classList.add("marker-reverse");
|
|
211
|
-
}
|
|
212
|
-
},
|
|
213
|
-
|
|
214
|
-
setMarkers(
|
|
215
|
-
markedFeatures: Feature[] | undefined,
|
|
216
|
-
picked: Feature | undefined
|
|
217
|
-
): void {
|
|
218
|
-
if (!marker) {
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
function setData(data: GeoJSON) {
|
|
223
|
-
(map.getSource("full-geom") as GeoJSONSource)?.setData(data);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
for (const marker of markers) {
|
|
227
|
-
marker.remove();
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
markers.length = 0;
|
|
231
|
-
|
|
232
|
-
setData(emptyGeojson);
|
|
233
|
-
|
|
234
|
-
if (!maplibregl) {
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
if (picked) {
|
|
239
|
-
let handled = false;
|
|
240
|
-
|
|
241
|
-
if (picked.geometry.type === "GeometryCollection") {
|
|
242
|
-
const geoms = picked.geometry.geometries.filter(
|
|
243
|
-
(geometry) =>
|
|
244
|
-
geometry.type === "Polygon" || geometry.type === "MultiPolygon"
|
|
245
|
-
) as (Polygon | MultiPolygon)[];
|
|
246
|
-
|
|
247
|
-
if (geoms.length > 0) {
|
|
248
|
-
let geometry = geoms.pop()!;
|
|
249
|
-
|
|
250
|
-
for (const geom of geoms) {
|
|
251
|
-
geometry = union(geometry, geom) as unknown as
|
|
252
|
-
| Polygon
|
|
253
|
-
| MultiPolygon; // union actually returns geometry
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
setMask({ ...picked, geometry }, setData);
|
|
257
|
-
|
|
258
|
-
handled = true;
|
|
259
|
-
} else {
|
|
260
|
-
const geometries = picked.geometry.geometries.filter(
|
|
261
|
-
(geometry) =>
|
|
262
|
-
geometry.type === "LineString" ||
|
|
263
|
-
geometry.type === "MultiLineString"
|
|
264
|
-
) as (LineString | MultiLineString)[];
|
|
265
|
-
|
|
266
|
-
if (geometries.length > 0) {
|
|
267
|
-
setData({
|
|
268
|
-
...picked,
|
|
269
|
-
geometry: { type: "GeometryCollection", geometries },
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
handled = true;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
if (handled) {
|
|
278
|
-
// nothing
|
|
279
|
-
} else if (
|
|
280
|
-
picked.geometry.type === "Polygon" ||
|
|
281
|
-
picked.geometry.type === "MultiPolygon"
|
|
282
|
-
) {
|
|
283
|
-
setMask(picked as any, setData);
|
|
284
|
-
} else if (
|
|
285
|
-
picked.geometry.type === "LineString" ||
|
|
286
|
-
picked.geometry.type === "MultiLineString"
|
|
287
|
-
) {
|
|
288
|
-
setData(picked as any);
|
|
289
|
-
|
|
290
|
-
return; // no pin for (multi)linestrings
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
if (marker) {
|
|
294
|
-
markers.push(
|
|
295
|
-
(typeof marker === "object"
|
|
296
|
-
? new maplibregl.Marker(marker)
|
|
297
|
-
: createMarker()
|
|
298
|
-
)
|
|
299
|
-
.setLngLat(picked.center)
|
|
300
|
-
.addTo(map)
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
if (showResultMarkers) {
|
|
306
|
-
for (const feature of markedFeatures ?? []) {
|
|
307
|
-
if (feature === picked) {
|
|
308
|
-
continue;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
const marker = (
|
|
312
|
-
typeof showResultMarkers === "object"
|
|
313
|
-
? new maplibregl.Marker(showResultMarkers)
|
|
314
|
-
: createMarker(true)
|
|
315
|
-
)
|
|
316
|
-
.setLngLat(feature.center)
|
|
317
|
-
.setPopup(
|
|
318
|
-
new maplibregl.Popup({
|
|
319
|
-
offset: [1, -27],
|
|
320
|
-
closeButton: false,
|
|
321
|
-
closeOnMove: true,
|
|
322
|
-
className: "maptiler-gc-popup",
|
|
323
|
-
}).setText(feature.place_name.replace(/,.*/, ""))
|
|
324
|
-
)
|
|
325
|
-
.addTo(map);
|
|
326
|
-
|
|
327
|
-
const element = marker.getElement();
|
|
328
|
-
|
|
329
|
-
element.addEventListener("click", (e) => {
|
|
330
|
-
e.stopPropagation();
|
|
331
|
-
|
|
332
|
-
eventHandler?.({ type: "markerClick", id: feature.id });
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
element.addEventListener("mouseenter", () => {
|
|
336
|
-
eventHandler?.({ type: "markerMouseEnter", id: feature.id });
|
|
337
|
-
|
|
338
|
-
marker.togglePopup();
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
element.addEventListener("mouseleave", () => {
|
|
342
|
-
eventHandler?.({ type: "markerMouseLeave", id: feature.id });
|
|
343
|
-
|
|
344
|
-
marker.togglePopup();
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
element.classList.toggle("marker-fuzzy", !!feature.matching_text);
|
|
348
|
-
|
|
349
|
-
markers.push(marker);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
},
|
|
353
|
-
|
|
354
|
-
setSelectedMarker(index: number): void {
|
|
355
|
-
if (selectedMarker) {
|
|
356
|
-
selectedMarker.getElement().classList.toggle("marker-selected", false);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
selectedMarker = index > -1 ? markers[index] : undefined;
|
|
360
|
-
|
|
361
|
-
selectedMarker?.getElement().classList.toggle("marker-selected", true);
|
|
362
|
-
},
|
|
363
|
-
};
|
|
364
|
-
|
|
365
|
-
return ctrl;
|
|
366
|
-
}
|