@maptiler/geocoding-control 2.0.0 → 2.0.1
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 +2616 -27
- package/leaflet-controller.d.ts +1 -1
- package/leaflet-controller.js +97 -95
- package/leaflet-controller.js.map +1 -1
- package/leaflet-controller.umd.js +2 -2
- package/leaflet-controller.umd.js.map +1 -1
- package/leaflet.d.ts +26 -4
- package/leaflet.js +906 -909
- package/leaflet.js.map +1 -1
- package/leaflet.umd.js +3 -3
- package/leaflet.umd.js.map +1 -1
- package/maplibregl-controller.d.ts +1 -1
- package/maplibregl-controller.js +480 -466
- 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 +2594 -9
- package/maplibregl.js +2094 -1969
- package/maplibregl.js.map +1 -1
- package/maplibregl.umd.js +3 -3
- package/maplibregl.umd.js.map +1 -1
- package/maptilersdk.d.ts +2594 -9
- package/maptilersdk.js +2086 -1964
- package/maptilersdk.js.map +1 -1
- package/maptilersdk.umd.js +3 -3
- package/maptilersdk.umd.js.map +1 -1
- package/openlayers-controller.d.ts +1 -1
- package/openlayers-controller.js +62 -60
- package/openlayers-controller.js.map +1 -1
- package/openlayers-controller.umd.js +2 -2
- package/openlayers-controller.umd.js.map +1 -1
- package/openlayers.d.ts +21 -0
- package/openlayers.js +754 -786
- package/openlayers.js.map +1 -1
- package/openlayers.umd.js +3 -3
- package/openlayers.umd.js.map +1 -1
- package/package.json +18 -18
- package/react.d.ts +4 -4
- package/react.js +619 -619
- package/react.js.map +1 -1
- package/react.umd.js +1 -1
- package/react.umd.js.map +1 -1
- package/style.css +1 -1
- package/svelte/FeatureItem.svelte +1 -1
- package/svelte/FeatureItem.svelte.d.ts +2 -2
- package/svelte/GeocodingControl.svelte +31 -32
- package/svelte/GeocodingControl.svelte.d.ts +26 -13
- package/svelte/MapLibreBasedGeocodingControl.d.ts +2616 -27
- package/svelte/MapLibreBasedGeocodingControl.js +120 -17
- package/svelte/leaflet-controller.d.ts +1 -1
- package/svelte/leaflet-controller.js +4 -1
- package/svelte/leaflet.d.ts +26 -4
- package/svelte/leaflet.js +17 -19
- package/svelte/maplibregl-controller.d.ts +1 -1
- package/svelte/maplibregl-controller.js +45 -36
- package/svelte/maplibregl.d.ts +2594 -9
- package/svelte/maplibregl.js +11 -3
- package/svelte/maptilersdk.d.ts +2594 -9
- package/svelte/maptilersdk.js +11 -3
- package/svelte/openlayers-controller.d.ts +1 -1
- package/svelte/openlayers-controller.js +4 -1
- package/svelte/openlayers.d.ts +21 -0
- package/svelte/openlayers.js +30 -45
- package/svelte/react.d.ts +4 -4
- package/svelte/react.js +5 -5
- package/svelte/types.d.ts +84 -35
- package/svelte/vanilla.d.ts +14 -1
- package/svelte/vanilla.js +31 -8
- package/types.d.ts +84 -35
- package/vanilla.d.ts +14 -1
- package/vanilla.js +929 -901
- package/vanilla.js.map +1 -1
- package/vanilla.umd.js +1 -1
- package/vanilla.umd.js.map +1 -1
|
@@ -1,8 +1,75 @@
|
|
|
1
1
|
import GeocodingControlComponent from "./GeocodingControl.svelte";
|
|
2
2
|
import { createMapLibreGlMapController, } from "./maplibregl-controller";
|
|
3
3
|
export { createMapLibreGlMapController, } from "./maplibregl-controller";
|
|
4
|
-
export function
|
|
5
|
-
|
|
4
|
+
export function crateClasses(Evented, maplibreGl, getExtraProps) {
|
|
5
|
+
// NOTE We can't use Maplibre `Event` - see https://github.com/maplibre/maplibre-gl-js/issues/5015
|
|
6
|
+
class Event {
|
|
7
|
+
type;
|
|
8
|
+
target;
|
|
9
|
+
constructor(target, type) {
|
|
10
|
+
this.type = type;
|
|
11
|
+
this.target = target;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
class SelectEvent extends Event {
|
|
15
|
+
feature;
|
|
16
|
+
constructor(target, details) {
|
|
17
|
+
super(target, "select");
|
|
18
|
+
Object.assign(this, details);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
class FeaturesListedEvent extends Event {
|
|
22
|
+
features;
|
|
23
|
+
constructor(target, features) {
|
|
24
|
+
super(target, "featureslisted");
|
|
25
|
+
this.features = features;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
class FeaturesMarkedEvent extends Event {
|
|
29
|
+
features;
|
|
30
|
+
constructor(target, features) {
|
|
31
|
+
super(target, "featuresmarked");
|
|
32
|
+
this.features = features;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
class OptionsVisibilityChangeEvent extends Event {
|
|
36
|
+
optionsVisible;
|
|
37
|
+
constructor(target, optionsVisible) {
|
|
38
|
+
super(target, "optionsvisibilitychange");
|
|
39
|
+
this.optionsVisible = optionsVisible;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
class PickEvent extends Event {
|
|
43
|
+
feature;
|
|
44
|
+
constructor(target, feature) {
|
|
45
|
+
super(target, "pick");
|
|
46
|
+
this.feature = feature;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
class QueryChangeEvent extends Event {
|
|
50
|
+
query;
|
|
51
|
+
constructor(target, query) {
|
|
52
|
+
super(target, "querychange");
|
|
53
|
+
this.query = query;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
class ResponseEvent extends Event {
|
|
57
|
+
url;
|
|
58
|
+
featureCollection;
|
|
59
|
+
constructor(target, url, featureCollection) {
|
|
60
|
+
super(target, "response");
|
|
61
|
+
this.url = url;
|
|
62
|
+
this.featureCollection = featureCollection;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
class ReverseToggleEvent extends Event {
|
|
66
|
+
reverse;
|
|
67
|
+
constructor(target, reverse) {
|
|
68
|
+
super(target, "reversetoggle");
|
|
69
|
+
this.reverse = reverse;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
class MapLibreBasedGeocodingControl extends Evented {
|
|
6
73
|
#gc;
|
|
7
74
|
#options;
|
|
8
75
|
constructor(options = {}) {
|
|
@@ -27,24 +94,46 @@ export function crateBaseClass(Evented, maplibreGl, getExtraProps) {
|
|
|
27
94
|
throw new Error("no apiKey provided");
|
|
28
95
|
}
|
|
29
96
|
this.#gc = new GeocodingControlComponent({ target: div, props });
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
97
|
+
this.#gc.$on("select", (event) => {
|
|
98
|
+
this.fire(new SelectEvent(this, event.detail));
|
|
99
|
+
});
|
|
100
|
+
this.#gc.$on("pick", (event) => {
|
|
101
|
+
this.fire(new PickEvent(this, event.detail.feature));
|
|
102
|
+
});
|
|
103
|
+
this.#gc.$on("featureslisted", (event) => {
|
|
104
|
+
this.fire(new FeaturesListedEvent(this, event.detail.features));
|
|
105
|
+
});
|
|
106
|
+
this.#gc.$on("featuresmarked", (event) => {
|
|
107
|
+
this.fire(new FeaturesMarkedEvent(this, event.detail.features));
|
|
108
|
+
});
|
|
109
|
+
this.#gc.$on("response", (event) => {
|
|
110
|
+
this.fire(new ResponseEvent(this, event.detail.url, event.detail.featureCollection));
|
|
111
|
+
});
|
|
112
|
+
this.#gc.$on("optionsvisibilitychange", (event) => {
|
|
113
|
+
this.fire(new OptionsVisibilityChangeEvent(this, event.detail.optionsVisible));
|
|
114
|
+
});
|
|
115
|
+
this.#gc.$on("reversetoggle", (event) => {
|
|
116
|
+
this.fire(new ReverseToggleEvent(this, event.detail.reverse));
|
|
117
|
+
});
|
|
118
|
+
this.#gc.$on("querychange", (event) => {
|
|
119
|
+
this.fire(new QueryChangeEvent(this, event.detail.query));
|
|
120
|
+
});
|
|
44
121
|
return div;
|
|
45
122
|
}
|
|
123
|
+
on(type, listener) {
|
|
124
|
+
return super.on(type, listener);
|
|
125
|
+
}
|
|
126
|
+
once(type, listener) {
|
|
127
|
+
return super.once(type, listener);
|
|
128
|
+
}
|
|
129
|
+
off(type, listener) {
|
|
130
|
+
return super.off(type, listener);
|
|
131
|
+
}
|
|
132
|
+
listens(type) {
|
|
133
|
+
return super.listens(type);
|
|
134
|
+
}
|
|
46
135
|
setOptions(options) {
|
|
47
|
-
this.#options
|
|
136
|
+
Object.assign(this.#options, options);
|
|
48
137
|
const { marker, showResultMarkers, flyTo, fullGeometryStyle, ...restOptions } = this.#options;
|
|
49
138
|
this.#gc?.$set(restOptions);
|
|
50
139
|
}
|
|
@@ -69,5 +158,19 @@ export function crateBaseClass(Evented, maplibreGl, getExtraProps) {
|
|
|
69
158
|
onRemove() {
|
|
70
159
|
this.#gc?.$destroy();
|
|
71
160
|
}
|
|
161
|
+
}
|
|
162
|
+
const events = {
|
|
163
|
+
SelectEvent,
|
|
164
|
+
FeaturesListedEvent,
|
|
165
|
+
FeaturesMarkedEvent,
|
|
166
|
+
OptionsVisibilityChangeEvent,
|
|
167
|
+
PickEvent,
|
|
168
|
+
QueryChangeEvent,
|
|
169
|
+
ResponseEvent,
|
|
170
|
+
ReverseToggleEvent,
|
|
171
|
+
};
|
|
172
|
+
return {
|
|
173
|
+
MapLibreBasedGeocodingControl,
|
|
174
|
+
events,
|
|
72
175
|
};
|
|
73
176
|
}
|
|
@@ -6,7 +6,7 @@ export declare function createLeafletMapController(map: L.Map, marker?: boolean
|
|
|
6
6
|
fitBounds(bbox: BBox, padding: number, maxZoom?: number): void;
|
|
7
7
|
indicateReverse(reverse: boolean): void;
|
|
8
8
|
setReverseMarker(coordinates?: Position): void;
|
|
9
|
-
|
|
9
|
+
setFeatures(markedFeatures: Feature[] | undefined, picked: Feature | undefined, showPolygonMarker: boolean): void;
|
|
10
10
|
setSelectedMarker(index: number): void;
|
|
11
11
|
getCenterAndZoom(): [number, number, number];
|
|
12
12
|
};
|
|
@@ -109,7 +109,7 @@ export function createLeafletMapController(map, marker = true, showResultMarkers
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
},
|
|
112
|
-
|
|
112
|
+
setFeatures(markedFeatures, picked, showPolygonMarker) {
|
|
113
113
|
function setData(data) {
|
|
114
114
|
resultLayer.clearLayers();
|
|
115
115
|
if (data) {
|
|
@@ -177,6 +177,9 @@ export function createLeafletMapController(map, marker = true, showResultMarkers
|
|
|
177
177
|
setData(picked);
|
|
178
178
|
return; // no pin for (multi)linestrings
|
|
179
179
|
}
|
|
180
|
+
if (!showPolygonMarker && picked.geometry.type !== "Point") {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
180
183
|
if (marker instanceof Function) {
|
|
181
184
|
const m = marker(map, picked);
|
|
182
185
|
if (m) {
|
package/svelte/leaflet.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as L from "leaflet";
|
|
2
|
-
import type { ControlOptions, Feature } from "./types";
|
|
2
|
+
import type { ControlOptions, DispatcherType, Feature } from "./types";
|
|
3
3
|
export { createLeafletMapController } from "./leaflet-controller";
|
|
4
4
|
type LeafletControlOptions = ControlOptions & L.ControlOptions & {
|
|
5
5
|
/**
|
|
@@ -54,15 +54,37 @@ type LeafletControlOptions = ControlOptions & L.ControlOptions & {
|
|
|
54
54
|
*/
|
|
55
55
|
fullGeometryStyle?: null | boolean | L.PathOptions | L.StyleFunction;
|
|
56
56
|
};
|
|
57
|
+
type LeafletEvent<T> = {
|
|
58
|
+
type: T;
|
|
59
|
+
target: GeocodingControl;
|
|
60
|
+
sourceTarget: GeocodingControl;
|
|
61
|
+
};
|
|
62
|
+
type CustomEventMap = {
|
|
63
|
+
[T in keyof DispatcherType]: DispatcherType[T] & LeafletEvent<T>;
|
|
64
|
+
};
|
|
57
65
|
/**
|
|
58
66
|
* Leaflet mixins https://leafletjs.com/reference.html#class
|
|
59
67
|
* for TypeScript https://www.typescriptlang.org/docs/handbook/mixins.html
|
|
60
68
|
* @internal
|
|
61
69
|
*/
|
|
62
|
-
declare class EventedControl {
|
|
63
|
-
constructor(...args: unknown[]);
|
|
70
|
+
declare class EventedControl extends L.Control {
|
|
64
71
|
}
|
|
65
|
-
interface EventedControl extends L.Control
|
|
72
|
+
interface EventedControl extends L.Control {
|
|
73
|
+
on<T extends keyof CustomEventMap>(type: T, fn: (event: CustomEventMap[T]) => void, context?: unknown): this;
|
|
74
|
+
addEventListener<T extends keyof CustomEventMap>(type: T, fn: (event: CustomEventMap[T]) => void, context?: unknown): this;
|
|
75
|
+
once<T extends keyof CustomEventMap>(type: T, fn: (event: CustomEventMap[T]) => void, context?: unknown): this;
|
|
76
|
+
addOneTimeEventListener<T extends keyof CustomEventMap>(type: T, fn: (event: CustomEventMap[T]) => void, context?: unknown): this;
|
|
77
|
+
off<T extends keyof CustomEventMap>(type?: T, fn?: (event: CustomEventMap[T]) => void, context?: unknown): this;
|
|
78
|
+
off(eventMap?: {
|
|
79
|
+
[T in keyof CustomEventMap]?: (event: CustomEventMap[T]) => void;
|
|
80
|
+
}): this;
|
|
81
|
+
removeEventListener<T extends keyof CustomEventMap>(type?: T, fn?: (event: CustomEventMap[T]) => void, context?: unknown): this;
|
|
82
|
+
listens<T extends keyof CustomEventMap>(type: T, fn: (event: CustomEventMap[T]) => void, context?: unknown, propagate?: boolean): boolean;
|
|
83
|
+
fire(type: string, data?: unknown, propagate?: boolean): this;
|
|
84
|
+
addEventParent(obj: L.Evented): this;
|
|
85
|
+
removeEventParent(obj: L.Evented): this;
|
|
86
|
+
fireEvent(type: string, data?: unknown, propagate?: boolean): this;
|
|
87
|
+
hasEventListeners<T extends keyof CustomEventMap>(type: T): boolean;
|
|
66
88
|
}
|
|
67
89
|
export declare class GeocodingControl extends EventedControl {
|
|
68
90
|
#private;
|
package/svelte/leaflet.js
CHANGED
|
@@ -7,18 +7,15 @@ export { createLeafletMapController } from "./leaflet-controller";
|
|
|
7
7
|
* for TypeScript https://www.typescriptlang.org/docs/handbook/mixins.html
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
11
|
-
class EventedControl {
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-unused-vars
|
|
13
|
-
constructor(...args) { }
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
11
|
+
class EventedControl extends L.Control {
|
|
14
12
|
}
|
|
15
|
-
L.Util.extend(EventedControl.prototype, L.Control.prototype);
|
|
16
13
|
L.Util.extend(EventedControl.prototype, L.Evented.prototype);
|
|
17
14
|
export class GeocodingControl extends EventedControl {
|
|
18
15
|
#gc;
|
|
19
16
|
#options;
|
|
20
17
|
constructor(options) {
|
|
21
|
-
super();
|
|
18
|
+
super(options);
|
|
22
19
|
this.#options = options;
|
|
23
20
|
}
|
|
24
21
|
onAdd(map) {
|
|
@@ -26,7 +23,7 @@ export class GeocodingControl extends EventedControl {
|
|
|
26
23
|
div.className = "leaflet-ctrl-geocoder";
|
|
27
24
|
L.DomEvent.disableClickPropagation(div);
|
|
28
25
|
L.DomEvent.disableScrollPropagation(div);
|
|
29
|
-
const { marker, showResultMarkers, flyTo, fullGeometryStyle, ...restOptions } = this.#options;
|
|
26
|
+
const { marker, showResultMarkers, flyTo, fullGeometryStyle, position, ...restOptions } = this.#options;
|
|
30
27
|
const flyToOptions = typeof flyTo === "boolean" ? {} : flyTo;
|
|
31
28
|
const mapController = createLeafletMapController(map, marker, showResultMarkers, flyToOptions, flyToOptions, fullGeometryStyle);
|
|
32
29
|
this.#gc = new GeocodingControlComponent({
|
|
@@ -37,22 +34,23 @@ export class GeocodingControl extends EventedControl {
|
|
|
37
34
|
...restOptions,
|
|
38
35
|
},
|
|
39
36
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
37
|
+
const eventNames = {
|
|
38
|
+
select: undefined,
|
|
39
|
+
pick: undefined,
|
|
40
|
+
featureslisted: undefined,
|
|
41
|
+
featuresmarked: undefined,
|
|
42
|
+
response: undefined,
|
|
43
|
+
optionsvisibilitychange: undefined,
|
|
44
|
+
reversetoggle: undefined,
|
|
45
|
+
querychange: undefined,
|
|
46
|
+
};
|
|
47
|
+
for (const eventName in eventNames) {
|
|
48
|
+
this.#gc.$on(eventName, (event) => this.fire(eventName, event.detail));
|
|
51
49
|
}
|
|
52
50
|
return div;
|
|
53
51
|
}
|
|
54
52
|
setOptions(options) {
|
|
55
|
-
this.#options
|
|
53
|
+
Object.assign(this.#options, options);
|
|
56
54
|
const { marker, showResultMarkers, flyTo, fullGeometryStyle, ...restOptions } = this.#options;
|
|
57
55
|
this.#gc?.$set(restOptions);
|
|
58
56
|
}
|
|
@@ -13,7 +13,7 @@ export declare function createMapLibreGlMapController(map: Map, maplibregl?: Map
|
|
|
13
13
|
fitBounds(bbox: BBox, padding: number, maxZoom?: number): void;
|
|
14
14
|
indicateReverse(reverse: boolean): void;
|
|
15
15
|
setReverseMarker(coordinates?: Position): void;
|
|
16
|
-
|
|
16
|
+
setFeatures(markedFeatures: Feature[] | undefined, picked: Feature | undefined, showPolygonMarker: boolean): void;
|
|
17
17
|
setSelectedMarker(index: number): void;
|
|
18
18
|
getCenterAndZoom(): [number, number, number];
|
|
19
19
|
};
|
|
@@ -2,7 +2,6 @@ import { feature, featureCollection } from "@turf/helpers";
|
|
|
2
2
|
import union from "@turf/union";
|
|
3
3
|
import MarkerIcon from "./MarkerIcon.svelte";
|
|
4
4
|
import { setMask } from "./mask";
|
|
5
|
-
const emptyGeojson = featureCollection([]);
|
|
6
5
|
const defaultGeometryStyle = {
|
|
7
6
|
fill: {
|
|
8
7
|
paint: {
|
|
@@ -23,55 +22,69 @@ const defaultGeometryStyle = {
|
|
|
23
22
|
filter: ["!", ["has", "isMask"]],
|
|
24
23
|
},
|
|
25
24
|
};
|
|
25
|
+
const RESULT_SOURCE = "mtlr-gc-full-geom";
|
|
26
|
+
const RESULT_LAYER_FILL = "mtlr-gc-full-geom-fill";
|
|
27
|
+
const RESULT_LAYER_LINE = "mtlr-gc-full-geom-line";
|
|
26
28
|
export function createMapLibreGlMapController(map, maplibregl, marker = true, showResultMarkers = true, flyToOptions = {}, fitBoundsOptions = {}, fullGeometryStyle = defaultGeometryStyle) {
|
|
27
29
|
let eventHandler;
|
|
28
30
|
const markers = [];
|
|
29
31
|
let selectedMarker;
|
|
30
32
|
let reverseMarker;
|
|
31
33
|
let savedData; // used to restore features on style switch
|
|
32
|
-
function
|
|
34
|
+
function syncFullGeometryLayer() {
|
|
35
|
+
if (!map.loaded) {
|
|
36
|
+
map.once("load", syncFullGeometryLayer);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
33
39
|
const effFullGeometryStyle = !fullGeometryStyle
|
|
34
40
|
? undefined
|
|
35
41
|
: fullGeometryStyle === true
|
|
36
42
|
? defaultGeometryStyle
|
|
37
43
|
: fullGeometryStyle;
|
|
38
|
-
if (!
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
if (!effFullGeometryStyle?.fill && !effFullGeometryStyle?.line) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const source = map.getSource(RESULT_SOURCE);
|
|
48
|
+
if (source) {
|
|
49
|
+
source.setData(savedData ?? featureCollection([]));
|
|
50
|
+
}
|
|
51
|
+
else if (savedData) {
|
|
52
|
+
map.addSource(RESULT_SOURCE, {
|
|
41
53
|
type: "geojson",
|
|
42
|
-
data:
|
|
54
|
+
data: savedData,
|
|
43
55
|
});
|
|
44
56
|
}
|
|
45
|
-
|
|
57
|
+
else {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (!map.getLayer(RESULT_LAYER_FILL) && effFullGeometryStyle?.fill) {
|
|
46
61
|
map.addLayer({
|
|
47
62
|
...effFullGeometryStyle?.fill,
|
|
48
|
-
id:
|
|
63
|
+
id: RESULT_LAYER_FILL,
|
|
49
64
|
type: "fill",
|
|
50
|
-
source:
|
|
65
|
+
source: RESULT_SOURCE,
|
|
51
66
|
});
|
|
52
67
|
}
|
|
53
|
-
if (!map.getLayer(
|
|
68
|
+
if (!map.getLayer(RESULT_LAYER_LINE) && effFullGeometryStyle?.line) {
|
|
54
69
|
map.addLayer({
|
|
55
70
|
...effFullGeometryStyle?.line,
|
|
56
|
-
id:
|
|
71
|
+
id: RESULT_LAYER_LINE,
|
|
57
72
|
type: "line",
|
|
58
|
-
source:
|
|
73
|
+
source: RESULT_SOURCE,
|
|
59
74
|
});
|
|
60
75
|
}
|
|
61
|
-
if (savedData) {
|
|
62
|
-
setData(savedData);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (map.loaded()) {
|
|
66
|
-
addFullGeometryLayer();
|
|
67
76
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
});
|
|
77
|
+
function setAndSaveData(data) {
|
|
78
|
+
savedData = data;
|
|
79
|
+
syncFullGeometryLayer();
|
|
72
80
|
}
|
|
73
81
|
map.on("styledata", () => {
|
|
74
|
-
|
|
82
|
+
// timeout prevents collision with svelte-maplibre library
|
|
83
|
+
setTimeout(() => {
|
|
84
|
+
if (savedData) {
|
|
85
|
+
syncFullGeometryLayer();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
75
88
|
});
|
|
76
89
|
const handleMapClick = (e) => {
|
|
77
90
|
eventHandler?.({
|
|
@@ -93,13 +106,6 @@ export function createMapLibreGlMapController(map, maplibregl, marker = true, sh
|
|
|
93
106
|
});
|
|
94
107
|
return new maplibregl.Marker({ element, offset: [1, -13] });
|
|
95
108
|
}
|
|
96
|
-
function setData(data) {
|
|
97
|
-
savedData = data;
|
|
98
|
-
if (!data) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
map.getSource("full-geom")?.setData(data);
|
|
102
|
-
}
|
|
103
109
|
return {
|
|
104
110
|
setEventHandler(handler) {
|
|
105
111
|
if (handler) {
|
|
@@ -150,12 +156,12 @@ export function createMapLibreGlMapController(map, maplibregl, marker = true, sh
|
|
|
150
156
|
}
|
|
151
157
|
}
|
|
152
158
|
},
|
|
153
|
-
|
|
159
|
+
setFeatures(markedFeatures, picked, showPolygonMarker) {
|
|
154
160
|
for (const marker of markers) {
|
|
155
161
|
marker.remove();
|
|
156
162
|
}
|
|
157
163
|
markers.length = 0;
|
|
158
|
-
|
|
164
|
+
setAndSaveData(undefined);
|
|
159
165
|
if (!maplibregl) {
|
|
160
166
|
return;
|
|
161
167
|
}
|
|
@@ -171,14 +177,14 @@ export function createMapLibreGlMapController(map, maplibregl, marker = true, sh
|
|
|
171
177
|
setMask({
|
|
172
178
|
...picked,
|
|
173
179
|
geometry: unioned.geometry,
|
|
174
|
-
},
|
|
180
|
+
}, setAndSaveData);
|
|
175
181
|
handled = true;
|
|
176
182
|
}
|
|
177
183
|
else {
|
|
178
184
|
const geometries = picked.geometry.geometries.filter((geometry) => geometry.type === "LineString" ||
|
|
179
185
|
geometry.type === "MultiLineString");
|
|
180
186
|
if (geometries.length > 0) {
|
|
181
|
-
|
|
187
|
+
setAndSaveData({
|
|
182
188
|
...picked,
|
|
183
189
|
geometry: { type: "GeometryCollection", geometries },
|
|
184
190
|
});
|
|
@@ -191,13 +197,16 @@ export function createMapLibreGlMapController(map, maplibregl, marker = true, sh
|
|
|
191
197
|
}
|
|
192
198
|
else if (picked.geometry.type === "Polygon" ||
|
|
193
199
|
picked.geometry.type === "MultiPolygon") {
|
|
194
|
-
setMask(picked,
|
|
200
|
+
setMask(picked, setAndSaveData);
|
|
195
201
|
}
|
|
196
202
|
else if (picked.geometry.type === "LineString" ||
|
|
197
203
|
picked.geometry.type === "MultiLineString") {
|
|
198
|
-
|
|
204
|
+
setAndSaveData(picked);
|
|
199
205
|
return; // no pin for (multi)linestrings
|
|
200
206
|
}
|
|
207
|
+
if (!showPolygonMarker && picked.geometry.type !== "Point") {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
201
210
|
if (marker instanceof Function) {
|
|
202
211
|
const m = marker(map, picked);
|
|
203
212
|
if (m) {
|