@emuanalytics/flow-rdf-core 4.0.3 → 4.0.5
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/README.md +1 -64
- package/dist/index.d.mts +36 -31
- package/dist/index.d.ts +36 -31
- package/dist/index.mjs +20 -3249
- package/dist/lib/context/context-registry.mjs +63 -0
- package/dist/lib/context/debugger.mjs +240 -0
- package/dist/lib/context/flow-context.mjs +61 -0
- package/dist/lib/context/global-state.mjs +70 -0
- package/dist/lib/context/map-registry.mjs +59 -0
- package/dist/lib/context/query-registry.mjs +53 -0
- package/dist/lib/errors/flow-error.mjs +10 -0
- package/dist/lib/errors/flow-expression-error.mjs +14 -0
- package/dist/lib/errors/flow-map-error.mjs +9 -0
- package/dist/lib/expressions/expression-parser.mjs +198 -0
- package/dist/lib/expressions/functions/from-palette.mjs +75 -0
- package/dist/lib/expressions/functions/regex.mjs +25 -0
- package/dist/lib/expressions/functions/state.mjs +25 -0
- package/dist/lib/expressions/parser-helpers.mjs +37 -0
- package/dist/lib/expressions/reactive-expression.mjs +253 -0
- package/dist/lib/map/flow-core-map.mjs +749 -0
- package/dist/lib/map/plugins/annotations/annotation-layers.mjs +163 -0
- package/dist/lib/map/plugins/annotations/annotation.events.mjs +27 -0
- package/dist/lib/map/plugins/annotations/annotation.plugin.mjs +498 -0
- package/dist/lib/map/plugins/annotations/maplibre-gl-draw-circle/lib/modes/DirectModeOverride.mjs +67 -0
- package/dist/lib/map/plugins/annotations/maplibre-gl-draw-circle/lib/modes/DragCircleMode.mjs +65 -0
- package/dist/lib/map/plugins/annotations/maplibre-gl-draw-circle/lib/utils/create_supplementary_points_circle.mjs +15 -0
- package/dist/lib/map/plugins/annotations/maplibre-gl-draw-circle/lib/utils/drag_pan.mjs +20 -0
- package/dist/lib/map/plugins/data-join.plugin.mjs +173 -0
- package/dist/lib/map/plugins/export/export.plugin.mjs +21 -0
- package/dist/lib/map/plugins/export/map-exporter.mjs +177 -0
- package/dist/lib/map/plugins/hover-effect.plugin.mjs +58 -0
- package/dist/lib/map/plugins/index.d.mts +37 -72
- package/dist/lib/map/plugins/index.d.ts +37 -72
- package/dist/lib/map/plugins/index.mjs +11 -1811
- package/dist/lib/map/plugins/keyboard-shortcut-manager.mjs +120 -0
- package/dist/lib/map/plugins/map-plugin-base.mjs +25 -0
- package/dist/lib/map/plugins/plugin-manager.mjs +135 -0
- package/dist/lib/map/plugins/popup.plugin.mjs +55 -0
- package/dist/lib/map/plugins/selection/selection.events.mjs +21 -0
- package/dist/lib/map/plugins/selection/selection.plugin.mjs +136 -0
- package/dist/lib/map/plugins/selection/source-selection.mjs +156 -0
- package/dist/lib/map/plugins/url-sync.plugin.mjs +55 -0
- package/dist/lib/map/support/image-registry.mjs +82 -0
- package/dist/lib/map/support/map-events.mjs +71 -0
- package/dist/lib/map/support/map-feature-stream.mjs +158 -0
- package/dist/lib/map/support/map-popup.mjs +159 -0
- package/dist/lib/map/types.mjs +7 -0
- package/dist/lib/map-style/map-data-source.mjs +192 -0
- package/dist/lib/map-style/map-layer-style-builder-generated.mjs +1307 -0
- package/dist/lib/map-style/map-layer-style-builder.mjs +86 -0
- package/dist/lib/map-style/map-layer.mjs +223 -0
- package/dist/lib/map-style/map-style.mjs +178 -0
- package/dist/lib/queries/async-committer.mjs +30 -0
- package/dist/lib/queries/query.mjs +172 -0
- package/dist/lib/state-store/decorators.mjs +83 -0
- package/dist/lib/state-store/state-store.mjs +534 -0
- package/dist/lib/state-store/utils.mjs +7 -0
- package/dist/lib/utils/announce.mjs +12 -0
- package/dist/lib/utils/assert.mjs +12 -0
- package/dist/{shared/flow-rdf-core.187cb345.mjs → lib/utils/debounce.mjs} +3 -39
- package/dist/lib/utils/decorators.mjs +59 -0
- package/dist/lib/utils/deferred.mjs +11 -0
- package/dist/lib/utils/ensure-array.mjs +16 -0
- package/dist/{shared/flow-rdf-core.1f0901c5.mjs → lib/utils/feature-type-checks.mjs} +2 -2
- package/dist/lib/utils/functional.mjs +22 -0
- package/dist/lib/utils/global.mjs +18 -0
- package/dist/lib/utils/index.mjs +8 -5
- package/dist/lib/utils/random-id.mjs +9 -0
- package/dist/lib/utils/string-utils.mjs +3 -0
- package/dist/lib/utils/throttle.mjs +20 -0
- package/dist/{shared/flow-rdf-core.25e5f6d7.mjs → lib/utils/type-checks.mjs} +1 -26
- package/dist/lib/utils/watchable-promise.mjs +55 -0
- package/dist/package.json.mjs +3 -0
- package/dist/shared/{flow-rdf-core.4dde996e.d.cts → flow-rdf-core.8b5acf14.d.mts} +1315 -172
- package/dist/shared/{flow-rdf-core.4dde996e.d.ts → flow-rdf-core.8b5acf14.d.ts} +1315 -172
- package/package.json +4 -8
- package/dist/index.cjs +0 -3316
- package/dist/index.d.cts +0 -90
- package/dist/lib/map/plugins/index.cjs +0 -1851
- package/dist/lib/map/plugins/index.d.cts +0 -345
- package/dist/lib/utils/index.cjs +0 -48
- package/dist/lib/utils/index.d.cts +0 -160
- package/dist/shared/flow-rdf-core.06e85a6c.cjs +0 -1394
- package/dist/shared/flow-rdf-core.4dde996e.d.mts +0 -1916
- package/dist/shared/flow-rdf-core.55c169ca.cjs +0 -150
- package/dist/shared/flow-rdf-core.63162669.d.cts +0 -10
- package/dist/shared/flow-rdf-core.65045caf.mjs +0 -1360
- package/dist/shared/flow-rdf-core.a82b9be4.cjs +0 -34
- package/dist/shared/flow-rdf-core.f50908f0.cjs +0 -102
|
@@ -1,1811 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import EventEmitter$1, { EventEmitter } from 'eventemitter3';
|
|
13
|
-
import maplibre from '@emuanalytics/maplibre-gl';
|
|
14
|
-
import * as lit from 'lit-html';
|
|
15
|
-
import turfCircle from '@turf/circle';
|
|
16
|
-
import turfDistance from '@turf/distance';
|
|
17
|
-
import { point } from '@turf/helpers';
|
|
18
|
-
import { autorun, toJS } from 'mobx';
|
|
19
|
-
import saveAs from 'file-saver';
|
|
20
|
-
// import '@emuanalytics/maplibre-gl-style-spec';
|
|
21
|
-
// import 'mobx-utils';
|
|
22
|
-
import 'parsimmon';
|
|
23
|
-
import 'colorbrewer';
|
|
24
|
-
import '@turf/invariant';
|
|
25
|
-
// import 'nanoid';
|
|
26
|
-
|
|
27
|
-
var __defProp$c = Object.defineProperty;
|
|
28
|
-
var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
29
|
-
var __publicField$c = (obj, key, value) => {
|
|
30
|
-
__defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
31
|
-
return value;
|
|
32
|
-
};
|
|
33
|
-
class AnnotationEvent extends MapEvent {
|
|
34
|
-
constructor(type, map, data) {
|
|
35
|
-
super(type, map);
|
|
36
|
-
__publicField$c(this, "mode");
|
|
37
|
-
__publicField$c(this, "canUndo");
|
|
38
|
-
__publicField$c(this, "canRedo");
|
|
39
|
-
__publicField$c(this, "activeFeatureId");
|
|
40
|
-
__publicField$c(this, "activeFeatureType");
|
|
41
|
-
__publicField$c(this, "features");
|
|
42
|
-
this.mode = data.mode;
|
|
43
|
-
this.canUndo = data.canUndo;
|
|
44
|
-
this.canRedo = data.canRedo;
|
|
45
|
-
this.activeFeatureId = data.activeFeatureId;
|
|
46
|
-
this.activeFeatureType = data.activeFeatureType;
|
|
47
|
-
this.features = data.features;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
var __defProp$b = Object.defineProperty;
|
|
52
|
-
var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
53
|
-
var __publicField$b = (obj, key, value) => {
|
|
54
|
-
__defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
55
|
-
return value;
|
|
56
|
-
};
|
|
57
|
-
class MapPluginBase extends EventEmitter {
|
|
58
|
-
constructor(pluginManager, options) {
|
|
59
|
-
super();
|
|
60
|
-
__publicField$b(this, "_pluginManager");
|
|
61
|
-
__publicField$b(this, "options");
|
|
62
|
-
this._pluginManager = pluginManager;
|
|
63
|
-
this.options = options ?? {};
|
|
64
|
-
}
|
|
65
|
-
get map() {
|
|
66
|
-
return this._pluginManager.map;
|
|
67
|
-
}
|
|
68
|
-
get pluginManager() {
|
|
69
|
-
return this._pluginManager;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function isFeatureWithId(f) {
|
|
74
|
-
return isDefined(f) && isDefined(f.source) && isDefined(f.id);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
var __defProp$a = Object.defineProperty;
|
|
78
|
-
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
79
|
-
var __publicField$a = (obj, key, value) => {
|
|
80
|
-
__defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
81
|
-
return value;
|
|
82
|
-
};
|
|
83
|
-
Debug("flow:map-popup");
|
|
84
|
-
class MapPopup extends EventEmitter$1 {
|
|
85
|
-
/**
|
|
86
|
-
* Constructs a new `MapPopup` instance.
|
|
87
|
-
*
|
|
88
|
-
* This is called by the `FlowMap::openPopup` method.
|
|
89
|
-
*
|
|
90
|
-
* @param map Parent Flo.w map.
|
|
91
|
-
* @param options Popup options.
|
|
92
|
-
*/
|
|
93
|
-
constructor(map, options) {
|
|
94
|
-
super();
|
|
95
|
-
this.map = map;
|
|
96
|
-
this.options = options;
|
|
97
|
-
__publicField$a(this, "_feature");
|
|
98
|
-
__publicField$a(this, "_contentContainer");
|
|
99
|
-
__publicField$a(this, "_featureStream", null);
|
|
100
|
-
//private _featureStreamSubscription: ISubscription | null = null;
|
|
101
|
-
__publicField$a(this, "_maplibrePopup", null);
|
|
102
|
-
__publicField$a(this, "_featureStreamDisposer");
|
|
103
|
-
this.options = {
|
|
104
|
-
// Defaults
|
|
105
|
-
closeButton: true,
|
|
106
|
-
closeOnClick: false,
|
|
107
|
-
closeOnMove: false,
|
|
108
|
-
maxWidth: "300px",
|
|
109
|
-
trackFeature: true,
|
|
110
|
-
//
|
|
111
|
-
...this.options
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
get feature() {
|
|
115
|
-
return this._feature;
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Close the popup.
|
|
119
|
-
*/
|
|
120
|
-
close() {
|
|
121
|
-
if (this._maplibrePopup) {
|
|
122
|
-
this._maplibrePopup.remove();
|
|
123
|
-
this._maplibrePopup = null;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Move the popup to a new location.
|
|
128
|
-
*
|
|
129
|
-
* @param lngLat New location.
|
|
130
|
-
*/
|
|
131
|
-
moveTo(lngLat) {
|
|
132
|
-
this._maplibrePopup.setLngLat(lngLat);
|
|
133
|
-
}
|
|
134
|
-
open(eventOrLngLat, feature) {
|
|
135
|
-
if (this._maplibrePopup) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
if (!isArray(eventOrLngLat)) {
|
|
139
|
-
if (isFeatureWithId(eventOrLngLat.features[0])) {
|
|
140
|
-
feature = eventOrLngLat.features[0];
|
|
141
|
-
}
|
|
142
|
-
eventOrLngLat = eventOrLngLat.lngLat;
|
|
143
|
-
}
|
|
144
|
-
if (feature) {
|
|
145
|
-
assert(isFeatureWithId(feature), "MapPopup.open(): feature must have unique ID");
|
|
146
|
-
}
|
|
147
|
-
this._maplibrePopup = new maplibre.Popup({
|
|
148
|
-
className: this.cssClasses().join(" "),
|
|
149
|
-
closeButton: this.options.closeButton,
|
|
150
|
-
closeOnClick: this.options.closeOnClick,
|
|
151
|
-
closeOnMove: this.options.closeOnMove,
|
|
152
|
-
maxWidth: this.options.maxWidth
|
|
153
|
-
});
|
|
154
|
-
this._maplibrePopup.once("close", this.popupCloseHandler.bind(this));
|
|
155
|
-
this._contentContainer = document.createElement("div");
|
|
156
|
-
this._contentContainer.classList.add("flow-map-popup-content");
|
|
157
|
-
this._maplibrePopup.setDOMContent(this._contentContainer);
|
|
158
|
-
this._maplibrePopup.addTo(this.map.maplibreMap);
|
|
159
|
-
if (feature) {
|
|
160
|
-
this._feature = feature;
|
|
161
|
-
this._featureStream = new MapFeatureStream({
|
|
162
|
-
map: this.map,
|
|
163
|
-
source: feature.source,
|
|
164
|
-
sourceLayer: feature.sourceLayer,
|
|
165
|
-
featureIds: [feature.id]
|
|
166
|
-
});
|
|
167
|
-
this._featureStreamDisposer = this.map.context.state.autorun(() => {
|
|
168
|
-
const data = this._featureStream?.featureData;
|
|
169
|
-
if (data) {
|
|
170
|
-
this.handleFeatureUpdate(data[feature.id]);
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
} else {
|
|
174
|
-
this.moveTo(eventOrLngLat);
|
|
175
|
-
this.renderContent(null);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
cssClasses() {
|
|
179
|
-
const classes = ["flow-map-popup"];
|
|
180
|
-
if (isStringFull(this.options.class)) {
|
|
181
|
-
classes.push(this.options.class);
|
|
182
|
-
}
|
|
183
|
-
if (this.options.closeButton) {
|
|
184
|
-
classes.push("flow-map-popup--with-close");
|
|
185
|
-
}
|
|
186
|
-
return classes;
|
|
187
|
-
}
|
|
188
|
-
handleFeatureUpdate(feature) {
|
|
189
|
-
if (!feature) {
|
|
190
|
-
this.close();
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
if (this.options.trackFeature) {
|
|
194
|
-
switch (feature.geometry.type) {
|
|
195
|
-
case "Point":
|
|
196
|
-
this.moveTo(feature.geometry.coordinates);
|
|
197
|
-
break;
|
|
198
|
-
case "MultiPoint":
|
|
199
|
-
this.moveTo(feature.geometry.coordinates[0]);
|
|
200
|
-
break;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
this.renderContent(feature);
|
|
204
|
-
}
|
|
205
|
-
popupCloseHandler() {
|
|
206
|
-
if (this._featureStreamDisposer) {
|
|
207
|
-
this._featureStreamDisposer();
|
|
208
|
-
this._featureStreamDisposer = void 0;
|
|
209
|
-
}
|
|
210
|
-
this.emit("closed", this);
|
|
211
|
-
this.removeAllListeners();
|
|
212
|
-
}
|
|
213
|
-
renderContent(feature) {
|
|
214
|
-
const state = this.map.context.state;
|
|
215
|
-
const content = isFunction(this.options.content) ? this.options.content(feature, state) : this.options.content;
|
|
216
|
-
if (isString(content)) {
|
|
217
|
-
this._contentContainer.innerHTML = content;
|
|
218
|
-
} else if (content instanceof Node) {
|
|
219
|
-
this._contentContainer.innerHTML = "";
|
|
220
|
-
this._contentContainer.appendChild(content);
|
|
221
|
-
} else {
|
|
222
|
-
lit.render(content, this._contentContainer);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
var __defProp$9 = Object.defineProperty;
|
|
228
|
-
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
229
|
-
var __publicField$9 = (obj, key, value) => {
|
|
230
|
-
__defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
231
|
-
return value;
|
|
232
|
-
};
|
|
233
|
-
class PopupPlugin extends MapPluginBase {
|
|
234
|
-
constructor(pluginManager) {
|
|
235
|
-
super(pluginManager);
|
|
236
|
-
__publicField$9(this, "_popupTemplates", /* @__PURE__ */ new Map());
|
|
237
|
-
__publicField$9(this, "_popups", /* @__PURE__ */ new Set());
|
|
238
|
-
__publicField$9(this, "name", "PopupPlugin");
|
|
239
|
-
}
|
|
240
|
-
registerPopup(id, options) {
|
|
241
|
-
this._popupTemplates.set(id, options);
|
|
242
|
-
}
|
|
243
|
-
openPopup(id, eventOrLngLat, feature) {
|
|
244
|
-
const popupOptions = this._popupTemplates.get(id);
|
|
245
|
-
if (!popupOptions) {
|
|
246
|
-
throw new FlowError(`MapPopup: no popup with id '${id}'`);
|
|
247
|
-
}
|
|
248
|
-
const popup = new MapPopup(this.map, popupOptions);
|
|
249
|
-
this._popups.add(popup);
|
|
250
|
-
popup.once("closed", () => {
|
|
251
|
-
this._popups.delete(popup);
|
|
252
|
-
});
|
|
253
|
-
if (isArray(eventOrLngLat)) {
|
|
254
|
-
popup.open(eventOrLngLat, feature);
|
|
255
|
-
} else {
|
|
256
|
-
popup.open(eventOrLngLat);
|
|
257
|
-
}
|
|
258
|
-
return popup;
|
|
259
|
-
}
|
|
260
|
-
closeAllPopups() {
|
|
261
|
-
this._popups.forEach((popup) => popup.close());
|
|
262
|
-
this._popups.clear();
|
|
263
|
-
}
|
|
264
|
-
closePopupsForSources(sources) {
|
|
265
|
-
sources = ensureArray(sources);
|
|
266
|
-
this._popups.forEach((popup) => {
|
|
267
|
-
if (popup.feature?.source && sources.indexOf(popup.feature?.source) >= 0) {
|
|
268
|
-
popup.close();
|
|
269
|
-
this._popups.delete(popup);
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
var __defProp$8 = Object.defineProperty;
|
|
276
|
-
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
277
|
-
var __publicField$8 = (obj, key, value) => {
|
|
278
|
-
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
279
|
-
return value;
|
|
280
|
-
};
|
|
281
|
-
class SelectionEvent extends MapEvent {
|
|
282
|
-
constructor(type, map, sourceIdentifier, features) {
|
|
283
|
-
super(type, map);
|
|
284
|
-
__publicField$8(this, "source");
|
|
285
|
-
__publicField$8(this, "sourceLayer");
|
|
286
|
-
__publicField$8(this, "features");
|
|
287
|
-
this.source = sourceIdentifier.source;
|
|
288
|
-
this.sourceLayer = sourceIdentifier.sourceLayer;
|
|
289
|
-
this.features = features;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
var __defProp$7 = Object.defineProperty;
|
|
294
|
-
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
295
|
-
var __publicField$7 = (obj, key, value) => {
|
|
296
|
-
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
297
|
-
return value;
|
|
298
|
-
};
|
|
299
|
-
class SourceSelection {
|
|
300
|
-
constructor(plugin, source, options) {
|
|
301
|
-
__publicField$7(this, "_featureStream");
|
|
302
|
-
__publicField$7(this, "_map");
|
|
303
|
-
__publicField$7(this, "_options");
|
|
304
|
-
__publicField$7(this, "_plugin");
|
|
305
|
-
__publicField$7(this, "_popups", /* @__PURE__ */ new Map());
|
|
306
|
-
__publicField$7(this, "_selectedFeatureIds", /* @__PURE__ */ new Set());
|
|
307
|
-
__publicField$7(this, "_sourceId");
|
|
308
|
-
__publicField$7(this, "_stateSubscription", null);
|
|
309
|
-
this._plugin = plugin;
|
|
310
|
-
this._map = plugin.map;
|
|
311
|
-
this._options = options;
|
|
312
|
-
const sourceType = plugin.map.getSource(source).type;
|
|
313
|
-
this._sourceId = {
|
|
314
|
-
source,
|
|
315
|
-
sourceLayer: sourceType === "vector" ? options.sourceLayer ?? "geometry" : void 0
|
|
316
|
-
};
|
|
317
|
-
this._featureStream = this._map.featureStream({
|
|
318
|
-
source,
|
|
319
|
-
sourceLayer: options.sourceLayer,
|
|
320
|
-
featureIds: []
|
|
321
|
-
});
|
|
322
|
-
if (options.selectionState) {
|
|
323
|
-
this._stateSubscription = this._map.context.state.toStream(options.selectionState, true).subscribe((val) => {
|
|
324
|
-
val = new Set(ensureArray(val));
|
|
325
|
-
this.updateSelection(val);
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
get options() {
|
|
330
|
-
return this._options;
|
|
331
|
-
}
|
|
332
|
-
get selectedFeatureIds() {
|
|
333
|
-
return this._selectedFeatureIds;
|
|
334
|
-
}
|
|
335
|
-
get selectedFeatureStream() {
|
|
336
|
-
return this._featureStream;
|
|
337
|
-
}
|
|
338
|
-
destroy() {
|
|
339
|
-
this._popups.forEach((popup) => popup.close());
|
|
340
|
-
this._stateSubscription?.unsubscribe();
|
|
341
|
-
this._selectedFeatureIds = /* @__PURE__ */ new Set();
|
|
342
|
-
this.updateMapSelectionState();
|
|
343
|
-
}
|
|
344
|
-
handleClick(lngLat, feature, selectionOptions, multiSelect, enablePopups) {
|
|
345
|
-
if (this._options.mode === "none") {
|
|
346
|
-
return;
|
|
347
|
-
}
|
|
348
|
-
const selectedFeatureIDs = new Set(this._selectedFeatureIds);
|
|
349
|
-
let clearSelection = false;
|
|
350
|
-
let toggleFeature = false;
|
|
351
|
-
let showPopup = false;
|
|
352
|
-
if (feature && feature.source === this._sourceId.source) {
|
|
353
|
-
if (this._options.mode === "single") {
|
|
354
|
-
if (selectedFeatureIDs.has(feature.id)) {
|
|
355
|
-
toggleFeature = true;
|
|
356
|
-
} else {
|
|
357
|
-
clearSelection = true;
|
|
358
|
-
toggleFeature = true;
|
|
359
|
-
}
|
|
360
|
-
} else {
|
|
361
|
-
if (!multiSelect) {
|
|
362
|
-
clearSelection = true;
|
|
363
|
-
}
|
|
364
|
-
toggleFeature = true;
|
|
365
|
-
}
|
|
366
|
-
} else if (feature && feature.source !== this._sourceId.source) {
|
|
367
|
-
clearSelection = this._options.clear === "group" ? selectionOptions?.group === this._options.group : !!this._options.clear;
|
|
368
|
-
} else {
|
|
369
|
-
clearSelection = !multiSelect;
|
|
370
|
-
}
|
|
371
|
-
if (clearSelection) {
|
|
372
|
-
selectedFeatureIDs.clear();
|
|
373
|
-
}
|
|
374
|
-
if (toggleFeature) {
|
|
375
|
-
assert(isFeatureWithId(feature));
|
|
376
|
-
if (selectedFeatureIDs.has(feature.id) && multiSelect) {
|
|
377
|
-
selectedFeatureIDs.delete(feature.id);
|
|
378
|
-
if (this._popups.has(feature.id))
|
|
379
|
-
this._popups.get(feature.id).close();
|
|
380
|
-
} else {
|
|
381
|
-
selectedFeatureIDs.add(feature.id);
|
|
382
|
-
showPopup = true;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
this.updateSelection(selectedFeatureIDs);
|
|
386
|
-
if (enablePopups && showPopup && this._options.popup) {
|
|
387
|
-
assert(isFeatureWithId(feature));
|
|
388
|
-
if (!this._popups.has(feature.id)) {
|
|
389
|
-
const popup = this._map.getPlugin(PopupPlugin).openPopup(this._options.popup, lngLat, feature);
|
|
390
|
-
if (popup) {
|
|
391
|
-
popup.on("closed", () => {
|
|
392
|
-
this._popups.delete(feature.id);
|
|
393
|
-
});
|
|
394
|
-
this._popups.set(feature.id, popup);
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
updateSelection(featureIds) {
|
|
400
|
-
if (!this.areSetsEqual(featureIds, this._selectedFeatureIds)) {
|
|
401
|
-
this._selectedFeatureIds = featureIds;
|
|
402
|
-
this.updateMapSelectionState();
|
|
403
|
-
this.updateStateStore();
|
|
404
|
-
this._featureStream.featureIds = Array.from(featureIds);
|
|
405
|
-
this._popups.forEach((popup) => {
|
|
406
|
-
assert(isFeatureWithId(popup.feature));
|
|
407
|
-
if (popup.feature.id && !featureIds.has(popup.feature.id)) {
|
|
408
|
-
popup.close();
|
|
409
|
-
}
|
|
410
|
-
});
|
|
411
|
-
const event = new SelectionEvent(
|
|
412
|
-
"selectionChanged",
|
|
413
|
-
this._map,
|
|
414
|
-
this._sourceId,
|
|
415
|
-
Array.from(this._selectedFeatureIds)
|
|
416
|
-
);
|
|
417
|
-
this._plugin.emit(event.type, event);
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
areSetsEqual(a, b) {
|
|
421
|
-
return a.size === b.size && [...a].every((value) => b.has(value));
|
|
422
|
-
}
|
|
423
|
-
updateMapSelectionState() {
|
|
424
|
-
this._map.removeFeatureState(this._sourceId, "selected", false);
|
|
425
|
-
this._selectedFeatureIds.forEach(
|
|
426
|
-
(id) => this._map.setFeatureState({ ...this._sourceId, id }, { selected: true }, false)
|
|
427
|
-
);
|
|
428
|
-
}
|
|
429
|
-
updateStateStore() {
|
|
430
|
-
if (isStringFull(this._options.selectionState)) {
|
|
431
|
-
const selectedIds = Array.from(this._selectedFeatureIds);
|
|
432
|
-
if (this._options.mode === "single") {
|
|
433
|
-
this._map.context.state.set(this._options.selectionState, selectedIds[0]);
|
|
434
|
-
} else if (this._options.mode === "multi") {
|
|
435
|
-
this._map.context.state.set(this._options.selectionState, selectedIds);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
var __defProp$6 = Object.defineProperty;
|
|
442
|
-
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
443
|
-
var __publicField$6 = (obj, key, value) => {
|
|
444
|
-
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
445
|
-
return value;
|
|
446
|
-
};
|
|
447
|
-
class SelectionPlugin extends MapPluginBase {
|
|
448
|
-
constructor(pluginManager) {
|
|
449
|
-
super(pluginManager);
|
|
450
|
-
__publicField$6(this, "_sourceSelections", /* @__PURE__ */ new Map());
|
|
451
|
-
__publicField$6(this, "_enablePopups", true);
|
|
452
|
-
__publicField$6(this, "name", "SelectionPlugin");
|
|
453
|
-
}
|
|
454
|
-
clearSelection(source) {
|
|
455
|
-
const sourceSelection = this._sourceSelections.get(source);
|
|
456
|
-
if (!sourceSelection) {
|
|
457
|
-
return;
|
|
458
|
-
}
|
|
459
|
-
switch (sourceSelection.options.mode) {
|
|
460
|
-
case "single":
|
|
461
|
-
case "multi":
|
|
462
|
-
sourceSelection.updateSelection(/* @__PURE__ */ new Set());
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
deselectFeatures(source, features) {
|
|
466
|
-
const sourceSelection = this._sourceSelections.get(source);
|
|
467
|
-
if (!sourceSelection) {
|
|
468
|
-
return;
|
|
469
|
-
}
|
|
470
|
-
features = ensureArray(features);
|
|
471
|
-
const currentSelection = new Set(sourceSelection.selectedFeatureIds);
|
|
472
|
-
switch (sourceSelection.options.mode) {
|
|
473
|
-
case "single":
|
|
474
|
-
case "multi":
|
|
475
|
-
features.forEach((f) => currentSelection.delete(f));
|
|
476
|
-
sourceSelection.updateSelection(currentSelection);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
destroy() {
|
|
480
|
-
this._sourceSelections.forEach((sel) => sel.destroy());
|
|
481
|
-
this._sourceSelections.clear();
|
|
482
|
-
}
|
|
483
|
-
disableSelection(source) {
|
|
484
|
-
if (this._sourceSelections.has(source)) {
|
|
485
|
-
this._sourceSelections.get(source).destroy();
|
|
486
|
-
this._sourceSelections.delete(source);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
enableSelection(source, options) {
|
|
490
|
-
if (options.popup) {
|
|
491
|
-
try {
|
|
492
|
-
this.map.getPlugin(PopupPlugin);
|
|
493
|
-
} catch (e) {
|
|
494
|
-
throw new FlowMapError(`enableSelection(): Popup plugin is required for automatic selection popups`);
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
this.disableSelection(source);
|
|
498
|
-
this._sourceSelections.set(source, new SourceSelection(this, source, options));
|
|
499
|
-
}
|
|
500
|
-
handleBeforeSourceRemoved(event) {
|
|
501
|
-
if (this._sourceSelections.has(event.source)) {
|
|
502
|
-
this._sourceSelections.get(event.source)?.destroy();
|
|
503
|
-
this._sourceSelections.delete(event.source);
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
handleClick(event) {
|
|
507
|
-
const multiSelect = event.originalEvent.shiftKey || event.originalEvent.altKey || event.originalEvent.metaKey;
|
|
508
|
-
const clickedFeature = event.features[0];
|
|
509
|
-
const clickedSource = clickedFeature?.source;
|
|
510
|
-
const selectionOptions = this._sourceSelections.get(clickedSource)?.options;
|
|
511
|
-
this._sourceSelections.forEach(
|
|
512
|
-
(sel) => sel.handleClick(event.lngLat, clickedFeature, selectionOptions, multiSelect, this._enablePopups)
|
|
513
|
-
);
|
|
514
|
-
}
|
|
515
|
-
selectFeatures(source, features) {
|
|
516
|
-
const sourceSelection = this._sourceSelections.get(source);
|
|
517
|
-
if (!sourceSelection) {
|
|
518
|
-
return;
|
|
519
|
-
}
|
|
520
|
-
features = ensureArray(features);
|
|
521
|
-
if (features.length === 0) {
|
|
522
|
-
this.clearSelection(source);
|
|
523
|
-
return;
|
|
524
|
-
}
|
|
525
|
-
let currentSelection = new Set(sourceSelection.selectedFeatureIds);
|
|
526
|
-
switch (sourceSelection.options.mode) {
|
|
527
|
-
case "single":
|
|
528
|
-
currentSelection = /* @__PURE__ */ new Set([features[0]]);
|
|
529
|
-
sourceSelection.updateSelection(currentSelection);
|
|
530
|
-
break;
|
|
531
|
-
case "multi":
|
|
532
|
-
features.forEach((f) => currentSelection.add(f));
|
|
533
|
-
sourceSelection.updateSelection(currentSelection);
|
|
534
|
-
break;
|
|
535
|
-
}
|
|
536
|
-
if (sourceSelection.selectedFeatureIds.size && isStringFull(sourceSelection.options.group)) {
|
|
537
|
-
this._sourceSelections.forEach((s) => {
|
|
538
|
-
if (s != sourceSelection && s.options.clear === "group" && s.options.group == sourceSelection.options.group) {
|
|
539
|
-
s.updateSelection(/* @__PURE__ */ new Set());
|
|
540
|
-
}
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
selectedFeatureIds(source) {
|
|
545
|
-
const sourceSelection = this._sourceSelections.get(source);
|
|
546
|
-
if (!sourceSelection) {
|
|
547
|
-
return [];
|
|
548
|
-
}
|
|
549
|
-
return Array.from(sourceSelection.selectedFeatureIds);
|
|
550
|
-
}
|
|
551
|
-
selectedFeatureStream(source) {
|
|
552
|
-
const sourceSelection = this._sourceSelections.get(source);
|
|
553
|
-
if (!sourceSelection) {
|
|
554
|
-
throw new FlowMapError("no source selection");
|
|
555
|
-
}
|
|
556
|
-
return sourceSelection.selectedFeatureStream;
|
|
557
|
-
}
|
|
558
|
-
enablePopups(enabled = true) {
|
|
559
|
-
this._enablePopups = true;
|
|
560
|
-
}
|
|
561
|
-
disablePopups() {
|
|
562
|
-
if (this._enablePopups) {
|
|
563
|
-
this.map.getPlugin(PopupPlugin).closeAllPopups();
|
|
564
|
-
this._enablePopups = false;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
function addAnnotationLayers(map) {
|
|
570
|
-
map.transaction(() => {
|
|
571
|
-
const annotationSource = new MapDataSource({
|
|
572
|
-
id: "map-annotations",
|
|
573
|
-
type: "geojson",
|
|
574
|
-
src: { type: "FeatureCollection", features: [] },
|
|
575
|
-
featureId: "id"
|
|
576
|
-
});
|
|
577
|
-
map.addSource(annotationSource);
|
|
578
|
-
const polygonFillLayer = new MapLayer({
|
|
579
|
-
id: "map-annotations-polygon-fill",
|
|
580
|
-
type: "fill",
|
|
581
|
-
source: annotationSource.id,
|
|
582
|
-
filter: `geometry-type() == 'Polygon' && coalesce(@visible, true)`,
|
|
583
|
-
style: `
|
|
584
|
-
fill-color: @fillColor;
|
|
585
|
-
`
|
|
586
|
-
});
|
|
587
|
-
map.addLayer(polygonFillLayer);
|
|
588
|
-
const polygonStrokeLayer = new MapLayer({
|
|
589
|
-
id: "map-annotations-polygon-stroke",
|
|
590
|
-
type: "line",
|
|
591
|
-
source: annotationSource.id,
|
|
592
|
-
filter: `geometry-type() == 'Polygon' && coalesce(@visible, true)`,
|
|
593
|
-
style: `
|
|
594
|
-
line-color: @strokeColor;
|
|
595
|
-
line-width: @strokeWidth;
|
|
596
|
-
`
|
|
597
|
-
});
|
|
598
|
-
map.addLayer(polygonStrokeLayer);
|
|
599
|
-
const lineStrokeLayer = new MapLayer({
|
|
600
|
-
id: "map-annotations-line-stroke",
|
|
601
|
-
type: "line",
|
|
602
|
-
source: annotationSource.id,
|
|
603
|
-
filter: `geometry-type() == 'LineString' && coalesce(@visible, true)`,
|
|
604
|
-
style: `
|
|
605
|
-
line-color: @strokeColor;
|
|
606
|
-
line-width: @strokeWidth;
|
|
607
|
-
`
|
|
608
|
-
});
|
|
609
|
-
map.addLayer(lineStrokeLayer);
|
|
610
|
-
const pointLayer = new MapLayer({
|
|
611
|
-
id: "map-annotations-point",
|
|
612
|
-
type: "circle",
|
|
613
|
-
source: annotationSource.id,
|
|
614
|
-
filter: `geometry-type() == 'Point' && coalesce(@visible, true)`,
|
|
615
|
-
style: `
|
|
616
|
-
circle-radius: @radius;
|
|
617
|
-
circle-color: @fillColor;
|
|
618
|
-
circle-stroke-color: @strokeColor;
|
|
619
|
-
circle-stroke-width: @strokeWidth;
|
|
620
|
-
`
|
|
621
|
-
});
|
|
622
|
-
map.addLayer(pointLayer);
|
|
623
|
-
const polygonLabelsLayer = new MapLayer({
|
|
624
|
-
id: "map-annotations-polygon-labels",
|
|
625
|
-
type: "symbol",
|
|
626
|
-
source: annotationSource.id,
|
|
627
|
-
filter: `geometry-type() == 'Polygon' && to-boolean(@labelText) && coalesce(@visible, true)`,
|
|
628
|
-
interactive: false,
|
|
629
|
-
style: `
|
|
630
|
-
symbol-placement: 'point';
|
|
631
|
-
text-field: @labelText;
|
|
632
|
-
text-color: @labelColor;
|
|
633
|
-
text-size: @labelSize;
|
|
634
|
-
text-anchor: @polygonLabelAnchor;
|
|
635
|
-
/* text-offset: @labelOffset; */
|
|
636
|
-
text-justify: @labelJustify;
|
|
637
|
-
text-max-width: @labelMaxWidth;
|
|
638
|
-
text-allow-overlap: true;
|
|
639
|
-
`
|
|
640
|
-
});
|
|
641
|
-
map.addLayer(polygonLabelsLayer);
|
|
642
|
-
const pointLabelsLayer = new MapLayer({
|
|
643
|
-
id: "map-annotations-point-labels",
|
|
644
|
-
type: "symbol",
|
|
645
|
-
source: annotationSource.id,
|
|
646
|
-
filter: `geometry-type() == 'Point' && to-boolean(@labelText) && coalesce(@visible, true)`,
|
|
647
|
-
interactive: false,
|
|
648
|
-
style: `
|
|
649
|
-
symbol-placement: 'point';
|
|
650
|
-
text-field: @labelText;
|
|
651
|
-
text-color: @labelColor;
|
|
652
|
-
text-size: @labelSize;
|
|
653
|
-
text-anchor: @labelAnchor;
|
|
654
|
-
text-offset: @labelOffset;
|
|
655
|
-
/* text-radial-offset: (@radius + 8) / coalesce(@labelSize, {{annotationsStyleDefaults.labelSize}}); */
|
|
656
|
-
text-justify: @labelJustify;
|
|
657
|
-
text-max-width: @labelMaxWidth;
|
|
658
|
-
text-allow-overlap: true;
|
|
659
|
-
`
|
|
660
|
-
});
|
|
661
|
-
map.addLayer(pointLabelsLayer);
|
|
662
|
-
const lineLabelsLayer = new MapLayer({
|
|
663
|
-
id: "map-annotations-line-labels",
|
|
664
|
-
type: "symbol",
|
|
665
|
-
source: annotationSource.id,
|
|
666
|
-
filter: `geometry-type() == 'LineString' && to-boolean(@labelText) && coalesce(@visible, true)`,
|
|
667
|
-
interactive: false,
|
|
668
|
-
style: `
|
|
669
|
-
symbol-placement: 'line-center';
|
|
670
|
-
text-field: @labelText;
|
|
671
|
-
text-color: @labelColor;
|
|
672
|
-
text-anchor: @labelAnchor;
|
|
673
|
-
text-size: @labelSize;
|
|
674
|
-
/* text-offset: @labelOffset; */
|
|
675
|
-
text-justify: @labelJustify;
|
|
676
|
-
text-max-width: @labelMaxWidth;
|
|
677
|
-
text-allow-overlap: true;
|
|
678
|
-
text-ignore-placement: true;
|
|
679
|
-
`
|
|
680
|
-
});
|
|
681
|
-
map.addLayer(lineLabelsLayer);
|
|
682
|
-
const polygonSelectionLayer = new MapLayer({
|
|
683
|
-
id: "map-annotations-polygon-selection",
|
|
684
|
-
type: "line",
|
|
685
|
-
source: annotationSource.id,
|
|
686
|
-
filter: `geometry-type() == 'Polygon' && coalesce(@visible, true)`,
|
|
687
|
-
interactive: false,
|
|
688
|
-
style: `
|
|
689
|
-
line-color: @@selected ? @selectionStrokeColor : @@hover ? @hoverStrokeColor : transparent;
|
|
690
|
-
line-width: @selectionWidth;
|
|
691
|
-
line-opacity: @selectionStrokeOpacity;
|
|
692
|
-
`
|
|
693
|
-
});
|
|
694
|
-
map.addLayer(polygonSelectionLayer);
|
|
695
|
-
const pointSelectionLayer = new MapLayer({
|
|
696
|
-
id: "map-annotations-point-selection",
|
|
697
|
-
type: "circle",
|
|
698
|
-
source: annotationSource.id,
|
|
699
|
-
filter: `geometry-type() == 'Point' && coalesce(@visible, true)`,
|
|
700
|
-
interactive: false,
|
|
701
|
-
style: `
|
|
702
|
-
circle-radius: @radius + 1;
|
|
703
|
-
circle-color: transparent;
|
|
704
|
-
circle-stroke-color: @@selected ? @selectionStrokeColor : @@hover ? @hoverStrokeColor : transparent;
|
|
705
|
-
circle-stroke-width: @selectionWidth;
|
|
706
|
-
circle-stroke-opacity: @selectionStrokeOpacity;
|
|
707
|
-
`
|
|
708
|
-
});
|
|
709
|
-
map.addLayer(pointSelectionLayer);
|
|
710
|
-
const lineSelectionLayer = new MapLayer({
|
|
711
|
-
id: "map-annotations-line-selection",
|
|
712
|
-
type: "line",
|
|
713
|
-
source: annotationSource.id,
|
|
714
|
-
filter: `geometry-type() == 'LineString' && coalesce(@visible, true)`,
|
|
715
|
-
interactive: false,
|
|
716
|
-
style: `
|
|
717
|
-
line-color: @@selected ? @selectionStrokeColor : @@hover ? @hoverStrokeColor : transparent;
|
|
718
|
-
line-opacity: @selectionStrokeOpacity;
|
|
719
|
-
line-width: @selectionWidth/2;
|
|
720
|
-
line-gap-width: @strokeWidth;
|
|
721
|
-
`
|
|
722
|
-
});
|
|
723
|
-
map.addLayer(lineSelectionLayer);
|
|
724
|
-
});
|
|
725
|
-
return map.getSource("map-annotations");
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
function createSupplementaryPointsForCircle(geojson) {
|
|
729
|
-
const { properties, geometry } = geojson;
|
|
730
|
-
if (properties.user_type !== "Circle")
|
|
731
|
-
return null;
|
|
732
|
-
const supplementaryPoints = [];
|
|
733
|
-
const vertices = geometry.coordinates[0].slice(0, -1);
|
|
734
|
-
for (let index = 0; index < vertices.length; index += Math.round(vertices.length / 4)) {
|
|
735
|
-
supplementaryPoints.push(MapboxDraw.lib.createVertex(properties.id, vertices[index], `0.${index}`, false));
|
|
736
|
-
}
|
|
737
|
-
return supplementaryPoints;
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
const DirectModeOverride = MapboxDraw.modes.direct_select;
|
|
741
|
-
const moveFeatures = MapboxDraw.lib.moveFeatures;
|
|
742
|
-
const constrainFeatureMovement = MapboxDraw.lib.constrainFeatureMovement;
|
|
743
|
-
const createSupplementaryPoints = MapboxDraw.lib.createSupplementaryPoints;
|
|
744
|
-
const Constants$1 = MapboxDraw.constants;
|
|
745
|
-
DirectModeOverride.dragFeature = function(state, e, delta) {
|
|
746
|
-
moveFeatures(this.getSelected(), delta);
|
|
747
|
-
this.getSelected().filter((feature) => feature.properties.type === "Circle").map((circle) => circle.properties.circleCenter).forEach((center) => {
|
|
748
|
-
center[0] += delta.lng;
|
|
749
|
-
center[1] += delta.lat;
|
|
750
|
-
});
|
|
751
|
-
state.dragMoveLocation = e.lngLat;
|
|
752
|
-
};
|
|
753
|
-
DirectModeOverride.dragVertex = function(state, e, delta) {
|
|
754
|
-
if (state.feature.properties.type === "Circle") {
|
|
755
|
-
const center = state.feature.properties.circleCenter;
|
|
756
|
-
const movedVertex = [e.lngLat.lng, e.lngLat.lat];
|
|
757
|
-
const radius = turfDistance(point(center), point(movedVertex), { units: "kilometers" });
|
|
758
|
-
const circleFeature = turfCircle(center, radius);
|
|
759
|
-
state.feature.incomingCoords(circleFeature.geometry.coordinates);
|
|
760
|
-
state.feature.properties.circleRadius = radius;
|
|
761
|
-
} else {
|
|
762
|
-
const selectedCoords = state.selectedCoordPaths.map((coord_path) => state.feature.getCoordinate(coord_path));
|
|
763
|
-
const selectedCoordPoints = selectedCoords.map((coords) => ({
|
|
764
|
-
type: Constants$1.geojsonTypes.FEATURE,
|
|
765
|
-
properties: {},
|
|
766
|
-
geometry: {
|
|
767
|
-
type: Constants$1.geojsonTypes.POINT,
|
|
768
|
-
coordinates: coords
|
|
769
|
-
}
|
|
770
|
-
}));
|
|
771
|
-
const constrainedDelta = constrainFeatureMovement(selectedCoordPoints, delta);
|
|
772
|
-
for (let i = 0; i < selectedCoords.length; i++) {
|
|
773
|
-
const coord = selectedCoords[i];
|
|
774
|
-
state.feature.updateCoordinate(state.selectedCoordPaths[i], coord[0] + constrainedDelta.lng, coord[1] + constrainedDelta.lat);
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
};
|
|
778
|
-
DirectModeOverride.toDisplayFeatures = function(state, geojson, push) {
|
|
779
|
-
if (state.featureId === geojson.properties.id) {
|
|
780
|
-
geojson.properties.active = Constants$1.activeStates.ACTIVE;
|
|
781
|
-
push(geojson);
|
|
782
|
-
const supplementaryPoints = geojson.properties.user_type === "Circle" ? createSupplementaryPointsForCircle(geojson) : createSupplementaryPoints(geojson, {
|
|
783
|
-
map: this.map,
|
|
784
|
-
midpoints: true,
|
|
785
|
-
selectedPaths: state.selectedCoordPaths
|
|
786
|
-
});
|
|
787
|
-
supplementaryPoints.forEach(push);
|
|
788
|
-
} else {
|
|
789
|
-
geojson.properties.active = Constants$1.activeStates.INACTIVE;
|
|
790
|
-
push(geojson);
|
|
791
|
-
}
|
|
792
|
-
this.fireActionable(state);
|
|
793
|
-
};
|
|
794
|
-
const DirectMode = DirectModeOverride;
|
|
795
|
-
|
|
796
|
-
const dragPan = {
|
|
797
|
-
enable(ctx) {
|
|
798
|
-
setTimeout(() => {
|
|
799
|
-
if (!ctx.map || !ctx.map.dragPan || !ctx._ctx || !ctx._ctx.store || !ctx._ctx.store.getInitialConfigValue)
|
|
800
|
-
return;
|
|
801
|
-
if (!ctx._ctx.store.getInitialConfigValue("dragPan"))
|
|
802
|
-
return;
|
|
803
|
-
ctx.map.dragPan.enable();
|
|
804
|
-
}, 0);
|
|
805
|
-
},
|
|
806
|
-
disable(ctx) {
|
|
807
|
-
setTimeout(() => {
|
|
808
|
-
if (!ctx.map || !ctx.map.doubleClickZoom)
|
|
809
|
-
return;
|
|
810
|
-
ctx.map.dragPan.disable();
|
|
811
|
-
}, 0);
|
|
812
|
-
}
|
|
813
|
-
};
|
|
814
|
-
|
|
815
|
-
const DragCircleMode = { ...MapboxDraw.modes.draw_polygon };
|
|
816
|
-
const Constants = MapboxDraw.constants;
|
|
817
|
-
DragCircleMode.onSetup = function(opts) {
|
|
818
|
-
const polygon = this.newFeature({
|
|
819
|
-
type: Constants.geojsonTypes.FEATURE,
|
|
820
|
-
properties: {
|
|
821
|
-
type: "Circle",
|
|
822
|
-
circleCenter: []
|
|
823
|
-
},
|
|
824
|
-
geometry: {
|
|
825
|
-
type: Constants.geojsonTypes.POLYGON,
|
|
826
|
-
coordinates: []
|
|
827
|
-
}
|
|
828
|
-
});
|
|
829
|
-
this.addFeature(polygon);
|
|
830
|
-
this.clearSelectedFeatures();
|
|
831
|
-
dragPan.disable(this);
|
|
832
|
-
this.updateUIClasses({ mouse: Constants.cursors.ADD });
|
|
833
|
-
this.activateUIButton(Constants.types.POLYGON);
|
|
834
|
-
this.setActionableState({
|
|
835
|
-
trash: true
|
|
836
|
-
});
|
|
837
|
-
return {
|
|
838
|
-
polygon,
|
|
839
|
-
currentVertexPosition: 0
|
|
840
|
-
};
|
|
841
|
-
};
|
|
842
|
-
DragCircleMode.onMouseDown = DragCircleMode.onTouchStart = function(state, e) {
|
|
843
|
-
const currentCenter = state.polygon.properties.circleCenter;
|
|
844
|
-
if (currentCenter.length === 0) {
|
|
845
|
-
state.polygon.properties.circleCenter = [e.lngLat.lng, e.lngLat.lat];
|
|
846
|
-
}
|
|
847
|
-
};
|
|
848
|
-
DragCircleMode.onDrag = DragCircleMode.onMouseMove = function(state, e) {
|
|
849
|
-
const center = state.polygon.properties.circleCenter;
|
|
850
|
-
if (center.length > 0) {
|
|
851
|
-
const distanceInKm = turfDistance(
|
|
852
|
-
point(center),
|
|
853
|
-
point([e.lngLat.lng, e.lngLat.lat]),
|
|
854
|
-
{ units: "kilometers" }
|
|
855
|
-
);
|
|
856
|
-
const circleFeature = turfCircle(center, distanceInKm);
|
|
857
|
-
state.polygon.incomingCoords(circleFeature.geometry.coordinates);
|
|
858
|
-
state.polygon.properties.circleRadius = distanceInKm;
|
|
859
|
-
}
|
|
860
|
-
};
|
|
861
|
-
DragCircleMode.onMouseUp = DragCircleMode.onTouchEnd = function(state) {
|
|
862
|
-
dragPan.enable(this);
|
|
863
|
-
return this.changeMode(Constants.modes.SIMPLE_SELECT, { featureIds: [state.polygon.id] });
|
|
864
|
-
};
|
|
865
|
-
DragCircleMode.onClick = DragCircleMode.onTap = function(state) {
|
|
866
|
-
state.polygon.properties.circleCenter = [];
|
|
867
|
-
};
|
|
868
|
-
DragCircleMode.toDisplayFeatures = function(state, geojson, display) {
|
|
869
|
-
const isActivePolygon = geojson.properties.id === state.polygon.id;
|
|
870
|
-
geojson.properties.active = isActivePolygon ? Constants.activeStates.ACTIVE : Constants.activeStates.INACTIVE;
|
|
871
|
-
return display(geojson);
|
|
872
|
-
};
|
|
873
|
-
const DragCircleMode$1 = DragCircleMode;
|
|
874
|
-
|
|
875
|
-
var __defProp$5 = Object.defineProperty;
|
|
876
|
-
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
877
|
-
var __publicField$5 = (obj, key, value) => {
|
|
878
|
-
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
879
|
-
return value;
|
|
880
|
-
};
|
|
881
|
-
Debug("flow:annotation-plugin");
|
|
882
|
-
const _AnnotationPlugin = class _AnnotationPlugin extends MapPluginBase {
|
|
883
|
-
constructor(pluginManager, options) {
|
|
884
|
-
super(pluginManager, options);
|
|
885
|
-
__publicField$5(this, "name", "AnnotationPlugin");
|
|
886
|
-
// Feature data model
|
|
887
|
-
__publicField$5(this, "_features", /* @__PURE__ */ new Map());
|
|
888
|
-
__publicField$5(this, "_featureIds", []);
|
|
889
|
-
// Undo/redo stacks
|
|
890
|
-
__publicField$5(this, "_undoStack", []);
|
|
891
|
-
__publicField$5(this, "_redoStack", []);
|
|
892
|
-
// Editing state
|
|
893
|
-
__publicField$5(this, "_mode", "idle");
|
|
894
|
-
__publicField$5(this, "_activeFeatureId", null);
|
|
895
|
-
__publicField$5(this, "_activeFeatureType", null);
|
|
896
|
-
__publicField$5(this, "_onCommitCleanup", []);
|
|
897
|
-
__publicField$5(this, "_annotationDataSource");
|
|
898
|
-
__publicField$5(this, "_drawControl", null);
|
|
899
|
-
__publicField$5(this, "_removeKeyboardShortcuts", null);
|
|
900
|
-
this.options = { ..._AnnotationPlugin._defaultOptions, ...options };
|
|
901
|
-
this.options.defaultStyle = { ..._AnnotationPlugin._defaultOptions.defaultStyle, ...options?.defaultStyle };
|
|
902
|
-
}
|
|
903
|
-
initialize() {
|
|
904
|
-
this._annotationDataSource = addAnnotationLayers(this.map);
|
|
905
|
-
if (this.options.selectionOptions) {
|
|
906
|
-
this.map.getPlugin(SelectionPlugin).enableSelection(this._annotationDataSource.id, this.options.selectionOptions);
|
|
907
|
-
}
|
|
908
|
-
if (this.options.interactive) {
|
|
909
|
-
this._removeKeyboardShortcuts = this.pluginManager.addKeyboardShortcuts({
|
|
910
|
-
"Enter,Escape": () => {
|
|
911
|
-
this.commit();
|
|
912
|
-
},
|
|
913
|
-
"Delete,Backspace": () => this.deleteSelectedFeature(),
|
|
914
|
-
"Ctrl+KeyZ": () => {
|
|
915
|
-
this.undo();
|
|
916
|
-
},
|
|
917
|
-
"Ctrl+Shift+KeyZ": () => {
|
|
918
|
-
this.redo();
|
|
919
|
-
},
|
|
920
|
-
KeyP: () => this.createFeature("Polygon"),
|
|
921
|
-
KeyL: () => this.createFeature("LineString"),
|
|
922
|
-
KeyM: () => this.createFeature("Point"),
|
|
923
|
-
KeyC: () => this.createFeature("Circle")
|
|
924
|
-
});
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
destroy() {
|
|
928
|
-
if (this._removeKeyboardShortcuts)
|
|
929
|
-
this._removeKeyboardShortcuts();
|
|
930
|
-
}
|
|
931
|
-
clear() {
|
|
932
|
-
this.commit();
|
|
933
|
-
this._featureIds = [];
|
|
934
|
-
this._features = /* @__PURE__ */ new Map();
|
|
935
|
-
this._undoStack = [];
|
|
936
|
-
this._redoStack = [];
|
|
937
|
-
this._mode = "idle";
|
|
938
|
-
this._activeFeatureId = null;
|
|
939
|
-
this._activeFeatureType = null;
|
|
940
|
-
this.render();
|
|
941
|
-
return this;
|
|
942
|
-
}
|
|
943
|
-
undo() {
|
|
944
|
-
const operation = this._undoStack.pop();
|
|
945
|
-
if (operation) {
|
|
946
|
-
operation.undo();
|
|
947
|
-
this._redoStack.push(operation);
|
|
948
|
-
this.render();
|
|
949
|
-
}
|
|
950
|
-
return this;
|
|
951
|
-
}
|
|
952
|
-
/**
|
|
953
|
-
* Redo the last undone operation.
|
|
954
|
-
*/
|
|
955
|
-
redo() {
|
|
956
|
-
const operation = this._redoStack.pop();
|
|
957
|
-
if (operation) {
|
|
958
|
-
operation.do();
|
|
959
|
-
this._undoStack.push(operation);
|
|
960
|
-
this.render();
|
|
961
|
-
}
|
|
962
|
-
return this;
|
|
963
|
-
}
|
|
964
|
-
getFeature(featureId) {
|
|
965
|
-
const feature = this._features.get(featureId);
|
|
966
|
-
if (!feature) {
|
|
967
|
-
throw new FlowError(`<AnnotationPlugin>: No feature with id '${featureId}'`);
|
|
968
|
-
}
|
|
969
|
-
return feature;
|
|
970
|
-
}
|
|
971
|
-
getFeatures() {
|
|
972
|
-
return this._featureIds.map((id) => this._features.get(id));
|
|
973
|
-
}
|
|
974
|
-
setFeatures(features) {
|
|
975
|
-
this.commit();
|
|
976
|
-
const normalizedFeatures = features.map((f) => this.applyDefaults(f));
|
|
977
|
-
const oldFeatures = this._features;
|
|
978
|
-
const oldFeatureIds = this._featureIds;
|
|
979
|
-
const operation = {
|
|
980
|
-
do: () => {
|
|
981
|
-
this._featureIds = normalizedFeatures.map((f) => f.id);
|
|
982
|
-
this._features = new Map(normalizedFeatures.map((f) => [f.id, f]));
|
|
983
|
-
},
|
|
984
|
-
undo: () => {
|
|
985
|
-
this._featureIds = oldFeatureIds;
|
|
986
|
-
this._features = oldFeatures;
|
|
987
|
-
}
|
|
988
|
-
};
|
|
989
|
-
this.performOperation(operation);
|
|
990
|
-
return this;
|
|
991
|
-
}
|
|
992
|
-
addFeature(feature) {
|
|
993
|
-
this.commit();
|
|
994
|
-
const fullFeature = this.applyDefaults(feature);
|
|
995
|
-
const operation = {
|
|
996
|
-
do: () => {
|
|
997
|
-
this._features.set(fullFeature.id, fullFeature);
|
|
998
|
-
this._featureIds.push(fullFeature.id);
|
|
999
|
-
},
|
|
1000
|
-
undo: () => {
|
|
1001
|
-
this._features.delete(fullFeature.id);
|
|
1002
|
-
const index = this._featureIds.indexOf(fullFeature.id);
|
|
1003
|
-
if (index !== -1) {
|
|
1004
|
-
this._featureIds.splice(index, 1);
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
};
|
|
1008
|
-
this.performOperation(operation);
|
|
1009
|
-
return fullFeature;
|
|
1010
|
-
}
|
|
1011
|
-
deleteFeature(featureId) {
|
|
1012
|
-
this.commit();
|
|
1013
|
-
if (!featureId) {
|
|
1014
|
-
return this;
|
|
1015
|
-
}
|
|
1016
|
-
this.deselectFeature(featureId);
|
|
1017
|
-
const feature = this.getFeature(featureId);
|
|
1018
|
-
const operation = {
|
|
1019
|
-
do: () => {
|
|
1020
|
-
this._features.delete(featureId);
|
|
1021
|
-
const index = this._featureIds.indexOf(featureId);
|
|
1022
|
-
if (index !== -1) {
|
|
1023
|
-
this._featureIds.splice(index, 1);
|
|
1024
|
-
}
|
|
1025
|
-
},
|
|
1026
|
-
undo: () => {
|
|
1027
|
-
this._features.set(featureId, feature);
|
|
1028
|
-
this._featureIds.push(featureId);
|
|
1029
|
-
}
|
|
1030
|
-
};
|
|
1031
|
-
this.performOperation(operation);
|
|
1032
|
-
return this;
|
|
1033
|
-
}
|
|
1034
|
-
createFeature(featureType) {
|
|
1035
|
-
this.commit();
|
|
1036
|
-
this.startDrawing();
|
|
1037
|
-
this._drawControl.changeMode(this.drawModeForFeatureType(featureType));
|
|
1038
|
-
this._mode = "creating";
|
|
1039
|
-
this._activeFeatureId = null;
|
|
1040
|
-
this._activeFeatureType = featureType;
|
|
1041
|
-
this.emitStateChange();
|
|
1042
|
-
const commitChanges = () => {
|
|
1043
|
-
setTimeout(() => this.commit(), 0);
|
|
1044
|
-
};
|
|
1045
|
-
this.map.maplibreMap.once("draw.create", commitChanges);
|
|
1046
|
-
this.map.maplibreMap.once("draw.modechange", commitChanges);
|
|
1047
|
-
this._onCommitCleanup.push(() => {
|
|
1048
|
-
this.map.maplibreMap.off("draw.create", commitChanges);
|
|
1049
|
-
this.map.maplibreMap.off("draw.modechange", commitChanges);
|
|
1050
|
-
});
|
|
1051
|
-
}
|
|
1052
|
-
editFeature(featureId) {
|
|
1053
|
-
const feature = this.getFeature(featureId);
|
|
1054
|
-
this._mode = "editing";
|
|
1055
|
-
this._activeFeatureId = featureId;
|
|
1056
|
-
this._activeFeatureType = feature.properties.type;
|
|
1057
|
-
const commitChanges = () => {
|
|
1058
|
-
setTimeout(() => this.commit(), 0);
|
|
1059
|
-
};
|
|
1060
|
-
this.startDrawing();
|
|
1061
|
-
this._drawControl.add(feature);
|
|
1062
|
-
this.setFeatureProperty(featureId, "visible", false);
|
|
1063
|
-
this.render();
|
|
1064
|
-
switch (this.editModeForFeature(feature)) {
|
|
1065
|
-
case "direct_select":
|
|
1066
|
-
this._drawControl.changeMode("direct_select", {
|
|
1067
|
-
featureId
|
|
1068
|
-
});
|
|
1069
|
-
this.map.maplibreMap.once("draw.modechange", commitChanges);
|
|
1070
|
-
this._onCommitCleanup.push(() => this.map.maplibreMap.off("draw.modechange", commitChanges));
|
|
1071
|
-
break;
|
|
1072
|
-
case "simple_select":
|
|
1073
|
-
this._drawControl.changeMode("simple_select", {
|
|
1074
|
-
featureIds: [featureId]
|
|
1075
|
-
});
|
|
1076
|
-
this.map.maplibreMap.once("draw.selectionchange", commitChanges);
|
|
1077
|
-
this._onCommitCleanup.push(() => this.map.maplibreMap.off("draw.selectionchange", commitChanges));
|
|
1078
|
-
break;
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
zoomToFeature(featureId, animationOptions) {
|
|
1082
|
-
const feature = this.getFeature(featureId);
|
|
1083
|
-
if (!feature)
|
|
1084
|
-
return this;
|
|
1085
|
-
const bbox = feature.properties.type === "Point" ? turfBBox(turfBuffer(feature, 50)) : turfBBox(feature);
|
|
1086
|
-
this.map.setBounds(bbox, animationOptions);
|
|
1087
|
-
return this;
|
|
1088
|
-
}
|
|
1089
|
-
setFeatureProperty(featureId, property, value) {
|
|
1090
|
-
const feature = this.getFeature(featureId);
|
|
1091
|
-
const featureCopy = {
|
|
1092
|
-
...feature,
|
|
1093
|
-
properties: { ...feature.properties, [property]: value }
|
|
1094
|
-
};
|
|
1095
|
-
this._features.set(featureId, featureCopy);
|
|
1096
|
-
return this;
|
|
1097
|
-
}
|
|
1098
|
-
setFeatureProperties(featureId, properties) {
|
|
1099
|
-
const feature = this.getFeature(featureId);
|
|
1100
|
-
const featureCopy = {
|
|
1101
|
-
...feature,
|
|
1102
|
-
properties: { ...feature.properties, ...properties }
|
|
1103
|
-
};
|
|
1104
|
-
this._features.set(featureId, featureCopy);
|
|
1105
|
-
return this;
|
|
1106
|
-
}
|
|
1107
|
-
commit() {
|
|
1108
|
-
this._onCommitCleanup.forEach((f) => f());
|
|
1109
|
-
this._onCommitCleanup = [];
|
|
1110
|
-
if (this._mode === "idle")
|
|
1111
|
-
return this;
|
|
1112
|
-
const drawControlFeature = this._drawControl.getAll().features[0];
|
|
1113
|
-
let operation = null;
|
|
1114
|
-
if (this._mode === "editing") {
|
|
1115
|
-
const mapFeature = this.getFeature(this._activeFeatureId);
|
|
1116
|
-
this.setFeatureProperty(mapFeature.id, "visible", true);
|
|
1117
|
-
if (!turfBooleanEqual(mapFeature.geometry, drawControlFeature.geometry)) {
|
|
1118
|
-
operation = {
|
|
1119
|
-
do: () => {
|
|
1120
|
-
this.setFeatureGeometry(mapFeature.id, drawControlFeature.geometry);
|
|
1121
|
-
if (drawControlFeature.properties.type === "Circle") {
|
|
1122
|
-
this.setFeatureProperty(mapFeature.id, "center", drawControlFeature.properties.circleCenter);
|
|
1123
|
-
this.setFeatureProperty(mapFeature.id, "radiusInKm", drawControlFeature.properties.circleRadius);
|
|
1124
|
-
}
|
|
1125
|
-
},
|
|
1126
|
-
undo: () => {
|
|
1127
|
-
this.setFeatureGeometry(mapFeature.id, mapFeature.geometry);
|
|
1128
|
-
if (mapFeature.properties.type === "Circle") {
|
|
1129
|
-
this.setFeatureProperty(mapFeature.id, "center", mapFeature.properties.circleCenter);
|
|
1130
|
-
this.setFeatureProperty(mapFeature.id, "radiusInKm", mapFeature.properties.circleRadius);
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
};
|
|
1134
|
-
}
|
|
1135
|
-
} else if (this._mode === "creating") {
|
|
1136
|
-
if (this.isValidGeometry(drawControlFeature)) {
|
|
1137
|
-
let createdFeature = drawControlFeature;
|
|
1138
|
-
createdFeature.id = "";
|
|
1139
|
-
this.applyDefaults(createdFeature);
|
|
1140
|
-
operation = {
|
|
1141
|
-
do: () => {
|
|
1142
|
-
this._features.set(drawControlFeature.id, drawControlFeature);
|
|
1143
|
-
this._featureIds.push(drawControlFeature.id);
|
|
1144
|
-
if (this.options.selectionOptions?.mode === "single" || this.options.selectionOptions?.mode === "multi") {
|
|
1145
|
-
this.map.getPlugin(SelectionPlugin).selectFeatures(this._annotationDataSource.id, drawControlFeature.id);
|
|
1146
|
-
}
|
|
1147
|
-
},
|
|
1148
|
-
undo: () => {
|
|
1149
|
-
createdFeature = this._features.get(createdFeature.id);
|
|
1150
|
-
this._features.delete(createdFeature.id);
|
|
1151
|
-
const index = this._featureIds.indexOf(createdFeature.id);
|
|
1152
|
-
if (index !== -1) {
|
|
1153
|
-
this._featureIds.splice(index, 1);
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
};
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
|
-
if (operation) {
|
|
1160
|
-
this.performOperation(operation);
|
|
1161
|
-
}
|
|
1162
|
-
this._mode = "idle";
|
|
1163
|
-
this._activeFeatureId = null;
|
|
1164
|
-
this._activeFeatureType = null;
|
|
1165
|
-
this.endDrawing();
|
|
1166
|
-
this.render();
|
|
1167
|
-
return this;
|
|
1168
|
-
}
|
|
1169
|
-
cancel() {
|
|
1170
|
-
this._onCommitCleanup.forEach((f) => f());
|
|
1171
|
-
this._onCommitCleanup = [];
|
|
1172
|
-
if (this._mode === "idle")
|
|
1173
|
-
return this;
|
|
1174
|
-
if (this._mode === "editing") {
|
|
1175
|
-
this.setFeatureProperty(this._activeFeatureId, "visible", true);
|
|
1176
|
-
}
|
|
1177
|
-
this._activeFeatureId = null;
|
|
1178
|
-
this._activeFeatureType = null;
|
|
1179
|
-
this._mode = "idle";
|
|
1180
|
-
this.endDrawing();
|
|
1181
|
-
this.render();
|
|
1182
|
-
return this;
|
|
1183
|
-
}
|
|
1184
|
-
render() {
|
|
1185
|
-
const renderedFeatures = {
|
|
1186
|
-
type: "FeatureCollection",
|
|
1187
|
-
features: this._featureIds.map((id) => this._features.get(id))
|
|
1188
|
-
};
|
|
1189
|
-
this._annotationDataSource.setSrc(renderedFeatures);
|
|
1190
|
-
this.emitStateChange();
|
|
1191
|
-
return this;
|
|
1192
|
-
}
|
|
1193
|
-
handleDblClick(event) {
|
|
1194
|
-
if (!this.options.interactive) {
|
|
1195
|
-
return;
|
|
1196
|
-
}
|
|
1197
|
-
const clickedFeature = event.features[0];
|
|
1198
|
-
if (clickedFeature && clickedFeature.source === this._annotationDataSource.id) {
|
|
1199
|
-
this.editFeature(clickedFeature.id.toString());
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
|
-
handleBeforeStyleChanged(event) {
|
|
1203
|
-
const { oldStyle, newStyle } = event;
|
|
1204
|
-
if (this._drawControl) {
|
|
1205
|
-
if (oldStyle.sources["mapbox-gl-draw"]) {
|
|
1206
|
-
newStyle.sources["mapbox-gl-draw"] = oldStyle.sources["mapbox-gl-draw"];
|
|
1207
|
-
}
|
|
1208
|
-
oldStyle.layers.filter((l) => l.id.startsWith("gl-draw")).forEach((l) => newStyle.layers.push(l));
|
|
1209
|
-
}
|
|
1210
|
-
return newStyle;
|
|
1211
|
-
}
|
|
1212
|
-
startDrawing() {
|
|
1213
|
-
if (this._drawControl) {
|
|
1214
|
-
return this._drawControl;
|
|
1215
|
-
}
|
|
1216
|
-
this.pluginManager.setExclusivePlugin(this);
|
|
1217
|
-
this._drawControl = new MapboxDraw({
|
|
1218
|
-
displayControlsDefault: false,
|
|
1219
|
-
keybindings: false,
|
|
1220
|
-
modes: {
|
|
1221
|
-
...MapboxDraw.modes,
|
|
1222
|
-
drag_circle: DragCircleMode$1,
|
|
1223
|
-
direct_select: DirectMode
|
|
1224
|
-
//...options.modes
|
|
1225
|
-
},
|
|
1226
|
-
userProperties: true
|
|
1227
|
-
});
|
|
1228
|
-
this.map.maplibreMap.addControl(this._drawControl);
|
|
1229
|
-
return this._drawControl;
|
|
1230
|
-
}
|
|
1231
|
-
endDrawing() {
|
|
1232
|
-
this.pluginManager.removeExclusivePlugin(this);
|
|
1233
|
-
if (this._drawControl) {
|
|
1234
|
-
this.map.maplibreMap.removeControl(this._drawControl);
|
|
1235
|
-
this._drawControl = null;
|
|
1236
|
-
}
|
|
1237
|
-
}
|
|
1238
|
-
applyDefaults(feature) {
|
|
1239
|
-
feature.id = feature.properties.id = this.generateFeatureId(feature);
|
|
1240
|
-
feature.properties = {
|
|
1241
|
-
id: this.generateFeatureId(feature),
|
|
1242
|
-
name: this.generateFeatureName(feature),
|
|
1243
|
-
type: feature.properties.type ?? feature.geometry.type,
|
|
1244
|
-
selected: false,
|
|
1245
|
-
...this.options.defaultStyle,
|
|
1246
|
-
...feature.properties
|
|
1247
|
-
};
|
|
1248
|
-
feature.id = feature.properties.id;
|
|
1249
|
-
return feature;
|
|
1250
|
-
}
|
|
1251
|
-
generateFeatureId(feature) {
|
|
1252
|
-
if (isNumber(feature.id) || isStringFull(feature.id)) {
|
|
1253
|
-
return feature.id.toString();
|
|
1254
|
-
} else {
|
|
1255
|
-
return randomId("feature");
|
|
1256
|
-
}
|
|
1257
|
-
}
|
|
1258
|
-
generateFeatureName(feature) {
|
|
1259
|
-
const type = feature.properties.type ?? feature.geometry.type;
|
|
1260
|
-
return `${type} ${this._featureIds.length}`;
|
|
1261
|
-
}
|
|
1262
|
-
performOperation(operation) {
|
|
1263
|
-
this._undoStack.push(operation);
|
|
1264
|
-
this._redoStack.length = 0;
|
|
1265
|
-
operation.do();
|
|
1266
|
-
}
|
|
1267
|
-
deselectFeature(featureId) {
|
|
1268
|
-
if (this.options.selectionOptions?.mode === "single" || this.options.selectionOptions?.mode === "multi") {
|
|
1269
|
-
this.map.getPlugin(SelectionPlugin).deselectFeatures(this._annotationDataSource.id, featureId);
|
|
1270
|
-
}
|
|
1271
|
-
}
|
|
1272
|
-
deleteSelectedFeature() {
|
|
1273
|
-
if (this.options.selectionOptions?.mode === "single" || this.options.selectionOptions?.mode === "multi") {
|
|
1274
|
-
const selected = this.map.getPlugin(SelectionPlugin).selectedFeatureIds(this._annotationDataSource.id);
|
|
1275
|
-
selected.forEach((id) => this.deleteFeature(id));
|
|
1276
|
-
this.render();
|
|
1277
|
-
}
|
|
1278
|
-
}
|
|
1279
|
-
editModeForFeature(feature) {
|
|
1280
|
-
switch (feature.geometry.type) {
|
|
1281
|
-
case "Point":
|
|
1282
|
-
return "simple_select";
|
|
1283
|
-
default:
|
|
1284
|
-
return "direct_select";
|
|
1285
|
-
}
|
|
1286
|
-
}
|
|
1287
|
-
drawModeForFeatureType(featureType) {
|
|
1288
|
-
switch (featureType) {
|
|
1289
|
-
case "Polygon":
|
|
1290
|
-
return "draw_polygon";
|
|
1291
|
-
case "LineString":
|
|
1292
|
-
return "draw_line_string";
|
|
1293
|
-
case "Point":
|
|
1294
|
-
return "draw_point";
|
|
1295
|
-
case "Circle":
|
|
1296
|
-
return "drag_circle";
|
|
1297
|
-
default:
|
|
1298
|
-
throw new Error(`Unrecognized feature type: ${featureType}`);
|
|
1299
|
-
}
|
|
1300
|
-
}
|
|
1301
|
-
setFeatureGeometry(featureId, geometry) {
|
|
1302
|
-
const feature = this.getFeature(featureId);
|
|
1303
|
-
const featureCopy = {
|
|
1304
|
-
...feature,
|
|
1305
|
-
geometry
|
|
1306
|
-
};
|
|
1307
|
-
this._features.set(featureId, featureCopy);
|
|
1308
|
-
return featureCopy;
|
|
1309
|
-
}
|
|
1310
|
-
isValidGeometry(feature) {
|
|
1311
|
-
if (isPolygon(feature)) {
|
|
1312
|
-
return feature.geometry.coordinates[0][0] !== null && feature.geometry.coordinates[0].length > 3 && turfArea(feature) > 0;
|
|
1313
|
-
} else if (isLineString(feature)) {
|
|
1314
|
-
return feature.geometry.coordinates.length > 1 && turfLength(feature) > 0;
|
|
1315
|
-
} else if (isPoint(feature)) {
|
|
1316
|
-
return feature.geometry.coordinates.length > 0;
|
|
1317
|
-
}
|
|
1318
|
-
return false;
|
|
1319
|
-
}
|
|
1320
|
-
emitStateChange() {
|
|
1321
|
-
const eventData = {
|
|
1322
|
-
mode: this._mode,
|
|
1323
|
-
canUndo: this._undoStack.length > 0,
|
|
1324
|
-
canRedo: this._redoStack.length > 0,
|
|
1325
|
-
activeFeatureId: this._activeFeatureId,
|
|
1326
|
-
activeFeatureType: this._activeFeatureType,
|
|
1327
|
-
features: this._featureIds.map((id) => this._features.get(id))
|
|
1328
|
-
};
|
|
1329
|
-
this.emit("annotationStateChanged", new AnnotationEvent("annotationStateChanged", this.map, eventData));
|
|
1330
|
-
}
|
|
1331
|
-
};
|
|
1332
|
-
__publicField$5(_AnnotationPlugin, "_defaultOptions", {
|
|
1333
|
-
interactive: true,
|
|
1334
|
-
defaultStyle: {
|
|
1335
|
-
labelSize: 10,
|
|
1336
|
-
labelColor: "#ffffff",
|
|
1337
|
-
labelMaxWidth: 10,
|
|
1338
|
-
labelOffset: [0, 0.5],
|
|
1339
|
-
labelJustify: "auto",
|
|
1340
|
-
labelAnchor: "top",
|
|
1341
|
-
polygonLabelAnchor: "center",
|
|
1342
|
-
radius: 5,
|
|
1343
|
-
fillColor: "rgba(204,204,204,0.65)",
|
|
1344
|
-
strokeWidth: 1,
|
|
1345
|
-
strokeColor: "#ffffff",
|
|
1346
|
-
selectionStrokeColor: "orange",
|
|
1347
|
-
selectionStrokeOpacity: 0.5,
|
|
1348
|
-
selectionWidth: 3,
|
|
1349
|
-
hoverStrokeColor: "transparent"
|
|
1350
|
-
}
|
|
1351
|
-
});
|
|
1352
|
-
let AnnotationPlugin = _AnnotationPlugin;
|
|
1353
|
-
|
|
1354
|
-
var __defProp$4 = Object.defineProperty;
|
|
1355
|
-
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1356
|
-
var __publicField$4 = (obj, key, value) => {
|
|
1357
|
-
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1358
|
-
return value;
|
|
1359
|
-
};
|
|
1360
|
-
const debug$1 = Debug("flow:data-join-map-plugin");
|
|
1361
|
-
const _DataJoin = class _DataJoin {
|
|
1362
|
-
constructor(id, map, options) {
|
|
1363
|
-
this.id = id;
|
|
1364
|
-
this.map = map;
|
|
1365
|
-
__publicField$4(this, "autorunDisposer", null);
|
|
1366
|
-
__publicField$4(this, "dataExpression", null);
|
|
1367
|
-
__publicField$4(this, "options");
|
|
1368
|
-
__publicField$4(this, "parameterExpressions", {});
|
|
1369
|
-
this.options = {
|
|
1370
|
-
..._DataJoin.defaultOptions,
|
|
1371
|
-
...options
|
|
1372
|
-
};
|
|
1373
|
-
}
|
|
1374
|
-
get source() {
|
|
1375
|
-
return this.options.source;
|
|
1376
|
-
}
|
|
1377
|
-
start() {
|
|
1378
|
-
this.stop();
|
|
1379
|
-
if (isString(this.options.data)) {
|
|
1380
|
-
if (isURL(this.options.data))
|
|
1381
|
-
this.options.data = `'${this.options.data}'`;
|
|
1382
|
-
this.dataExpression = new ReactiveExpression(this.options.data);
|
|
1383
|
-
this.dataExpression.bindState(this.map.context.state);
|
|
1384
|
-
} else {
|
|
1385
|
-
this.dataExpression = null;
|
|
1386
|
-
}
|
|
1387
|
-
if (isArrayFull(this.options.parameters)) {
|
|
1388
|
-
this.parameterExpressions = this.options.parameters.reduce((accum, param) => {
|
|
1389
|
-
const expr = new ReactiveExpression(param.value.toString());
|
|
1390
|
-
expr.bindState(this.map.context.state);
|
|
1391
|
-
accum[param.name] = expr;
|
|
1392
|
-
return accum;
|
|
1393
|
-
}, {});
|
|
1394
|
-
}
|
|
1395
|
-
this.autorunDisposer = autorun(
|
|
1396
|
-
async () => {
|
|
1397
|
-
let data = this.dataExpression ? toJS(this.dataExpression.value) : this.options.data;
|
|
1398
|
-
const missingParams = this.options.parameters.map((p) => p.required && isNil(this.parameterExpressions[p.name].value) ? p.name : void 0).filter((p) => !!p);
|
|
1399
|
-
if (isNull(data)) {
|
|
1400
|
-
debug$1(`FlowMap<${this.map.id}>: Skipping data join '${this.id}' (null data)`);
|
|
1401
|
-
return;
|
|
1402
|
-
}
|
|
1403
|
-
if (missingParams.length) {
|
|
1404
|
-
debug$1(
|
|
1405
|
-
`FlowMap<${this.map.id}>: Skipping data join '${this.id}' (null required parameters: ${missingParams.join(
|
|
1406
|
-
", "
|
|
1407
|
-
)})`
|
|
1408
|
-
);
|
|
1409
|
-
return;
|
|
1410
|
-
}
|
|
1411
|
-
debug$1(`FlowMap<${this.map.id}>: Performing data join '${this.id}'`);
|
|
1412
|
-
if (isString(data)) {
|
|
1413
|
-
try {
|
|
1414
|
-
data = await this.loadData(data);
|
|
1415
|
-
} catch (e) {
|
|
1416
|
-
this.map.emitError(`Failed to load data for data join '${this.id}' - ${e.message}`, e);
|
|
1417
|
-
data = [];
|
|
1418
|
-
}
|
|
1419
|
-
}
|
|
1420
|
-
this.doDataJoin(data);
|
|
1421
|
-
},
|
|
1422
|
-
{ name: `FlowDataJoin.${this.map.id}.${this.id})` }
|
|
1423
|
-
);
|
|
1424
|
-
}
|
|
1425
|
-
stop() {
|
|
1426
|
-
if (this.autorunDisposer) {
|
|
1427
|
-
this.autorunDisposer();
|
|
1428
|
-
this.autorunDisposer = null;
|
|
1429
|
-
}
|
|
1430
|
-
}
|
|
1431
|
-
doDataJoin(data) {
|
|
1432
|
-
const source = this.map.getSource(this.options.source);
|
|
1433
|
-
const sourceLayer = source.type === "vector" ? this.options.sourceLayer || "geometry" : void 0;
|
|
1434
|
-
if (this.options.clear) {
|
|
1435
|
-
this.map.removeFeatureState({ source: source.id, sourceLayer }, this.id);
|
|
1436
|
-
}
|
|
1437
|
-
const featureData = data.reduce((accum, d) => {
|
|
1438
|
-
accum[d[this.options.foreignKey]] = { [this.id]: d };
|
|
1439
|
-
return accum;
|
|
1440
|
-
}, {});
|
|
1441
|
-
this.map.setFeatureStateBulk({ source: source.id, sourceLayer }, featureData);
|
|
1442
|
-
}
|
|
1443
|
-
loadData(datasetOrUrl) {
|
|
1444
|
-
if (isURL(datasetOrUrl)) {
|
|
1445
|
-
const url = new URL(datasetOrUrl);
|
|
1446
|
-
const params = new URLSearchParams(url.searchParams);
|
|
1447
|
-
if (isArrayFull(this.options.parameters)) {
|
|
1448
|
-
this.options.parameters.forEach((p) => {
|
|
1449
|
-
params.append(p.name, this.parameterExpressions[p.name].value);
|
|
1450
|
-
});
|
|
1451
|
-
}
|
|
1452
|
-
url.search = params.toString();
|
|
1453
|
-
const headers = new Headers({ Accept: "application/json" });
|
|
1454
|
-
const request = new Request(url.toString(), {
|
|
1455
|
-
method: "GET",
|
|
1456
|
-
mode: "cors",
|
|
1457
|
-
headers,
|
|
1458
|
-
cache: "default"
|
|
1459
|
-
});
|
|
1460
|
-
return fetch(request).then((response) => {
|
|
1461
|
-
if (!response.ok) {
|
|
1462
|
-
throw new Error(`status=${response.status} ${response.statusText}`);
|
|
1463
|
-
}
|
|
1464
|
-
return response.json();
|
|
1465
|
-
});
|
|
1466
|
-
} else {
|
|
1467
|
-
const params = {};
|
|
1468
|
-
if (isArrayFull(this.options.parameters)) {
|
|
1469
|
-
this.options.parameters.forEach((p) => {
|
|
1470
|
-
params[p.name] = this.parameterExpressions[p.name].value;
|
|
1471
|
-
});
|
|
1472
|
-
}
|
|
1473
|
-
return this.map.context.flowClient.datasets.query(datasetOrUrl, {}, params);
|
|
1474
|
-
}
|
|
1475
|
-
}
|
|
1476
|
-
};
|
|
1477
|
-
__publicField$4(_DataJoin, "defaultOptions", {
|
|
1478
|
-
clear: false,
|
|
1479
|
-
parameters: []
|
|
1480
|
-
});
|
|
1481
|
-
let DataJoin = _DataJoin;
|
|
1482
|
-
class DataJoinPlugin extends MapPluginBase {
|
|
1483
|
-
constructor(pluginManager) {
|
|
1484
|
-
super(pluginManager);
|
|
1485
|
-
__publicField$4(this, "_joins", /* @__PURE__ */ new Map());
|
|
1486
|
-
__publicField$4(this, "name", "DataJoinPlugin");
|
|
1487
|
-
}
|
|
1488
|
-
addDataJoin(id, options) {
|
|
1489
|
-
const dataJoin = new DataJoin(id, this.map, options);
|
|
1490
|
-
this._joins.set(id, dataJoin);
|
|
1491
|
-
dataJoin.start();
|
|
1492
|
-
}
|
|
1493
|
-
bindState(state) {
|
|
1494
|
-
this._joins.forEach((join) => join.start());
|
|
1495
|
-
}
|
|
1496
|
-
destroy() {
|
|
1497
|
-
this._joins.forEach((join) => join.stop());
|
|
1498
|
-
this._joins.clear();
|
|
1499
|
-
}
|
|
1500
|
-
handleSourceRemoved(event) {
|
|
1501
|
-
this._joins.forEach((join) => {
|
|
1502
|
-
if (join.source === event.source) {
|
|
1503
|
-
join.stop();
|
|
1504
|
-
this._joins.delete(join.id);
|
|
1505
|
-
}
|
|
1506
|
-
});
|
|
1507
|
-
}
|
|
1508
|
-
removeDataJoin(id) {
|
|
1509
|
-
const dataJoin = this._joins.get(id);
|
|
1510
|
-
if (dataJoin) {
|
|
1511
|
-
dataJoin.stop();
|
|
1512
|
-
this._joins.delete(id);
|
|
1513
|
-
} else {
|
|
1514
|
-
throw new FlowError(`Cannot remove unrecognized data join '${id}'`);
|
|
1515
|
-
}
|
|
1516
|
-
}
|
|
1517
|
-
}
|
|
1518
|
-
|
|
1519
|
-
var __defProp$3 = Object.defineProperty;
|
|
1520
|
-
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1521
|
-
var __publicField$3 = (obj, key, value) => {
|
|
1522
|
-
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1523
|
-
return value;
|
|
1524
|
-
};
|
|
1525
|
-
const _MapExporter = class _MapExporter {
|
|
1526
|
-
constructor(map) {
|
|
1527
|
-
this.map = map;
|
|
1528
|
-
__publicField$3(this, "nativePixelRatio", window.devicePixelRatio);
|
|
1529
|
-
}
|
|
1530
|
-
async export(options) {
|
|
1531
|
-
options = { ..._MapExporter.defaultOptions, ...options };
|
|
1532
|
-
const [container, mapCopy] = await this.createMapCopy(options);
|
|
1533
|
-
return new Promise((resolve, reject) => {
|
|
1534
|
-
const fileName = `${options.name}.${options.format}`;
|
|
1535
|
-
const mapCanvas = mapCopy.getCanvas();
|
|
1536
|
-
const exportCanvas = this.createExportCanvas(container, mapCanvas);
|
|
1537
|
-
const exportContext = exportCanvas.getContext("2d");
|
|
1538
|
-
if (!exportContext) {
|
|
1539
|
-
this.destroyMapCopy(container, mapCopy);
|
|
1540
|
-
reject(new Error("Failed to create export canvas context"));
|
|
1541
|
-
return;
|
|
1542
|
-
}
|
|
1543
|
-
const drawOverlayCallback = (err) => {
|
|
1544
|
-
if (err) {
|
|
1545
|
-
this.destroyMapCopy(container, mapCopy);
|
|
1546
|
-
reject(err);
|
|
1547
|
-
} else {
|
|
1548
|
-
switch (options.format) {
|
|
1549
|
-
case "png":
|
|
1550
|
-
exportCanvas.toBlob((blob) => {
|
|
1551
|
-
blob && saveAs(blob, fileName);
|
|
1552
|
-
});
|
|
1553
|
-
break;
|
|
1554
|
-
case "pdf":
|
|
1555
|
-
throw new Error("Export to PDF is not currently supported");
|
|
1556
|
-
}
|
|
1557
|
-
this.destroyMapCopy(container, mapCopy);
|
|
1558
|
-
resolve(fileName);
|
|
1559
|
-
}
|
|
1560
|
-
};
|
|
1561
|
-
const mapImage = new Image();
|
|
1562
|
-
mapImage.onload = () => {
|
|
1563
|
-
exportContext.drawImage(mapImage, 0, 0);
|
|
1564
|
-
if (isFunction(options.drawOverlayFn)) {
|
|
1565
|
-
options.drawOverlayFn(
|
|
1566
|
-
exportContext,
|
|
1567
|
-
exportCanvas.width,
|
|
1568
|
-
exportCanvas.height,
|
|
1569
|
-
options.dpmm,
|
|
1570
|
-
drawOverlayCallback
|
|
1571
|
-
);
|
|
1572
|
-
} else {
|
|
1573
|
-
drawOverlayCallback(null);
|
|
1574
|
-
}
|
|
1575
|
-
};
|
|
1576
|
-
mapImage.src = mapCopy.getCanvas().toDataURL();
|
|
1577
|
-
});
|
|
1578
|
-
}
|
|
1579
|
-
createMapCopy(options) {
|
|
1580
|
-
const geoBounds = options.bounds || this.map.maplibreMap.getBounds().toArray().flat();
|
|
1581
|
-
const geoBottomLeft = [geoBounds[0], geoBounds[1]];
|
|
1582
|
-
const geoTopRight = [geoBounds[2], geoBounds[3]];
|
|
1583
|
-
const geoCenter = [
|
|
1584
|
-
(geoBottomLeft[0] + geoTopRight[0]) / 2,
|
|
1585
|
-
(geoBottomLeft[1] + geoTopRight[1]) / 2
|
|
1586
|
-
];
|
|
1587
|
-
const pxBottomLeft = this.map.maplibreMap.project(geoBottomLeft);
|
|
1588
|
-
const pxTopRight = this.map.maplibreMap.project(geoTopRight);
|
|
1589
|
-
const pxWidth = pxTopRight.x - pxBottomLeft.x;
|
|
1590
|
-
const pxHeight = pxBottomLeft.y - pxTopRight.y;
|
|
1591
|
-
const exportWidth = options.width * options.dpmm;
|
|
1592
|
-
const exportHeight = options.height * options.dpmm;
|
|
1593
|
-
const aspectRatios = {
|
|
1594
|
-
width: pxWidth / exportWidth,
|
|
1595
|
-
height: pxHeight / exportHeight
|
|
1596
|
-
};
|
|
1597
|
-
const coverRatio = Math.max(aspectRatios.width, aspectRatios.height);
|
|
1598
|
-
const copyWidth = exportWidth * coverRatio;
|
|
1599
|
-
const copyHeight = exportHeight * coverRatio;
|
|
1600
|
-
const pixelRatio = exportWidth / copyWidth;
|
|
1601
|
-
this.setDevicePixelRatio(pixelRatio);
|
|
1602
|
-
const container = document.createElement("div");
|
|
1603
|
-
container.id = randomId("export");
|
|
1604
|
-
container.classList.add("maplibregl-export-container");
|
|
1605
|
-
container.style.width = `${copyWidth}px`;
|
|
1606
|
-
container.style.height = `${copyHeight}px`;
|
|
1607
|
-
this.map.container.insertBefore(container, this.map.container.firstChild);
|
|
1608
|
-
const mapCopy = new maplibre.Map({
|
|
1609
|
-
container,
|
|
1610
|
-
center: geoCenter,
|
|
1611
|
-
zoom: this.map.maplibreMap.getZoom(),
|
|
1612
|
-
style: { ...this.map.maplibreMap.getStyle(), transition: { delay: 0, duration: 0 } },
|
|
1613
|
-
bearing: this.map.maplibreMap.getBearing(),
|
|
1614
|
-
pitch: this.map.maplibreMap.getPitch(),
|
|
1615
|
-
interactive: false,
|
|
1616
|
-
attributionControl: false,
|
|
1617
|
-
fadeDuration: 0,
|
|
1618
|
-
preserveDrawingBuffer: true,
|
|
1619
|
-
transformRequest: this.transformMapRequest.bind(this)
|
|
1620
|
-
});
|
|
1621
|
-
mapCopy.on("styleimagemissing", this.handleMissingImage.bind(this));
|
|
1622
|
-
return new Promise((resolve) => {
|
|
1623
|
-
mapCopy.once("load", () => {
|
|
1624
|
-
Object.keys(this.map.maplibreMap.style.sourceCaches).forEach((sourceId) => {
|
|
1625
|
-
mapCopy.style.sourceCaches[sourceId]._state.stateChanges = this.map.maplibreMap.style.sourceCaches[sourceId]._state.state;
|
|
1626
|
-
});
|
|
1627
|
-
mapCopy._update();
|
|
1628
|
-
setTimeout(() => resolve([container, mapCopy]), 500);
|
|
1629
|
-
});
|
|
1630
|
-
});
|
|
1631
|
-
}
|
|
1632
|
-
destroyMapCopy(container, map) {
|
|
1633
|
-
this.setDevicePixelRatio(this.nativePixelRatio);
|
|
1634
|
-
map.remove();
|
|
1635
|
-
container.parentNode.removeChild(container);
|
|
1636
|
-
}
|
|
1637
|
-
createExportCanvas(container, mapCanvas) {
|
|
1638
|
-
const canvasContainer = container.getElementsByClassName("maplibregl-canvas-container")[0];
|
|
1639
|
-
const overlayCanvas = document.createElement("canvas");
|
|
1640
|
-
overlayCanvas.id = randomId("overlay");
|
|
1641
|
-
overlayCanvas.width = mapCanvas.width;
|
|
1642
|
-
overlayCanvas.height = mapCanvas.height;
|
|
1643
|
-
overlayCanvas.style.position = "absolute";
|
|
1644
|
-
overlayCanvas.style.width = mapCanvas.style.width;
|
|
1645
|
-
overlayCanvas.style.height = mapCanvas.style.height;
|
|
1646
|
-
canvasContainer.appendChild(overlayCanvas);
|
|
1647
|
-
return overlayCanvas;
|
|
1648
|
-
}
|
|
1649
|
-
setDevicePixelRatio(pixelRatio) {
|
|
1650
|
-
Object.defineProperty(window, "devicePixelRatio", {
|
|
1651
|
-
get: () => pixelRatio
|
|
1652
|
-
});
|
|
1653
|
-
}
|
|
1654
|
-
async handleMissingImage(e) {
|
|
1655
|
-
const imageInfo = this.map.imageRegistry.getImage(e.id);
|
|
1656
|
-
if (imageInfo === this.map.imageRegistry.unknownImage) {
|
|
1657
|
-
console.error(`Map ${this.map.id}: Image '${e.id}' not registered`);
|
|
1658
|
-
}
|
|
1659
|
-
if (!imageInfo.image.complete) {
|
|
1660
|
-
imageInfo.image.onload = () => {
|
|
1661
|
-
this.map.maplibreMap.updateImage(e.id, imageInfo.image);
|
|
1662
|
-
this.map.maplibreMap.redraw();
|
|
1663
|
-
};
|
|
1664
|
-
}
|
|
1665
|
-
this.map.maplibreMap.addImage(e.id, imageInfo.image, {
|
|
1666
|
-
pixelRatio: imageInfo.pixelDensity,
|
|
1667
|
-
sdf: imageInfo.recolor
|
|
1668
|
-
});
|
|
1669
|
-
}
|
|
1670
|
-
transformMapRequest(url, _resourceType) {
|
|
1671
|
-
if (this.map.context.flowClient.accessToken && url.startsWith(this.map.context.flowClient.baseUrl)) {
|
|
1672
|
-
return {
|
|
1673
|
-
url,
|
|
1674
|
-
headers: { Authorization: `Bearer ${this.map.context.flowClient.accessToken}` }
|
|
1675
|
-
};
|
|
1676
|
-
} else {
|
|
1677
|
-
return { url };
|
|
1678
|
-
}
|
|
1679
|
-
}
|
|
1680
|
-
};
|
|
1681
|
-
__publicField$3(_MapExporter, "defaultOptions", {
|
|
1682
|
-
name: "map",
|
|
1683
|
-
width: 297,
|
|
1684
|
-
height: 210,
|
|
1685
|
-
dpmm: 12,
|
|
1686
|
-
format: "png"
|
|
1687
|
-
});
|
|
1688
|
-
let MapExporter = _MapExporter;
|
|
1689
|
-
|
|
1690
|
-
var __defProp$2 = Object.defineProperty;
|
|
1691
|
-
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1692
|
-
var __publicField$2 = (obj, key, value) => {
|
|
1693
|
-
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1694
|
-
return value;
|
|
1695
|
-
};
|
|
1696
|
-
class ExportPlugin extends MapPluginBase {
|
|
1697
|
-
constructor(pluginManager) {
|
|
1698
|
-
super(pluginManager);
|
|
1699
|
-
__publicField$2(this, "name", "ExportPlugin");
|
|
1700
|
-
}
|
|
1701
|
-
exportMap(options) {
|
|
1702
|
-
const mapExporter = new MapExporter(this.map);
|
|
1703
|
-
return mapExporter.export(options);
|
|
1704
|
-
}
|
|
1705
|
-
}
|
|
1706
|
-
|
|
1707
|
-
var __defProp$1 = Object.defineProperty;
|
|
1708
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1709
|
-
var __publicField$1 = (obj, key, value) => {
|
|
1710
|
-
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1711
|
-
return value;
|
|
1712
|
-
};
|
|
1713
|
-
class HoverEffectPlugin extends MapPluginBase {
|
|
1714
|
-
constructor(pluginManager) {
|
|
1715
|
-
super(pluginManager);
|
|
1716
|
-
__publicField$1(this, "hoveredFeature", null);
|
|
1717
|
-
__publicField$1(this, "name", "HoverEffectPlugin");
|
|
1718
|
-
}
|
|
1719
|
-
handleMouseMove(event) {
|
|
1720
|
-
const hoveredFeature = event.features[0];
|
|
1721
|
-
if (hoveredFeature) {
|
|
1722
|
-
this.map.maplibreMap._container.classList.add("feature-hovered");
|
|
1723
|
-
} else {
|
|
1724
|
-
this.map.maplibreMap._container.classList.remove("feature-hovered");
|
|
1725
|
-
}
|
|
1726
|
-
if (!this.compareFeatures(hoveredFeature, this.hoveredFeature)) {
|
|
1727
|
-
this.clearHover();
|
|
1728
|
-
if (isFeatureWithId(hoveredFeature) && isDefined(this.map.getSource(hoveredFeature.source)?.featureId)) {
|
|
1729
|
-
this.map.setFeatureState(hoveredFeature, { hover: true }, false);
|
|
1730
|
-
this.hoveredFeature = hoveredFeature;
|
|
1731
|
-
}
|
|
1732
|
-
}
|
|
1733
|
-
}
|
|
1734
|
-
handleMouseOut(event) {
|
|
1735
|
-
this.clearHover();
|
|
1736
|
-
}
|
|
1737
|
-
handleSetExclusivePlugin(exclusivePlugins) {
|
|
1738
|
-
if (exclusivePlugins.length) {
|
|
1739
|
-
this.clearHover();
|
|
1740
|
-
this.map.maplibreMap._container.classList.remove("feature-hovered");
|
|
1741
|
-
}
|
|
1742
|
-
}
|
|
1743
|
-
compareFeatures(f1, f2) {
|
|
1744
|
-
if (f1 === f2) {
|
|
1745
|
-
return true;
|
|
1746
|
-
}
|
|
1747
|
-
if (isObject(f1) && isObject(f2)) {
|
|
1748
|
-
return f1.id == f2.id && f1.source === f2.source && f1.sourceLayer == f2.sourceLayer;
|
|
1749
|
-
}
|
|
1750
|
-
return false;
|
|
1751
|
-
}
|
|
1752
|
-
clearHover() {
|
|
1753
|
-
if (this.hoveredFeature && this.map.getSource(this.hoveredFeature.source)) {
|
|
1754
|
-
this.map.removeFeatureState(this.hoveredFeature, "hover", false);
|
|
1755
|
-
this.hoveredFeature = null;
|
|
1756
|
-
}
|
|
1757
|
-
}
|
|
1758
|
-
}
|
|
1759
|
-
|
|
1760
|
-
var __defProp = Object.defineProperty;
|
|
1761
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1762
|
-
var __publicField = (obj, key, value) => {
|
|
1763
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1764
|
-
return value;
|
|
1765
|
-
};
|
|
1766
|
-
const debug = Debug("flow:url-sync-plugin");
|
|
1767
|
-
class UrlSyncPlugin extends MapPluginBase {
|
|
1768
|
-
constructor(pluginManager) {
|
|
1769
|
-
super(pluginManager);
|
|
1770
|
-
__publicField(this, "name", "UrlSyncPlugin");
|
|
1771
|
-
}
|
|
1772
|
-
initialize() {
|
|
1773
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
1774
|
-
const hash = searchParams.get(this.map.id);
|
|
1775
|
-
if (hash) {
|
|
1776
|
-
const center = this.hashToMapState(hash);
|
|
1777
|
-
debug("Setting map position from URL", center);
|
|
1778
|
-
this.map.setCenter(center);
|
|
1779
|
-
}
|
|
1780
|
-
}
|
|
1781
|
-
handleMoveEnd(event) {
|
|
1782
|
-
const center = this.mapStateToHash(this.map.getCenter());
|
|
1783
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
1784
|
-
searchParams.set(this.map.id, center);
|
|
1785
|
-
const newUrl = `${location.pathname}?${searchParams.toString()}`;
|
|
1786
|
-
debug("Updating URL with map position", center);
|
|
1787
|
-
window.history.replaceState({}, "", newUrl);
|
|
1788
|
-
}
|
|
1789
|
-
mapStateToHash(mapCenter) {
|
|
1790
|
-
const state = {
|
|
1791
|
-
z: mapCenter.zoom.toFixed(3),
|
|
1792
|
-
x: mapCenter.lng.toFixed(3),
|
|
1793
|
-
y: mapCenter.lat.toFixed(3),
|
|
1794
|
-
pitch: mapCenter.pitch.toFixed(1),
|
|
1795
|
-
bearing: mapCenter.bearing.toFixed(1)
|
|
1796
|
-
};
|
|
1797
|
-
return `${state.z}_${state.x}_${state.y}_${state.pitch}_${state.bearing}`;
|
|
1798
|
-
}
|
|
1799
|
-
hashToMapState(hash) {
|
|
1800
|
-
const [zoom, x, y, pitch, bearing] = hash.split("_");
|
|
1801
|
-
return {
|
|
1802
|
-
lng: +x,
|
|
1803
|
-
lat: +y,
|
|
1804
|
-
zoom: +zoom,
|
|
1805
|
-
pitch: +pitch,
|
|
1806
|
-
bearing: +bearing
|
|
1807
|
-
};
|
|
1808
|
-
}
|
|
1809
|
-
}
|
|
1810
|
-
|
|
1811
|
-
export { AnnotationEvent, AnnotationPlugin, DataJoin, DataJoinPlugin, ExportPlugin, HoverEffectPlugin, MapPluginBase, PopupPlugin, SelectionEvent, SelectionPlugin, UrlSyncPlugin };
|
|
1
|
+
export { AnnotationEvent } from './annotations/annotation.events.mjs';
|
|
2
|
+
export { AnnotationPlugin } from './annotations/annotation.plugin.mjs';
|
|
3
|
+
export { DataJoin, DataJoinPlugin } from './data-join.plugin.mjs';
|
|
4
|
+
export { ExportPlugin } from './export/export.plugin.mjs';
|
|
5
|
+
export { HoverEffectPlugin } from './hover-effect.plugin.mjs';
|
|
6
|
+
export { MapPluginBase } from './map-plugin-base.mjs';
|
|
7
|
+
export { PluginManager } from './plugin-manager.mjs';
|
|
8
|
+
export { PopupPlugin } from './popup.plugin.mjs';
|
|
9
|
+
export { SelectionEvent } from './selection/selection.events.mjs';
|
|
10
|
+
export { SelectionPlugin } from './selection/selection.plugin.mjs';
|
|
11
|
+
export { UrlSyncPlugin } from './url-sync.plugin.mjs';
|