@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.
Files changed (89) hide show
  1. package/README.md +1 -64
  2. package/dist/index.d.mts +36 -31
  3. package/dist/index.d.ts +36 -31
  4. package/dist/index.mjs +20 -3249
  5. package/dist/lib/context/context-registry.mjs +63 -0
  6. package/dist/lib/context/debugger.mjs +240 -0
  7. package/dist/lib/context/flow-context.mjs +61 -0
  8. package/dist/lib/context/global-state.mjs +70 -0
  9. package/dist/lib/context/map-registry.mjs +59 -0
  10. package/dist/lib/context/query-registry.mjs +53 -0
  11. package/dist/lib/errors/flow-error.mjs +10 -0
  12. package/dist/lib/errors/flow-expression-error.mjs +14 -0
  13. package/dist/lib/errors/flow-map-error.mjs +9 -0
  14. package/dist/lib/expressions/expression-parser.mjs +198 -0
  15. package/dist/lib/expressions/functions/from-palette.mjs +75 -0
  16. package/dist/lib/expressions/functions/regex.mjs +25 -0
  17. package/dist/lib/expressions/functions/state.mjs +25 -0
  18. package/dist/lib/expressions/parser-helpers.mjs +37 -0
  19. package/dist/lib/expressions/reactive-expression.mjs +253 -0
  20. package/dist/lib/map/flow-core-map.mjs +749 -0
  21. package/dist/lib/map/plugins/annotations/annotation-layers.mjs +163 -0
  22. package/dist/lib/map/plugins/annotations/annotation.events.mjs +27 -0
  23. package/dist/lib/map/plugins/annotations/annotation.plugin.mjs +498 -0
  24. package/dist/lib/map/plugins/annotations/maplibre-gl-draw-circle/lib/modes/DirectModeOverride.mjs +67 -0
  25. package/dist/lib/map/plugins/annotations/maplibre-gl-draw-circle/lib/modes/DragCircleMode.mjs +65 -0
  26. package/dist/lib/map/plugins/annotations/maplibre-gl-draw-circle/lib/utils/create_supplementary_points_circle.mjs +15 -0
  27. package/dist/lib/map/plugins/annotations/maplibre-gl-draw-circle/lib/utils/drag_pan.mjs +20 -0
  28. package/dist/lib/map/plugins/data-join.plugin.mjs +173 -0
  29. package/dist/lib/map/plugins/export/export.plugin.mjs +21 -0
  30. package/dist/lib/map/plugins/export/map-exporter.mjs +177 -0
  31. package/dist/lib/map/plugins/hover-effect.plugin.mjs +58 -0
  32. package/dist/lib/map/plugins/index.d.mts +37 -72
  33. package/dist/lib/map/plugins/index.d.ts +37 -72
  34. package/dist/lib/map/plugins/index.mjs +11 -1811
  35. package/dist/lib/map/plugins/keyboard-shortcut-manager.mjs +120 -0
  36. package/dist/lib/map/plugins/map-plugin-base.mjs +25 -0
  37. package/dist/lib/map/plugins/plugin-manager.mjs +135 -0
  38. package/dist/lib/map/plugins/popup.plugin.mjs +55 -0
  39. package/dist/lib/map/plugins/selection/selection.events.mjs +21 -0
  40. package/dist/lib/map/plugins/selection/selection.plugin.mjs +136 -0
  41. package/dist/lib/map/plugins/selection/source-selection.mjs +156 -0
  42. package/dist/lib/map/plugins/url-sync.plugin.mjs +55 -0
  43. package/dist/lib/map/support/image-registry.mjs +82 -0
  44. package/dist/lib/map/support/map-events.mjs +71 -0
  45. package/dist/lib/map/support/map-feature-stream.mjs +158 -0
  46. package/dist/lib/map/support/map-popup.mjs +159 -0
  47. package/dist/lib/map/types.mjs +7 -0
  48. package/dist/lib/map-style/map-data-source.mjs +192 -0
  49. package/dist/lib/map-style/map-layer-style-builder-generated.mjs +1307 -0
  50. package/dist/lib/map-style/map-layer-style-builder.mjs +86 -0
  51. package/dist/lib/map-style/map-layer.mjs +223 -0
  52. package/dist/lib/map-style/map-style.mjs +178 -0
  53. package/dist/lib/queries/async-committer.mjs +30 -0
  54. package/dist/lib/queries/query.mjs +172 -0
  55. package/dist/lib/state-store/decorators.mjs +83 -0
  56. package/dist/lib/state-store/state-store.mjs +534 -0
  57. package/dist/lib/state-store/utils.mjs +7 -0
  58. package/dist/lib/utils/announce.mjs +12 -0
  59. package/dist/lib/utils/assert.mjs +12 -0
  60. package/dist/{shared/flow-rdf-core.187cb345.mjs → lib/utils/debounce.mjs} +3 -39
  61. package/dist/lib/utils/decorators.mjs +59 -0
  62. package/dist/lib/utils/deferred.mjs +11 -0
  63. package/dist/lib/utils/ensure-array.mjs +16 -0
  64. package/dist/{shared/flow-rdf-core.1f0901c5.mjs → lib/utils/feature-type-checks.mjs} +2 -2
  65. package/dist/lib/utils/functional.mjs +22 -0
  66. package/dist/lib/utils/global.mjs +18 -0
  67. package/dist/lib/utils/index.mjs +8 -5
  68. package/dist/lib/utils/random-id.mjs +9 -0
  69. package/dist/lib/utils/string-utils.mjs +3 -0
  70. package/dist/lib/utils/throttle.mjs +20 -0
  71. package/dist/{shared/flow-rdf-core.25e5f6d7.mjs → lib/utils/type-checks.mjs} +1 -26
  72. package/dist/lib/utils/watchable-promise.mjs +55 -0
  73. package/dist/package.json.mjs +3 -0
  74. package/dist/shared/{flow-rdf-core.4dde996e.d.cts → flow-rdf-core.8b5acf14.d.mts} +1315 -172
  75. package/dist/shared/{flow-rdf-core.4dde996e.d.ts → flow-rdf-core.8b5acf14.d.ts} +1315 -172
  76. package/package.json +4 -8
  77. package/dist/index.cjs +0 -3316
  78. package/dist/index.d.cts +0 -90
  79. package/dist/lib/map/plugins/index.cjs +0 -1851
  80. package/dist/lib/map/plugins/index.d.cts +0 -345
  81. package/dist/lib/utils/index.cjs +0 -48
  82. package/dist/lib/utils/index.d.cts +0 -160
  83. package/dist/shared/flow-rdf-core.06e85a6c.cjs +0 -1394
  84. package/dist/shared/flow-rdf-core.4dde996e.d.mts +0 -1916
  85. package/dist/shared/flow-rdf-core.55c169ca.cjs +0 -150
  86. package/dist/shared/flow-rdf-core.63162669.d.cts +0 -10
  87. package/dist/shared/flow-rdf-core.65045caf.mjs +0 -1360
  88. package/dist/shared/flow-rdf-core.a82b9be4.cjs +0 -34
  89. package/dist/shared/flow-rdf-core.f50908f0.cjs +0 -102
package/dist/index.cjs DELETED
@@ -1,3316 +0,0 @@
1
- 'use strict';
2
-
3
- const mobx = require('mobx');
4
- const Debug = require('debug');
5
- const flowEngineClient = require('@emuanalytics/flow-engine-client');
6
- const randomId = require('./shared/flow-rdf-core.f50908f0.cjs');
7
- const mapFeatureStream = require('./shared/flow-rdf-core.06e85a6c.cjs');
8
- const maplibre = require('@emuanalytics/maplibre-gl');
9
- const EventEmitter = require('eventemitter3');
10
- const mobxUtils = require('mobx-utils');
11
- const throttle = require('./shared/flow-rdf-core.55c169ca.cjs');
12
- const lzString = require('lz-string');
13
- require('nanoid');
14
- require('@emuanalytics/maplibre-gl-style-spec');
15
- require('parsimmon');
16
- require('colorbrewer');
17
-
18
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
19
-
20
- function _interopNamespaceCompat(e) {
21
- if (e && typeof e === 'object' && 'default' in e) return e;
22
- const n = Object.create(null);
23
- if (e) {
24
- for (const k in e) {
25
- n[k] = e[k];
26
- }
27
- }
28
- n.default = e;
29
- return n;
30
- }
31
-
32
- const mobx__namespace = /*#__PURE__*/_interopNamespaceCompat(mobx);
33
- const Debug__default = /*#__PURE__*/_interopDefaultCompat(Debug);
34
- const maplibre__default = /*#__PURE__*/_interopDefaultCompat(maplibre);
35
- const EventEmitter__default = /*#__PURE__*/_interopDefaultCompat(EventEmitter);
36
- const lzString__default = /*#__PURE__*/_interopDefaultCompat(lzString);
37
-
38
- const version = "4.0.3";
39
-
40
- const CONSOLE_HIGHLIGHT_STYLE$1 = `
41
- padding: 2px 4px;
42
- border-radius: 2px;
43
- background: #389DFF;
44
- color: white;`;
45
- function announce() {
46
- console.log("%cFlo.w RDF Core v%s", CONSOLE_HIGHLIGHT_STYLE$1, version);
47
- }
48
-
49
- const mockGlobal = {};
50
- function getGlobal() {
51
- if (typeof globalThis !== "undefined") {
52
- return globalThis;
53
- }
54
- if (typeof window !== "undefined") {
55
- return window;
56
- }
57
- if (typeof global !== "undefined") {
58
- return global;
59
- }
60
- if (typeof self !== "undefined") {
61
- return self;
62
- }
63
- return mockGlobal;
64
- }
65
-
66
- var __accessCheck = (obj, member, msg) => {
67
- if (!member.has(obj))
68
- throw TypeError("Cannot " + msg);
69
- };
70
- var __privateGet = (obj, member, getter) => {
71
- __accessCheck(obj, member, "read from private field");
72
- return getter ? getter.call(obj) : member.get(obj);
73
- };
74
- var __privateAdd = (obj, member, value) => {
75
- if (member.has(obj))
76
- throw TypeError("Cannot add the same private member more than once");
77
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
78
- };
79
- var __privateSet = (obj, member, value, setter) => {
80
- __accessCheck(obj, member, "write to private field");
81
- setter ? setter.call(obj, value) : member.set(obj, value);
82
- return value;
83
- };
84
- var _value, _settled, _status;
85
- class WatchablePromise extends Promise {
86
- constructor(executor) {
87
- super((resolve, reject) => {
88
- executor(
89
- (value) => {
90
- resolve(value);
91
- __privateSet(this, _value, value);
92
- __privateSet(this, _settled, true);
93
- __privateSet(this, _status, "fulfilled");
94
- },
95
- (reason) => {
96
- reject(reason);
97
- __privateSet(this, _settled, true);
98
- __privateSet(this, _status, "rejected");
99
- }
100
- );
101
- });
102
- __privateAdd(this, _value, void 0);
103
- __privateAdd(this, _settled, false);
104
- __privateAdd(this, _status, "pending");
105
- }
106
- get settled() {
107
- return __privateGet(this, _settled);
108
- }
109
- get status() {
110
- return __privateGet(this, _status);
111
- }
112
- get value() {
113
- return __privateGet(this, _value);
114
- }
115
- }
116
- _value = new WeakMap();
117
- _settled = new WeakMap();
118
- _status = new WeakMap();
119
-
120
- function deferred() {
121
- let methods;
122
- const promise = new WatchablePromise((resolve, reject) => {
123
- methods = { resolve, reject };
124
- });
125
- return Object.assign(promise, methods);
126
- }
127
-
128
- var __defProp$c = Object.defineProperty;
129
- var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
130
- var __publicField$c = (obj, key, value) => {
131
- __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
132
- return value;
133
- };
134
- const FLOW_GLOBAL = "FDBG";
135
- const CONSOLE_HIGHLIGHT_STYLE = `
136
- padding: 2px 4px;
137
- border-radius: 2px;
138
- background: #389DFF;
139
- color: white;`;
140
- const CONSOLE_BOLD_STYLE = `font-weight: bold;`;
141
- class Debugger {
142
- /**
143
- * Constructs a new Flo.w debugger instance.
144
- *
145
- * A new Flo.w debugger will be created automatically if the `enableDebug` option is
146
- * specified when initializing a Flo.w context.
147
- *
148
- * @param context Flo.w context ID.
149
- */
150
- constructor(context) {
151
- this.context = context;
152
- __publicField$c(this, "spyDisposer");
153
- __publicField$c(this, "watchDisposers", {});
154
- }
155
- /**
156
- * Install a 'watch' for the specified context state property path.
157
- *
158
- * @param path Context state property path.
159
- */
160
- watch(path) {
161
- if (!this.watchDisposers[path]) {
162
- this.watchDisposers[path] = this.context.state.autorun(() => this.logStateValue(path));
163
- }
164
- }
165
- /**
166
- * Remove a previously-installed 'watch' for the specified context state property path.
167
- *
168
- * @param path Context state property path.
169
- */
170
- unwatch(path) {
171
- if (path) {
172
- if (this.watchDisposers[path]) {
173
- this.watchDisposers[path]();
174
- delete this.watchDisposers[path];
175
- }
176
- } else {
177
- Object.keys(this.watchDisposers).forEach((key) => this.watchDisposers[key]());
178
- this.watchDisposers = {};
179
- }
180
- }
181
- /**
182
- * Set a Flo.w context state property.
183
- *
184
- * @param path Context state property path
185
- * @param value New value to set
186
- */
187
- set(path, value) {
188
- this.context.state.set(path, value);
189
- }
190
- /**
191
- * Read the value of a Flo.w context state property.
192
- *
193
- * @param keyOrPath Context state property path.
194
- * @returns The context state property value.
195
- */
196
- get(keyOrPath) {
197
- if (randomId.isUndefined(keyOrPath)) {
198
- keyOrPath = [];
199
- } else if (typeof keyOrPath === "string") {
200
- if (keyOrPath.startsWith("$")) {
201
- keyOrPath = keyOrPath.slice(1);
202
- }
203
- return this.get(keyOrPath.split("."));
204
- }
205
- let value = this.context.state;
206
- const path = [...keyOrPath];
207
- while (path.length > 0) {
208
- if (value == null) {
209
- value = void 0;
210
- break;
211
- }
212
- const key = path.shift();
213
- value = value[key];
214
- }
215
- return toJSHelper(value, {});
216
- }
217
- /**
218
- * Enable verbose debugging of all reactive updates.
219
- */
220
- spy() {
221
- this.unspy();
222
- this.spyDisposer = mobx__namespace.spy(this.spyListener.bind(this));
223
- }
224
- /**
225
- * Disable verbose debugging of all reactive updates.
226
- */
227
- unspy() {
228
- if (this.spyDisposer) {
229
- this.spyDisposer();
230
- this.spyDisposer = void 0;
231
- }
232
- }
233
- /**
234
- * Get a registered map instance by ID.
235
- */
236
- maps(mapId) {
237
- if (!mapId) {
238
- return Array.from(this.context.maps._maps.keys());
239
- }
240
- const mapPromise = this.context.maps.getMap(mapId);
241
- return mapPromise?.value;
242
- }
243
- /**
244
- * Get a registered reactive query by ID.
245
- */
246
- queries(queryId) {
247
- if (!queryId) {
248
- return Array.from(this.context.queries._queries.keys());
249
- }
250
- const queryPromise = this.context.queries.getQuery(queryId);
251
- return queryPromise?.value;
252
- }
253
- spyListener(event) {
254
- console.log(`%cspy`, CONSOLE_HIGHLIGHT_STYLE, event);
255
- }
256
- logStateValue(path) {
257
- const value = toJSHelper(this.context.state.get(path), { recurseEverything: false });
258
- console.log(`%cwatch%c %s`, CONSOLE_HIGHLIGHT_STYLE, CONSOLE_BOLD_STYLE, path, value);
259
- }
260
- }
261
- function installGlobalDebugger(dbg) {
262
- console.log(
263
- `%cFlow.w RDF Debbugger`,
264
- CONSOLE_HIGHLIGHT_STYLE,
265
- `Enabled for context '${dbg.context.id}' - access using ${FLOW_GLOBAL} in web developer console.`
266
- );
267
- const g = typeof global !== "undefined" ? global : window;
268
- g[FLOW_GLOBAL] = g[FLOW_GLOBAL] || {
269
- context: dbg.context,
270
- watch: dbg.watch.bind(dbg),
271
- unwatch: dbg.unwatch.bind(dbg),
272
- set: dbg.set.bind(dbg),
273
- get: dbg.get.bind(dbg),
274
- spy: dbg.spy.bind(dbg),
275
- maps: dbg.maps.bind(dbg),
276
- queries: dbg.queries.bind(dbg),
277
- unspy: dbg.unspy.bind(dbg)
278
- };
279
- }
280
- function cache(map, key, value, options) {
281
- if (options.detectCycles)
282
- map.set(key, value);
283
- return value;
284
- }
285
- function getPlainObjectKeys(object) {
286
- const enumerables = /* @__PURE__ */ new Set();
287
- for (const key in object)
288
- enumerables.add(key);
289
- Object.getOwnPropertySymbols(object).forEach(function(k) {
290
- if (Object.getOwnPropertyDescriptor(object, k).enumerable)
291
- enumerables.add(k);
292
- });
293
- return Array.from(enumerables);
294
- }
295
- function toJSHelper(source, options, __alreadySeen = null) {
296
- if (!options.recurseEverything && !mobx.isObservable(source))
297
- return source;
298
- if (typeof source !== "object")
299
- return source;
300
- if (source === null)
301
- return null;
302
- if (source instanceof Date)
303
- return source;
304
- if (mobx.isComputed(source)) {
305
- try {
306
- const value = source.get();
307
- return { computedValue: value };
308
- } catch (e) {
309
- return { computedValueException: e.message };
310
- }
311
- }
312
- const detectCycles = options.detectCycles === true;
313
- if (detectCycles && source !== null && __alreadySeen.has(source)) {
314
- return __alreadySeen.get(source);
315
- }
316
- if (mobx.isObservableArray(source) || Array.isArray(source)) {
317
- const res_1 = cache(__alreadySeen, source, [], options);
318
- const toAdd = source.map(function(value) {
319
- return toJSHelper(value, options, __alreadySeen);
320
- });
321
- res_1.length = toAdd.length;
322
- for (let i = 0, l = toAdd.length; i < l; i++)
323
- res_1[i] = toAdd[i];
324
- return res_1;
325
- }
326
- if (mobx.isObservableSet(source) || Object.getPrototypeOf(source) === Set.prototype) {
327
- if (options.exportMapsAsObjects === false) {
328
- const res_2 = cache(__alreadySeen, source, /* @__PURE__ */ new Set(), options);
329
- source.forEach(function(value) {
330
- res_2.add(toJSHelper(value, options, __alreadySeen));
331
- });
332
- return res_2;
333
- } else {
334
- const res_3 = cache(__alreadySeen, source, [], options);
335
- source.forEach(function(value) {
336
- res_3.push(toJSHelper(value, options, __alreadySeen));
337
- });
338
- return res_3;
339
- }
340
- }
341
- if (mobx.isObservableMap(source) || Object.getPrototypeOf(source) === Map.prototype) {
342
- if (options.exportMapsAsObjects === false) {
343
- const res_4 = cache(__alreadySeen, source, /* @__PURE__ */ new Map(), options);
344
- source.forEach(function(value, key) {
345
- res_4.set(key, toJSHelper(value, options, __alreadySeen));
346
- });
347
- return res_4;
348
- } else {
349
- const res_5 = cache(__alreadySeen, source, {}, options);
350
- source.forEach(function(value, key) {
351
- res_5[key] = toJSHelper(value, options, __alreadySeen);
352
- });
353
- return res_5;
354
- }
355
- }
356
- const res = cache(__alreadySeen, source, {}, options);
357
- getPlainObjectKeys(source).forEach(function(key) {
358
- res[key] = toJSHelper(source[key], options, __alreadySeen);
359
- });
360
- return res;
361
- }
362
-
363
- var __defProp$b = Object.defineProperty;
364
- var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
365
- var __publicField$b = (obj, key, value) => {
366
- __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
367
- return value;
368
- };
369
- const debug$4 = Debug__default("flow:map-registry");
370
- class MapRegistry {
371
- constructor() {
372
- __publicField$b(this, "_maps", /* @__PURE__ */ new Map());
373
- }
374
- /**
375
- * Register a Flo.w map.
376
- *
377
- * @param id Map ID.
378
- * @param map Map to register.
379
- */
380
- registerMap(map) {
381
- debug$4(`Registering map '${map.id}'`);
382
- if (!this._maps.get(map.id)) {
383
- this._maps.set(map.id, deferred());
384
- }
385
- const deferredMap = this._maps.get(map.id);
386
- deferredMap.resolve(map);
387
- return map;
388
- }
389
- /**
390
- * Un-register a Flo.w map.
391
- *
392
- * @param id Map ID.
393
- */
394
- unregisterMap(map) {
395
- debug$4(`Unregistering map '${map.id}'`);
396
- this._maps.delete(map.id);
397
- }
398
- /**
399
- * Retrieve the specified map.
400
- *
401
- * This method returns a promise that resolves when the map has been initialized.
402
- *
403
- * @param id Map ID.
404
- */
405
- getMap(id) {
406
- if (!this._maps.get(id)) {
407
- this._maps.set(id, deferred());
408
- }
409
- const deferredMap = this._maps.get(id);
410
- return deferredMap;
411
- }
412
- }
413
-
414
- var __defProp$a = Object.defineProperty;
415
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
416
- var __publicField$a = (obj, key, value) => {
417
- __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
418
- return value;
419
- };
420
- const debug$3 = Debug__default("flow:query-registry");
421
- class QueryRegistry {
422
- constructor() {
423
- __publicField$a(this, "_queries", /* @__PURE__ */ new Map());
424
- }
425
- /**
426
- * Register a Flo.w reactive query.
427
- *
428
- * @param query Query to register.
429
- */
430
- registerQuery(query) {
431
- debug$3(`Registering query '${query.id}'`);
432
- if (!this._queries.get(query.id)) {
433
- this._queries.set(query.id, deferred());
434
- }
435
- const deferredQuery = this._queries.get(query.id);
436
- deferredQuery.resolve(query);
437
- }
438
- /**
439
- * Un-register a Flo.w reactive query.
440
- *
441
- * @param query Query to unregister.
442
- */
443
- unregisterQuery(query) {
444
- debug$3(`Unregistering map '${query.id}'`);
445
- this._queries.delete(query.id);
446
- }
447
- /**
448
- * Retrieve the specified query.
449
- *
450
- * This method returns a promise that resolves when the query has been initialized.
451
- *
452
- * @param id Map ID.
453
- */
454
- getQuery(id) {
455
- if (!this._queries.get(id)) {
456
- this._queries.set(id, deferred());
457
- }
458
- const deferredQuery = this._queries.get(id);
459
- return deferredQuery;
460
- }
461
- }
462
-
463
- var __defProp$9 = Object.defineProperty;
464
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
465
- var __publicField$9 = (obj, key, value) => {
466
- __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
467
- return value;
468
- };
469
- const DEFAULT_FLOW_HOST = "https://flow.emu-analytics.net";
470
- const DEFAULT_CONTEXT_ID = "default";
471
- const _FlowContext = class _FlowContext {
472
- /**
473
- * Constructs a new `FlowCoreContext`.
474
- *
475
- * Use [[ContextRegistry.initializeContext]] to create an instance of `FlowCoreContext`.
476
- *
477
- * @param id The ID of the context.
478
- * @param host The Flo.w Engine host URL.
479
- * @param apiKey The Flo.w Engine API key.
480
- * @param enableDebug Set to `true` to enable the debugger.
481
- */
482
- constructor(options) {
483
- __publicField$9(this, "_options");
484
- __publicField$9(this, "flowClient");
485
- __publicField$9(this, "state");
486
- __publicField$9(this, "maps", new MapRegistry());
487
- __publicField$9(this, "queries", new QueryRegistry());
488
- /** The Flo.w debugger. Available as `window.FDBG` in the browser's web developer console. */
489
- __publicField$9(this, "debugger");
490
- this._options = {
491
- ..._FlowContext._defaultOptions,
492
- ...options
493
- };
494
- if (!options.state.initialized) {
495
- options.state.initialize();
496
- }
497
- this.flowClient = new flowEngineClient.Client(this._options.host, this._options.apiKey);
498
- this.state = options.state;
499
- if (options.enableDebug) {
500
- this.debugger = new Debugger(this);
501
- installGlobalDebugger(this.debugger);
502
- }
503
- }
504
- get id() {
505
- return this._options.id;
506
- }
507
- evaluateExpression(expr) {
508
- const expression = new mapFeatureStream.ReactiveExpression(expr);
509
- expression.bindState(this.state);
510
- return expression.value;
511
- }
512
- };
513
- __publicField$9(_FlowContext, "_defaultOptions", {
514
- id: DEFAULT_CONTEXT_ID,
515
- host: DEFAULT_FLOW_HOST,
516
- enableDebug: false
517
- });
518
- let FlowContext = _FlowContext;
519
-
520
- var __defProp$8 = Object.defineProperty;
521
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
522
- var __publicField$8 = (obj, key, value) => {
523
- __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
524
- return value;
525
- };
526
- const debug$2 = Debug__default("flow:context-registry");
527
- const _ContextRegistry = class _ContextRegistry {
528
- constructor() {
529
- __publicField$8(this, "_contexts", /* @__PURE__ */ new Map());
530
- }
531
- /**
532
- * Initialize a new Flo.w context.
533
- *
534
- * @param options Context options.
535
- */
536
- initializeContext(options) {
537
- options = { ..._ContextRegistry._defaultOptions, ...options };
538
- debug$2(`Initializing context '${options.id}'`, options);
539
- if (!this._contexts.get(options.id)) {
540
- this._contexts.set(options.id, {
541
- initialized: false,
542
- deferred: deferred()
543
- });
544
- }
545
- const registryEntry = this._contexts.get(options.id);
546
- if (registryEntry.initialized) {
547
- console.warn(`Context '${options.id}' has already been initialized. Skipping re-initialization.`);
548
- }
549
- const context = new FlowContext(options);
550
- registryEntry.initialized = true;
551
- registryEntry.deferred.resolve(context);
552
- return context;
553
- }
554
- uninitializeContext(contextId = DEFAULT_CONTEXT_ID) {
555
- if (!this._contexts.has(contextId)) {
556
- console.warn(`Context '${contextId}' has not been initialized. Skipping uninitialization.`);
557
- }
558
- debug$2(`Uninitializing context '${contextId}'`);
559
- this._contexts.delete(contextId);
560
- }
561
- getContext(id = DEFAULT_CONTEXT_ID) {
562
- if (!this._contexts.get(id)) {
563
- this._contexts.set(id, {
564
- initialized: false,
565
- deferred: deferred()
566
- });
567
- }
568
- const deferredContext = this._contexts.get(id);
569
- return deferredContext?.deferred;
570
- }
571
- };
572
- __publicField$8(_ContextRegistry, "_defaultOptions", {
573
- id: DEFAULT_CONTEXT_ID,
574
- host: "https://flow.emu-analytics.net"
575
- });
576
- let ContextRegistry = _ContextRegistry;
577
-
578
- var __defProp$7 = Object.defineProperty;
579
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
580
- var __publicField$7 = (obj, key, value) => {
581
- __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
582
- return value;
583
- };
584
- class FlowRdfCoreGlobals {
585
- constructor() {
586
- /**
587
- * FlowRdfCoreGlobals version.
588
- * Compatiblity with other versions loaded in memory as long as this version matches.
589
- * It indicates that the global state still stores similar information
590
- *
591
- * N.B: this version is unrelated to the package version.
592
- */
593
- __publicField$7(this, "version", 1);
594
- __publicField$7(this, "globalContextRegistry", new ContextRegistry());
595
- }
596
- }
597
- let canMergeGlobalState = true;
598
- let isolateCalled = false;
599
- let globalState = function() {
600
- const global = getGlobal();
601
- if (global.__flowRdfCoreInstanceCount > 0 && !global.__flowRdfCoreGlobals) {
602
- canMergeGlobalState = false;
603
- }
604
- if (global.__flowRdfCoreGlobals && global.__flowRdfCoreGlobals.version !== new FlowRdfCoreGlobals().version) {
605
- canMergeGlobalState = false;
606
- }
607
- if (!canMergeGlobalState) {
608
- setTimeout(() => {
609
- if (!isolateCalled) {
610
- throw new Error(
611
- 'There are multiple, different versions of FlowRdfCore active. Make sure FlowRdfCore is loaded only once or use `configure({ isolateGlobalState: true })`",'
612
- );
613
- }
614
- }, 1);
615
- return new FlowRdfCoreGlobals();
616
- } else if (global.__flowRdfCoreGlobals) {
617
- global.__flowRdfCoreInstanceCount += 1;
618
- return global.__flowRdfCoreGlobals;
619
- } else {
620
- global.__flowRdfCoreInstanceCount = 1;
621
- mobx.configure({
622
- enforceActions: "never"
623
- });
624
- announce();
625
- return global.__flowRdfCoreGlobals = new FlowRdfCoreGlobals();
626
- }
627
- }();
628
- function isolateGlobalState() {
629
- isolateCalled = true;
630
- if (canMergeGlobalState) {
631
- const global = getGlobal();
632
- if (--global.__flowRdfCoreInstanceCount === 0) {
633
- global.__flowRdfCoreGlobals = void 0;
634
- }
635
- globalState = new FlowRdfCoreGlobals();
636
- }
637
- }
638
- function getGlobalState() {
639
- return globalState;
640
- }
641
-
642
- var __defProp$6 = Object.defineProperty;
643
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
644
- var __publicField$6 = (obj, key, value) => {
645
- __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
646
- return value;
647
- };
648
- class MapLayerStyleBuilder {
649
- constructor() {
650
- __publicField$6(this, "_styles", /* @__PURE__ */ new Map());
651
- }
652
- static registerStyleBuilder(layerType, builder) {
653
- this._styleBuilders.set(layerType, builder);
654
- }
655
- static createStyleBuilder(layerType) {
656
- const builder = this._styleBuilders.get(layerType);
657
- if (!builder) {
658
- throw new Error(`MapLayerStyleBuilder: Unknown layer type '${layerType}'`);
659
- }
660
- return new builder();
661
- }
662
- /**
663
- * Whether this layer is displayed.
664
- *
665
- * @param value - visible value (default `true`)
666
- */
667
- visibility(value) {
668
- this.addStyle("visibility", value);
669
- return this;
670
- }
671
- /**
672
- * Create a style specification string.
673
- *
674
- * Call this method after setting all style properties
675
- * on the style builder.
676
- *
677
- * @returns Layer style specification string
678
- */
679
- build() {
680
- const styles = [];
681
- for (const [prop, value] of this._styles.entries()) {
682
- styles.push(`${prop}: ${value};`);
683
- }
684
- return styles.join("\n");
685
- }
686
- /**
687
- * Format and add style property to the style builder.
688
- */
689
- addStyle(property, value) {
690
- this._styles.set(property, this.formatValue(value));
691
- }
692
- formatValue(value) {
693
- if (isStyleExpression(value)) {
694
- return value.toString();
695
- } else if (randomId.isString(value)) {
696
- return `'${value.toString()}'`;
697
- } else if (randomId.isNumber(value)) {
698
- return value.toString();
699
- } else if (randomId.isBoolean(value)) {
700
- return (!!value).toString();
701
- } else if (randomId.isArray(value)) {
702
- return `[${value.map((v) => this.formatValue(v)).join(", ")}]`;
703
- } else {
704
- return value.toString();
705
- }
706
- }
707
- }
708
- __publicField$6(MapLayerStyleBuilder, "_styleBuilders", /* @__PURE__ */ new Map());
709
- class StyleExpression {
710
- constructor(_expr) {
711
- this._expr = _expr;
712
- __publicField$6(this, "__styleExpression", "styleexpression");
713
- }
714
- toString() {
715
- return this._expr;
716
- }
717
- }
718
- function isStyleExpression(val) {
719
- return val && val.__styleExpression;
720
- }
721
- function expr(expr2) {
722
- return new StyleExpression(expr2);
723
- }
724
-
725
- class FillLayerStyleBuilder extends MapLayerStyleBuilder {
726
- /**
727
- * Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key.
728
- *
729
- * @param value - fill-sort-key value
730
- */
731
- fillSortKey(value) {
732
- this.addStyle("fill-sort-key", value);
733
- return this;
734
- }
735
- /**
736
- * Whether or not the fill should be antialiased.
737
- *
738
- * @param value - fill-antialias value (default `true`)
739
- */
740
- fillAntialias(value) {
741
- this.addStyle("fill-antialias", value);
742
- return this;
743
- }
744
- /**
745
- * The opacity of the entire fill layer. In contrast to the `fill-color`, this value will also affect the 1px stroke around the fill, if the stroke is used.
746
- *
747
- * @param value - fill-opacity value (default `1`)
748
- */
749
- fillOpacity(value) {
750
- this.addStyle("fill-opacity", value);
751
- return this;
752
- }
753
- /**
754
- * The color of the filled part of this layer. This color can be specified as `rgba` with an alpha component and the color's opacity will not affect the opacity of the 1px stroke, if it is used.
755
- *
756
- * @param value - fill-color value (default `#000000`)
757
- */
758
- fillColor(value) {
759
- this.addStyle("fill-color", value);
760
- return this;
761
- }
762
- /**
763
- * The outline color of the fill. Matches the value of `fill-color` if unspecified.
764
- *
765
- * @param value - fill-outline-color value
766
- */
767
- fillOutlineColor(value) {
768
- this.addStyle("fill-outline-color", value);
769
- return this;
770
- }
771
- /**
772
- * The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively.
773
- *
774
- * @param value - fill-translate value in pixels (default `0,0`)
775
- */
776
- fillTranslate(value) {
777
- this.addStyle("fill-translate", value);
778
- return this;
779
- }
780
- /**
781
- * Controls the frame of reference for `fill-translate`.
782
- *
783
- * Values:
784
- * - map: The fill is translated relative to the map.
785
- * - viewport: The fill is translated relative to the viewport.
786
- *
787
- * @param value - fill-translate-anchor value (default `map`)
788
- */
789
- fillTranslateAnchor(value) {
790
- this.addStyle("fill-translate-anchor", value);
791
- return this;
792
- }
793
- /**
794
- * Name of image in sprite to use for drawing image fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). Note that zoom-dependent expressions will be evaluated only at integer zoom levels.
795
- *
796
- * @param value - fill-pattern value
797
- */
798
- fillPattern(value) {
799
- this.addStyle("fill-pattern", value);
800
- return this;
801
- }
802
- }
803
- MapLayerStyleBuilder.registerStyleBuilder("fill", FillLayerStyleBuilder);
804
- class LineLayerStyleBuilder extends MapLayerStyleBuilder {
805
- /**
806
- * The display of line endings.
807
- *
808
- * Values:
809
- * - butt: A cap with a squared-off end which is drawn to the exact endpoint of the line.
810
- * - round: A cap with a rounded end which is drawn beyond the endpoint of the line at a radius of one-half of the line's width and centered on the endpoint of the line.
811
- * - square: A cap with a squared-off end which is drawn beyond the endpoint of the line at a distance of one-half of the line's width.
812
- *
813
- * @param value - line-cap value (default `butt`)
814
- */
815
- lineCap(value) {
816
- this.addStyle("line-cap", value);
817
- return this;
818
- }
819
- /**
820
- * The display of lines when joining.
821
- *
822
- * Values:
823
- * - bevel: A join with a squared-off end which is drawn beyond the endpoint of the line at a distance of one-half of the line's width.
824
- * - round: A join with a rounded end which is drawn beyond the endpoint of the line at a radius of one-half of the line's width and centered on the endpoint of the line.
825
- * - miter: A join with a sharp, angled corner which is drawn with the outer sides beyond the endpoint of the path until they meet.
826
- *
827
- * @param value - line-join value (default `miter`)
828
- */
829
- lineJoin(value) {
830
- this.addStyle("line-join", value);
831
- return this;
832
- }
833
- /**
834
- * Used to automatically convert miter joins to bevel joins for sharp angles.
835
- *
836
- * @param value - line-miter-limit value (default `2`)
837
- */
838
- lineMiterLimit(value) {
839
- this.addStyle("line-miter-limit", value);
840
- return this;
841
- }
842
- /**
843
- * Used to automatically convert round joins to miter joins for shallow angles.
844
- *
845
- * @param value - line-round-limit value (default `1.05`)
846
- */
847
- lineRoundLimit(value) {
848
- this.addStyle("line-round-limit", value);
849
- return this;
850
- }
851
- /**
852
- * Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key.
853
- *
854
- * @param value - line-sort-key value
855
- */
856
- lineSortKey(value) {
857
- this.addStyle("line-sort-key", value);
858
- return this;
859
- }
860
- /**
861
- * The opacity at which the line will be drawn.
862
- *
863
- * @param value - line-opacity value (default `1`)
864
- */
865
- lineOpacity(value) {
866
- this.addStyle("line-opacity", value);
867
- return this;
868
- }
869
- /**
870
- * The color with which the line will be drawn.
871
- *
872
- * @param value - line-color value (default `#000000`)
873
- */
874
- lineColor(value) {
875
- this.addStyle("line-color", value);
876
- return this;
877
- }
878
- /**
879
- * The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively.
880
- *
881
- * @param value - line-translate value in pixels (default `0,0`)
882
- */
883
- lineTranslate(value) {
884
- this.addStyle("line-translate", value);
885
- return this;
886
- }
887
- /**
888
- * Controls the frame of reference for `line-translate`.
889
- *
890
- * Values:
891
- * - map: The line is translated relative to the map.
892
- * - viewport: The line is translated relative to the viewport.
893
- *
894
- * @param value - line-translate-anchor value (default `map`)
895
- */
896
- lineTranslateAnchor(value) {
897
- this.addStyle("line-translate-anchor", value);
898
- return this;
899
- }
900
- /**
901
- * Stroke thickness.
902
- *
903
- * @param value - line-width value in pixels (default `1`)
904
- */
905
- lineWidth(value) {
906
- this.addStyle("line-width", value);
907
- return this;
908
- }
909
- /**
910
- * Draws a line casing outside of a line's actual path. Value indicates the width of the inner gap.
911
- *
912
- * @param value - line-gap-width value in pixels
913
- */
914
- lineGapWidth(value) {
915
- this.addStyle("line-gap-width", value);
916
- return this;
917
- }
918
- /**
919
- * The line's offset. For linear features, a positive value offsets the line to the right, relative to the direction of the line, and a negative value to the left. For polygon features, a positive value results in an inset, and a negative value results in an outset.
920
- *
921
- * @param value - line-offset value in pixels
922
- */
923
- lineOffset(value) {
924
- this.addStyle("line-offset", value);
925
- return this;
926
- }
927
- /**
928
- * Blur applied to the line, in pixels.
929
- *
930
- * @param value - line-blur value in pixels
931
- */
932
- lineBlur(value) {
933
- this.addStyle("line-blur", value);
934
- return this;
935
- }
936
- /**
937
- * Specifies the lengths of the alternating dashes and gaps that form the dash pattern. The lengths are later scaled by the line width. To convert a dash length to pixels, multiply the length by the current line width. Note that GeoJSON sources with `lineMetrics: true` specified won't render dashed lines to the expected scale. Also note that zoom-dependent expressions will be evaluated only at integer zoom levels.
938
- *
939
- * @param value - line-dasharray value in line widths
940
- */
941
- lineDasharray(value) {
942
- this.addStyle("line-dasharray", value);
943
- return this;
944
- }
945
- /**
946
- * Name of image in sprite to use for drawing image lines. For seamless patterns, image width must be a factor of two (2, 4, 8, ..., 512). Note that zoom-dependent expressions will be evaluated only at integer zoom levels.
947
- *
948
- * @param value - line-pattern value
949
- */
950
- linePattern(value) {
951
- this.addStyle("line-pattern", value);
952
- return this;
953
- }
954
- /**
955
- * Defines a gradient with which to color a line feature. Can only be used with GeoJSON sources that specify `"lineMetrics": true`.
956
- *
957
- * @param value - line-gradient value
958
- */
959
- lineGradient(value) {
960
- this.addStyle("line-gradient", value);
961
- return this;
962
- }
963
- }
964
- MapLayerStyleBuilder.registerStyleBuilder("line", LineLayerStyleBuilder);
965
- class SymbolLayerStyleBuilder extends MapLayerStyleBuilder {
966
- /**
967
- * Label placement relative to its geometry.
968
- *
969
- * Values:
970
- * - point: The label is placed at the point where the geometry is located.
971
- * - line: The label is placed along the line of the geometry. Can only be used on `LineString` and `Polygon` geometries.
972
- * - line-center: The label is placed at the center of the line of the geometry. Can only be used on `LineString` and `Polygon` geometries. Note that a single feature in a vector tile may contain multiple line geometries.
973
- *
974
- * @param value - symbol-placement value (default `point`)
975
- */
976
- symbolPlacement(value) {
977
- this.addStyle("symbol-placement", value);
978
- return this;
979
- }
980
- /**
981
- * Distance between two symbol anchors.
982
- *
983
- * @param value - symbol-spacing value in pixels (default `250`)
984
- */
985
- symbolSpacing(value) {
986
- this.addStyle("symbol-spacing", value);
987
- return this;
988
- }
989
- /**
990
- * If true, the symbols will not cross tile edges to avoid mutual collisions. Recommended in layers that don't have enough padding in the vector tile to prevent collisions, or if it is a point symbol layer placed after a line symbol layer. When using a client that supports global collision detection, like MapLibre GL JS version 0.42.0 or greater, enabling this property is not needed to prevent clipped labels at tile boundaries.
991
- *
992
- * @param value - symbol-avoid-edges value
993
- */
994
- symbolAvoidEdges(value) {
995
- this.addStyle("symbol-avoid-edges", value);
996
- return this;
997
- }
998
- /**
999
- * Sorts features in ascending order based on this value. Features with lower sort keys are drawn and placed first. When `icon-allow-overlap` or `text-allow-overlap` is `false`, features with a lower sort key will have priority during placement. When `icon-allow-overlap` or `text-allow-overlap` is set to `true`, features with a higher sort key will overlap over features with a lower sort key.
1000
- *
1001
- * @param value - symbol-sort-key value
1002
- */
1003
- symbolSortKey(value) {
1004
- this.addStyle("symbol-sort-key", value);
1005
- return this;
1006
- }
1007
- /**
1008
- * Determines whether overlapping symbols in the same layer are rendered in the order that they appear in the data source or by their y-position relative to the viewport. To control the order and prioritization of symbols otherwise, use `symbol-sort-key`.
1009
- *
1010
- * Values:
1011
- * - auto: Sorts symbols by `symbol-sort-key` if set. Otherwise, sorts symbols by their y-position relative to the viewport if `icon-allow-overlap` or `text-allow-overlap` is set to `true` or `icon-ignore-placement` or `text-ignore-placement` is `false`.
1012
- * - viewport-y: Sorts symbols by their y-position relative to the viewport if `icon-allow-overlap` or `text-allow-overlap` is set to `true` or `icon-ignore-placement` or `text-ignore-placement` is `false`.
1013
- * - source: Sorts symbols by `symbol-sort-key` if set. Otherwise, no sorting is applied; symbols are rendered in the same order as the source data.
1014
- *
1015
- * @param value - symbol-z-order value (default `auto`)
1016
- */
1017
- symbolZOrder(value) {
1018
- this.addStyle("symbol-z-order", value);
1019
- return this;
1020
- }
1021
- /**
1022
- * If true, the icon will be visible even if it collides with other previously drawn symbols.
1023
- *
1024
- * @param value - icon-allow-overlap value
1025
- */
1026
- iconAllowOverlap(value) {
1027
- this.addStyle("icon-allow-overlap", value);
1028
- return this;
1029
- }
1030
- /**
1031
- * Allows for control over whether to show an icon when it overlaps other symbols on the map. If `icon-overlap` is not set, `icon-allow-overlap` is used instead.
1032
- *
1033
- * Values:
1034
- * - never: The icon will be hidden if it collides with any other previously drawn symbol.
1035
- * - always: The icon will be visible even if it collides with any other previously drawn symbol.
1036
- * - cooperative: If the icon collides with another previously drawn symbol, the overlap mode for that symbol is checked. If the previous symbol was placed using `never` overlap mode, the new icon is hidden. If the previous symbol was placed using `always` or `cooperative` overlap mode, the new icon is visible.
1037
- *
1038
- * @param value - icon-overlap value
1039
- */
1040
- iconOverlap(value) {
1041
- this.addStyle("icon-overlap", value);
1042
- return this;
1043
- }
1044
- /**
1045
- * If true, other symbols can be visible even if they collide with the icon.
1046
- *
1047
- * @param value - icon-ignore-placement value
1048
- */
1049
- iconIgnorePlacement(value) {
1050
- this.addStyle("icon-ignore-placement", value);
1051
- return this;
1052
- }
1053
- /**
1054
- * If true, text will display without their corresponding icons when the icon collides with other symbols and the text does not.
1055
- *
1056
- * @param value - icon-optional value
1057
- */
1058
- iconOptional(value) {
1059
- this.addStyle("icon-optional", value);
1060
- return this;
1061
- }
1062
- /**
1063
- * In combination with `symbol-placement`, determines the rotation behavior of icons.
1064
- *
1065
- * Values:
1066
- * - map: When `symbol-placement` is set to `point`, aligns icons east-west. When `symbol-placement` is set to `line` or `line-center`, aligns icon x-axes with the line.
1067
- * - viewport: Produces icons whose x-axes are aligned with the x-axis of the viewport, regardless of the value of `symbol-placement`.
1068
- * - auto: When `symbol-placement` is set to `point`, this is equivalent to `viewport`. When `symbol-placement` is set to `line` or `line-center`, this is equivalent to `map`.
1069
- *
1070
- * @param value - icon-rotation-alignment value (default `auto`)
1071
- */
1072
- iconRotationAlignment(value) {
1073
- this.addStyle("icon-rotation-alignment", value);
1074
- return this;
1075
- }
1076
- /**
1077
- * Scales the original size of the icon by the provided factor. The new pixel size of the image will be the original pixel size multiplied by `icon-size`. 1 is the original size; 3 triples the size of the image.
1078
- *
1079
- * @param value - icon-size value in factor of the original icon size (default `1`)
1080
- */
1081
- iconSize(value) {
1082
- this.addStyle("icon-size", value);
1083
- return this;
1084
- }
1085
- /**
1086
- * Scales the icon to fit around the associated text.
1087
- *
1088
- * Values:
1089
- * - none: The icon is displayed at its intrinsic aspect ratio.
1090
- * - width: The icon is scaled in the x-dimension to fit the width of the text.
1091
- * - height: The icon is scaled in the y-dimension to fit the height of the text.
1092
- * - both: The icon is scaled in both x- and y-dimensions.
1093
- *
1094
- * @param value - icon-text-fit value (default `none`)
1095
- */
1096
- iconTextFit(value) {
1097
- this.addStyle("icon-text-fit", value);
1098
- return this;
1099
- }
1100
- /**
1101
- * Size of the additional area added to dimensions determined by `icon-text-fit`, in clockwise order: top, right, bottom, left.
1102
- *
1103
- * @param value - icon-text-fit-padding value in pixels (default `0,0,0,0`)
1104
- */
1105
- iconTextFitPadding(value) {
1106
- this.addStyle("icon-text-fit-padding", value);
1107
- return this;
1108
- }
1109
- /**
1110
- * Name of image in sprite to use for drawing an image background.
1111
- *
1112
- * @param value - icon-image value
1113
- */
1114
- iconImage(value) {
1115
- this.addStyle("icon-image", value);
1116
- return this;
1117
- }
1118
- /**
1119
- * Rotates the icon clockwise.
1120
- *
1121
- * @param value - icon-rotate value in degrees
1122
- */
1123
- iconRotate(value) {
1124
- this.addStyle("icon-rotate", value);
1125
- return this;
1126
- }
1127
- /**
1128
- * Size of additional area round the icon bounding box used for detecting symbol collisions. Values are declared using CSS margin shorthand syntax: a single value applies to all four sides; two values apply to [top/bottom, left/right]; three values apply to [top, left/right, bottom]; four values apply to [top, right, bottom, left]. For backwards compatibility, a single bare number is accepted, and treated the same as a one-element array - padding applied to all sides.
1129
- *
1130
- * @param value - icon-padding value in pixels (default `2`)
1131
- */
1132
- iconPadding(value) {
1133
- this.addStyle("icon-padding", value);
1134
- return this;
1135
- }
1136
- /**
1137
- * If true, the icon may be flipped to prevent it from being rendered upside-down.
1138
- *
1139
- * @param value - icon-keep-upright value
1140
- */
1141
- iconKeepUpright(value) {
1142
- this.addStyle("icon-keep-upright", value);
1143
- return this;
1144
- }
1145
- /**
1146
- * Offset distance of icon from its anchor. Positive values indicate right and down, while negative values indicate left and up. Each component is multiplied by the value of `icon-size` to obtain the final offset in pixels. When combined with `icon-rotate` the offset will be as if the rotated direction was up.
1147
- *
1148
- * @param value - icon-offset value (default `0,0`)
1149
- */
1150
- iconOffset(value) {
1151
- this.addStyle("icon-offset", value);
1152
- return this;
1153
- }
1154
- /**
1155
- * Part of the icon placed closest to the anchor.
1156
- *
1157
- * Values:
1158
- * - center: The center of the icon is placed closest to the anchor.
1159
- * - left: The left side of the icon is placed closest to the anchor.
1160
- * - right: The right side of the icon is placed closest to the anchor.
1161
- * - top: The top of the icon is placed closest to the anchor.
1162
- * - bottom: The bottom of the icon is placed closest to the anchor.
1163
- * - top-left: The top left corner of the icon is placed closest to the anchor.
1164
- * - top-right: The top right corner of the icon is placed closest to the anchor.
1165
- * - bottom-left: The bottom left corner of the icon is placed closest to the anchor.
1166
- * - bottom-right: The bottom right corner of the icon is placed closest to the anchor.
1167
- *
1168
- * @param value - icon-anchor value (default `center`)
1169
- */
1170
- iconAnchor(value) {
1171
- this.addStyle("icon-anchor", value);
1172
- return this;
1173
- }
1174
- /**
1175
- * Orientation of icon when map is pitched.
1176
- *
1177
- * Values:
1178
- * - map: The icon is aligned to the plane of the map.
1179
- * - viewport: The icon is aligned to the plane of the viewport.
1180
- * - auto: Automatically matches the value of `icon-rotation-alignment`.
1181
- *
1182
- * @param value - icon-pitch-alignment value (default `auto`)
1183
- */
1184
- iconPitchAlignment(value) {
1185
- this.addStyle("icon-pitch-alignment", value);
1186
- return this;
1187
- }
1188
- /**
1189
- * Orientation of text when map is pitched.
1190
- *
1191
- * Values:
1192
- * - map: The text is aligned to the plane of the map.
1193
- * - viewport: The text is aligned to the plane of the viewport.
1194
- * - auto: Automatically matches the value of `text-rotation-alignment`.
1195
- *
1196
- * @param value - text-pitch-alignment value (default `auto`)
1197
- */
1198
- textPitchAlignment(value) {
1199
- this.addStyle("text-pitch-alignment", value);
1200
- return this;
1201
- }
1202
- /**
1203
- * In combination with `symbol-placement`, determines the rotation behavior of the individual glyphs forming the text.
1204
- *
1205
- * Values:
1206
- * - map: When `symbol-placement` is set to `point`, aligns text east-west. When `symbol-placement` is set to `line` or `line-center`, aligns text x-axes with the line.
1207
- * - viewport: Produces glyphs whose x-axes are aligned with the x-axis of the viewport, regardless of the value of `symbol-placement`.
1208
- * - viewport-glyph: When `symbol-placement` is set to `point`, aligns text to the x-axis of the viewport. When `symbol-placement` is set to `line` or `line-center`, aligns glyphs to the x-axis of the viewport and places them along the line.
1209
- * - auto: When `symbol-placement` is set to `point`, this is equivalent to `viewport`. When `symbol-placement` is set to `line` or `line-center`, this is equivalent to `map`.
1210
- *
1211
- * @param value - text-rotation-alignment value (default `auto`)
1212
- */
1213
- textRotationAlignment(value) {
1214
- this.addStyle("text-rotation-alignment", value);
1215
- return this;
1216
- }
1217
- /**
1218
- * Value to use for a text label. If a plain `string` is provided, it will be treated as a `formatted` with default/inherited formatting options.
1219
- *
1220
- * @param value - text-field value
1221
- */
1222
- textField(value) {
1223
- this.addStyle("text-field", value);
1224
- return this;
1225
- }
1226
- /**
1227
- * Font stack to use for displaying text.
1228
- *
1229
- * @param value - text-font value (default `Open Sans Regular,Arial Unicode MS Regular`)
1230
- */
1231
- textFont(value) {
1232
- this.addStyle("text-font", value);
1233
- return this;
1234
- }
1235
- /**
1236
- * Font size.
1237
- *
1238
- * @param value - text-size value in pixels (default `16`)
1239
- */
1240
- textSize(value) {
1241
- this.addStyle("text-size", value);
1242
- return this;
1243
- }
1244
- /**
1245
- * The maximum line width for text wrapping.
1246
- *
1247
- * @param value - text-max-width value in ems (default `10`)
1248
- */
1249
- textMaxWidth(value) {
1250
- this.addStyle("text-max-width", value);
1251
- return this;
1252
- }
1253
- /**
1254
- * Text leading value for multi-line text.
1255
- *
1256
- * @param value - text-line-height value in ems (default `1.2`)
1257
- */
1258
- textLineHeight(value) {
1259
- this.addStyle("text-line-height", value);
1260
- return this;
1261
- }
1262
- /**
1263
- * Text tracking amount.
1264
- *
1265
- * @param value - text-letter-spacing value in ems
1266
- */
1267
- textLetterSpacing(value) {
1268
- this.addStyle("text-letter-spacing", value);
1269
- return this;
1270
- }
1271
- /**
1272
- * Text justification options.
1273
- *
1274
- * Values:
1275
- * - auto: The text is aligned towards the anchor position.
1276
- * - left: The text is aligned to the left.
1277
- * - center: The text is centered.
1278
- * - right: The text is aligned to the right.
1279
- *
1280
- * @param value - text-justify value (default `center`)
1281
- */
1282
- textJustify(value) {
1283
- this.addStyle("text-justify", value);
1284
- return this;
1285
- }
1286
- /**
1287
- * Radial offset of text, in the direction of the symbol's anchor. Useful in combination with `text-variable-anchor`, which defaults to using the two-dimensional `text-offset` if present.
1288
- *
1289
- * @param value - text-radial-offset value in ems
1290
- */
1291
- textRadialOffset(value) {
1292
- this.addStyle("text-radial-offset", value);
1293
- return this;
1294
- }
1295
- /**
1296
- * To increase the chance of placing high-priority labels on the map, you can provide an array of `text-anchor` locations: the renderer will attempt to place the label at each location, in order, before moving onto the next label. Use `text-justify: auto` to choose justification based on anchor position. To apply an offset, use the `text-radial-offset` or the two-dimensional `text-offset`.
1297
- *
1298
- * Values:
1299
- * - center: The center of the text is placed closest to the anchor.
1300
- * - left: The left side of the text is placed closest to the anchor.
1301
- * - right: The right side of the text is placed closest to the anchor.
1302
- * - top: The top of the text is placed closest to the anchor.
1303
- * - bottom: The bottom of the text is placed closest to the anchor.
1304
- * - top-left: The top left corner of the text is placed closest to the anchor.
1305
- * - top-right: The top right corner of the text is placed closest to the anchor.
1306
- * - bottom-left: The bottom left corner of the text is placed closest to the anchor.
1307
- * - bottom-right: The bottom right corner of the text is placed closest to the anchor.
1308
- *
1309
- * @param value - text-variable-anchor value
1310
- */
1311
- textVariableAnchor(value) {
1312
- this.addStyle("text-variable-anchor", value);
1313
- return this;
1314
- }
1315
- /**
1316
- * To increase the chance of placing high-priority labels on the map, you can provide an array of `text-anchor` locations, each paired with an offset value. The renderer will attempt to place the label at each location, in order, before moving on to the next location+offset. Use `text-justify: auto` to choose justification based on anchor position.
1317
-
1318
- The length of the array must be even, and must alternate between enum and point entries. i.e., each anchor location must be accompanied by a point, and that point defines the offset when the corresponding anchor location is used. Positive offset values indicate right and down, while negative values indicate left and up. Anchor locations may repeat, allowing the renderer to try multiple offsets to try and place a label using the same anchor.
1319
-
1320
- When present, this property takes precedence over `text-anchor`, `text-variable-anchor`, `text-offset`, and `text-radial-offset`.
1321
-
1322
- ```json
1323
- { "text-variable-anchor-offset": ["top", [0, 4], "left", [3,0], "bottom", [1, 1]] }
1324
- ```
1325
-
1326
- When the renderer chooses the `top` anchor, `[0, 4]` will be used for `text-offset`; the text will be shifted down by 4 ems.
1327
-
1328
- When the renderer chooses the `left` anchor, `[3, 0]` will be used for `text-offset`; the text will be shifted right by 3 ems.
1329
- *
1330
- * @param value - text-variable-anchor-offset value
1331
- */
1332
- textVariableAnchorOffset(value) {
1333
- this.addStyle("text-variable-anchor-offset", value);
1334
- return this;
1335
- }
1336
- /**
1337
- * Part of the text placed closest to the anchor.
1338
- *
1339
- * Values:
1340
- * - center: The center of the text is placed closest to the anchor.
1341
- * - left: The left side of the text is placed closest to the anchor.
1342
- * - right: The right side of the text is placed closest to the anchor.
1343
- * - top: The top of the text is placed closest to the anchor.
1344
- * - bottom: The bottom of the text is placed closest to the anchor.
1345
- * - top-left: The top left corner of the text is placed closest to the anchor.
1346
- * - top-right: The top right corner of the text is placed closest to the anchor.
1347
- * - bottom-left: The bottom left corner of the text is placed closest to the anchor.
1348
- * - bottom-right: The bottom right corner of the text is placed closest to the anchor.
1349
- *
1350
- * @param value - text-anchor value (default `center`)
1351
- */
1352
- textAnchor(value) {
1353
- this.addStyle("text-anchor", value);
1354
- return this;
1355
- }
1356
- /**
1357
- * Maximum angle change between adjacent characters.
1358
- *
1359
- * @param value - text-max-angle value in degrees (default `45`)
1360
- */
1361
- textMaxAngle(value) {
1362
- this.addStyle("text-max-angle", value);
1363
- return this;
1364
- }
1365
- /**
1366
- * The property allows control over a symbol's orientation. Note that the property values act as a hint, so that a symbol whose language doesn’t support the provided orientation will be laid out in its natural orientation. Example: English point symbol will be rendered horizontally even if array value contains single 'vertical' enum value. The order of elements in an array define priority order for the placement of an orientation variant.
1367
- *
1368
- * Values:
1369
- * - horizontal: If a text's language supports horizontal writing mode, symbols with point placement would be laid out horizontally.
1370
- * - vertical: If a text's language supports vertical writing mode, symbols with point placement would be laid out vertically.
1371
- *
1372
- * @param value - text-writing-mode value
1373
- */
1374
- textWritingMode(value) {
1375
- this.addStyle("text-writing-mode", value);
1376
- return this;
1377
- }
1378
- /**
1379
- * Rotates the text clockwise.
1380
- *
1381
- * @param value - text-rotate value in degrees
1382
- */
1383
- textRotate(value) {
1384
- this.addStyle("text-rotate", value);
1385
- return this;
1386
- }
1387
- /**
1388
- * Size of the additional area around the text bounding box used for detecting symbol collisions.
1389
- *
1390
- * @param value - text-padding value in pixels (default `2`)
1391
- */
1392
- textPadding(value) {
1393
- this.addStyle("text-padding", value);
1394
- return this;
1395
- }
1396
- /**
1397
- * If true, the text may be flipped vertically to prevent it from being rendered upside-down.
1398
- *
1399
- * @param value - text-keep-upright value (default `true`)
1400
- */
1401
- textKeepUpright(value) {
1402
- this.addStyle("text-keep-upright", value);
1403
- return this;
1404
- }
1405
- /**
1406
- * Specifies how to capitalize text, similar to the CSS `text-transform` property.
1407
- *
1408
- * Values:
1409
- * - none: The text is not altered.
1410
- * - uppercase: Forces all letters to be displayed in uppercase.
1411
- * - lowercase: Forces all letters to be displayed in lowercase.
1412
- *
1413
- * @param value - text-transform value (default `none`)
1414
- */
1415
- textTransform(value) {
1416
- this.addStyle("text-transform", value);
1417
- return this;
1418
- }
1419
- /**
1420
- * Offset distance of text from its anchor. Positive values indicate right and down, while negative values indicate left and up. If used with text-variable-anchor, input values will be taken as absolute values. Offsets along the x- and y-axis will be applied automatically based on the anchor position.
1421
- *
1422
- * @param value - text-offset value in ems (default `0,0`)
1423
- */
1424
- textOffset(value) {
1425
- this.addStyle("text-offset", value);
1426
- return this;
1427
- }
1428
- /**
1429
- * If true, the text will be visible even if it collides with other previously drawn symbols.
1430
- *
1431
- * @param value - text-allow-overlap value
1432
- */
1433
- textAllowOverlap(value) {
1434
- this.addStyle("text-allow-overlap", value);
1435
- return this;
1436
- }
1437
- /**
1438
- * Allows for control over whether to show symbol text when it overlaps other symbols on the map. If `text-overlap` is not set, `text-allow-overlap` is used instead
1439
- *
1440
- * Values:
1441
- * - never: The text will be hidden if it collides with any other previously drawn symbol.
1442
- * - always: The text will be visible even if it collides with any other previously drawn symbol.
1443
- * - cooperative: If the text collides with another previously drawn symbol, the overlap mode for that symbol is checked. If the previous symbol was placed using `never` overlap mode, the new text is hidden. If the previous symbol was placed using `always` or `cooperative` overlap mode, the new text is visible.
1444
- *
1445
- * @param value - text-overlap value
1446
- */
1447
- textOverlap(value) {
1448
- this.addStyle("text-overlap", value);
1449
- return this;
1450
- }
1451
- /**
1452
- * If true, other symbols can be visible even if they collide with the text.
1453
- *
1454
- * @param value - text-ignore-placement value
1455
- */
1456
- textIgnorePlacement(value) {
1457
- this.addStyle("text-ignore-placement", value);
1458
- return this;
1459
- }
1460
- /**
1461
- * If true, icons will display without their corresponding text when the text collides with other symbols and the icon does not.
1462
- *
1463
- * @param value - text-optional value
1464
- */
1465
- textOptional(value) {
1466
- this.addStyle("text-optional", value);
1467
- return this;
1468
- }
1469
- /**
1470
- * The opacity at which the icon will be drawn.
1471
- *
1472
- * @param value - icon-opacity value (default `1`)
1473
- */
1474
- iconOpacity(value) {
1475
- this.addStyle("icon-opacity", value);
1476
- return this;
1477
- }
1478
- /**
1479
- * The color of the icon. This can only be used with sdf icons.
1480
- *
1481
- * @param value - icon-color value (default `#000000`)
1482
- */
1483
- iconColor(value) {
1484
- this.addStyle("icon-color", value);
1485
- return this;
1486
- }
1487
- /**
1488
- * The color of the icon's halo. Icon halos can only be used with SDF icons.
1489
- *
1490
- * @param value - icon-halo-color value (default `rgba(0, 0, 0, 0)`)
1491
- */
1492
- iconHaloColor(value) {
1493
- this.addStyle("icon-halo-color", value);
1494
- return this;
1495
- }
1496
- /**
1497
- * Distance of halo to the icon outline.
1498
- *
1499
- * @param value - icon-halo-width value in pixels
1500
- */
1501
- iconHaloWidth(value) {
1502
- this.addStyle("icon-halo-width", value);
1503
- return this;
1504
- }
1505
- /**
1506
- * Fade out the halo towards the outside.
1507
- *
1508
- * @param value - icon-halo-blur value in pixels
1509
- */
1510
- iconHaloBlur(value) {
1511
- this.addStyle("icon-halo-blur", value);
1512
- return this;
1513
- }
1514
- /**
1515
- * Distance that the icon's anchor is moved from its original placement. Positive values indicate right and down, while negative values indicate left and up.
1516
- *
1517
- * @param value - icon-translate value in pixels (default `0,0`)
1518
- */
1519
- iconTranslate(value) {
1520
- this.addStyle("icon-translate", value);
1521
- return this;
1522
- }
1523
- /**
1524
- * Controls the frame of reference for `icon-translate`.
1525
- *
1526
- * Values:
1527
- * - map: Icons are translated relative to the map.
1528
- * - viewport: Icons are translated relative to the viewport.
1529
- *
1530
- * @param value - icon-translate-anchor value (default `map`)
1531
- */
1532
- iconTranslateAnchor(value) {
1533
- this.addStyle("icon-translate-anchor", value);
1534
- return this;
1535
- }
1536
- /**
1537
- * The opacity at which the text will be drawn.
1538
- *
1539
- * @param value - text-opacity value (default `1`)
1540
- */
1541
- textOpacity(value) {
1542
- this.addStyle("text-opacity", value);
1543
- return this;
1544
- }
1545
- /**
1546
- * The color with which the text will be drawn.
1547
- *
1548
- * @param value - text-color value (default `#000000`)
1549
- */
1550
- textColor(value) {
1551
- this.addStyle("text-color", value);
1552
- return this;
1553
- }
1554
- /**
1555
- * The color of the text's halo, which helps it stand out from backgrounds.
1556
- *
1557
- * @param value - text-halo-color value (default `rgba(0, 0, 0, 0)`)
1558
- */
1559
- textHaloColor(value) {
1560
- this.addStyle("text-halo-color", value);
1561
- return this;
1562
- }
1563
- /**
1564
- * Distance of halo to the font outline. Max text halo width is 1/4 of the font-size.
1565
- *
1566
- * @param value - text-halo-width value in pixels
1567
- */
1568
- textHaloWidth(value) {
1569
- this.addStyle("text-halo-width", value);
1570
- return this;
1571
- }
1572
- /**
1573
- * The halo's fadeout distance towards the outside.
1574
- *
1575
- * @param value - text-halo-blur value in pixels
1576
- */
1577
- textHaloBlur(value) {
1578
- this.addStyle("text-halo-blur", value);
1579
- return this;
1580
- }
1581
- /**
1582
- * Distance that the text's anchor is moved from its original placement. Positive values indicate right and down, while negative values indicate left and up.
1583
- *
1584
- * @param value - text-translate value in pixels (default `0,0`)
1585
- */
1586
- textTranslate(value) {
1587
- this.addStyle("text-translate", value);
1588
- return this;
1589
- }
1590
- /**
1591
- * Controls the frame of reference for `text-translate`.
1592
- *
1593
- * Values:
1594
- * - map: The text is translated relative to the map.
1595
- * - viewport: The text is translated relative to the viewport.
1596
- *
1597
- * @param value - text-translate-anchor value (default `map`)
1598
- */
1599
- textTranslateAnchor(value) {
1600
- this.addStyle("text-translate-anchor", value);
1601
- return this;
1602
- }
1603
- }
1604
- MapLayerStyleBuilder.registerStyleBuilder("symbol", SymbolLayerStyleBuilder);
1605
- class CircleLayerStyleBuilder extends MapLayerStyleBuilder {
1606
- /**
1607
- * Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key.
1608
- *
1609
- * @param value - circle-sort-key value
1610
- */
1611
- circleSortKey(value) {
1612
- this.addStyle("circle-sort-key", value);
1613
- return this;
1614
- }
1615
- /**
1616
- * Circle radius.
1617
- *
1618
- * @param value - circle-radius value in pixels (default `5`)
1619
- */
1620
- circleRadius(value) {
1621
- this.addStyle("circle-radius", value);
1622
- return this;
1623
- }
1624
- /**
1625
- * The fill color of the circle.
1626
- *
1627
- * @param value - circle-color value (default `#000000`)
1628
- */
1629
- circleColor(value) {
1630
- this.addStyle("circle-color", value);
1631
- return this;
1632
- }
1633
- /**
1634
- * Amount to blur the circle. 1 blurs the circle such that only the centerpoint is full opacity.
1635
- *
1636
- * @param value - circle-blur value
1637
- */
1638
- circleBlur(value) {
1639
- this.addStyle("circle-blur", value);
1640
- return this;
1641
- }
1642
- /**
1643
- * The opacity at which the circle will be drawn.
1644
- *
1645
- * @param value - circle-opacity value (default `1`)
1646
- */
1647
- circleOpacity(value) {
1648
- this.addStyle("circle-opacity", value);
1649
- return this;
1650
- }
1651
- /**
1652
- * The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively.
1653
- *
1654
- * @param value - circle-translate value in pixels (default `0,0`)
1655
- */
1656
- circleTranslate(value) {
1657
- this.addStyle("circle-translate", value);
1658
- return this;
1659
- }
1660
- /**
1661
- * Controls the frame of reference for `circle-translate`.
1662
- *
1663
- * Values:
1664
- * - map: The circle is translated relative to the map.
1665
- * - viewport: The circle is translated relative to the viewport.
1666
- *
1667
- * @param value - circle-translate-anchor value (default `map`)
1668
- */
1669
- circleTranslateAnchor(value) {
1670
- this.addStyle("circle-translate-anchor", value);
1671
- return this;
1672
- }
1673
- /**
1674
- * Controls the scaling behavior of the circle when the map is pitched.
1675
- *
1676
- * Values:
1677
- * - map: Circles are scaled according to their apparent distance to the camera.
1678
- * - viewport: Circles are not scaled.
1679
- *
1680
- * @param value - circle-pitch-scale value (default `map`)
1681
- */
1682
- circlePitchScale(value) {
1683
- this.addStyle("circle-pitch-scale", value);
1684
- return this;
1685
- }
1686
- /**
1687
- * Orientation of circle when map is pitched.
1688
- *
1689
- * Values:
1690
- * - map: The circle is aligned to the plane of the map.
1691
- * - viewport: The circle is aligned to the plane of the viewport.
1692
- *
1693
- * @param value - circle-pitch-alignment value (default `viewport`)
1694
- */
1695
- circlePitchAlignment(value) {
1696
- this.addStyle("circle-pitch-alignment", value);
1697
- return this;
1698
- }
1699
- /**
1700
- * The width of the circle's stroke. Strokes are placed outside of the `circle-radius`.
1701
- *
1702
- * @param value - circle-stroke-width value in pixels
1703
- */
1704
- circleStrokeWidth(value) {
1705
- this.addStyle("circle-stroke-width", value);
1706
- return this;
1707
- }
1708
- /**
1709
- * The stroke color of the circle.
1710
- *
1711
- * @param value - circle-stroke-color value (default `#000000`)
1712
- */
1713
- circleStrokeColor(value) {
1714
- this.addStyle("circle-stroke-color", value);
1715
- return this;
1716
- }
1717
- /**
1718
- * The opacity of the circle's stroke.
1719
- *
1720
- * @param value - circle-stroke-opacity value (default `1`)
1721
- */
1722
- circleStrokeOpacity(value) {
1723
- this.addStyle("circle-stroke-opacity", value);
1724
- return this;
1725
- }
1726
- }
1727
- MapLayerStyleBuilder.registerStyleBuilder("circle", CircleLayerStyleBuilder);
1728
- class HeatmapLayerStyleBuilder extends MapLayerStyleBuilder {
1729
- /**
1730
- * Radius of influence of one heatmap point in pixels. Increasing the value makes the heatmap smoother, but less detailed.
1731
- *
1732
- * @param value - heatmap-radius value in pixels (default `30`)
1733
- */
1734
- heatmapRadius(value) {
1735
- this.addStyle("heatmap-radius", value);
1736
- return this;
1737
- }
1738
- /**
1739
- * A measure of how much an individual point contributes to the heatmap. A value of 10 would be equivalent to having 10 points of weight 1 in the same spot. Especially useful when combined with clustering.
1740
- *
1741
- * @param value - heatmap-weight value (default `1`)
1742
- */
1743
- heatmapWeight(value) {
1744
- this.addStyle("heatmap-weight", value);
1745
- return this;
1746
- }
1747
- /**
1748
- * Similar to `heatmap-weight` but controls the intensity of the heatmap globally. Primarily used for adjusting the heatmap based on zoom level.
1749
- *
1750
- * @param value - heatmap-intensity value (default `1`)
1751
- */
1752
- heatmapIntensity(value) {
1753
- this.addStyle("heatmap-intensity", value);
1754
- return this;
1755
- }
1756
- /**
1757
- * Defines the color of each pixel based on its density value in a heatmap. Should be an expression that uses `["heatmap-density"]` as input.
1758
- *
1759
- * @param value - heatmap-color value (default `interpolate,linear,heatmap-density,0,rgba(0, 0, 255, 0),0.1,royalblue,0.3,cyan,0.5,lime,0.7,yellow,1,red`)
1760
- */
1761
- heatmapColor(value) {
1762
- this.addStyle("heatmap-color", value);
1763
- return this;
1764
- }
1765
- /**
1766
- * The global opacity at which the heatmap layer will be drawn.
1767
- *
1768
- * @param value - heatmap-opacity value (default `1`)
1769
- */
1770
- heatmapOpacity(value) {
1771
- this.addStyle("heatmap-opacity", value);
1772
- return this;
1773
- }
1774
- }
1775
- MapLayerStyleBuilder.registerStyleBuilder("heatmap", HeatmapLayerStyleBuilder);
1776
- class FillExtrusionLayerStyleBuilder extends MapLayerStyleBuilder {
1777
- /**
1778
- * The opacity of the entire fill extrusion layer. This is rendered on a per-layer, not per-feature, basis, and data-driven styling is not available.
1779
- *
1780
- * @param value - fill-extrusion-opacity value (default `1`)
1781
- */
1782
- fillExtrusionOpacity(value) {
1783
- this.addStyle("fill-extrusion-opacity", value);
1784
- return this;
1785
- }
1786
- /**
1787
- * The base color of the extruded fill. The extrusion's surfaces will be shaded differently based on this color in combination with the root `light` settings. If this color is specified as `rgba` with an alpha component, the alpha component will be ignored; use `fill-extrusion-opacity` to set layer opacity.
1788
- *
1789
- * @param value - fill-extrusion-color value (default `#000000`)
1790
- */
1791
- fillExtrusionColor(value) {
1792
- this.addStyle("fill-extrusion-color", value);
1793
- return this;
1794
- }
1795
- /**
1796
- * The geometry's offset. Values are [x, y] where negatives indicate left and up (on the flat plane), respectively.
1797
- *
1798
- * @param value - fill-extrusion-translate value in pixels (default `0,0`)
1799
- */
1800
- fillExtrusionTranslate(value) {
1801
- this.addStyle("fill-extrusion-translate", value);
1802
- return this;
1803
- }
1804
- /**
1805
- * Controls the frame of reference for `fill-extrusion-translate`.
1806
- *
1807
- * Values:
1808
- * - map: The fill extrusion is translated relative to the map.
1809
- * - viewport: The fill extrusion is translated relative to the viewport.
1810
- *
1811
- * @param value - fill-extrusion-translate-anchor value (default `map`)
1812
- */
1813
- fillExtrusionTranslateAnchor(value) {
1814
- this.addStyle("fill-extrusion-translate-anchor", value);
1815
- return this;
1816
- }
1817
- /**
1818
- * Name of image in sprite to use for drawing images on extruded fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). Note that zoom-dependent expressions will be evaluated only at integer zoom levels.
1819
- *
1820
- * @param value - fill-extrusion-pattern value
1821
- */
1822
- fillExtrusionPattern(value) {
1823
- this.addStyle("fill-extrusion-pattern", value);
1824
- return this;
1825
- }
1826
- /**
1827
- * The height with which to extrude this layer.
1828
- *
1829
- * @param value - fill-extrusion-height value in meters
1830
- */
1831
- fillExtrusionHeight(value) {
1832
- this.addStyle("fill-extrusion-height", value);
1833
- return this;
1834
- }
1835
- /**
1836
- * The height with which to extrude the base of this layer. Must be less than or equal to `fill-extrusion-height`.
1837
- *
1838
- * @param value - fill-extrusion-base value in meters
1839
- */
1840
- fillExtrusionBase(value) {
1841
- this.addStyle("fill-extrusion-base", value);
1842
- return this;
1843
- }
1844
- /**
1845
- * Whether to apply a vertical gradient to the sides of a fill-extrusion layer. If true, sides will be shaded slightly darker farther down.
1846
- *
1847
- * @param value - fill-extrusion-vertical-gradient value (default `true`)
1848
- */
1849
- fillExtrusionVerticalGradient(value) {
1850
- this.addStyle("fill-extrusion-vertical-gradient", value);
1851
- return this;
1852
- }
1853
- }
1854
- MapLayerStyleBuilder.registerStyleBuilder("fill-extrusion", FillExtrusionLayerStyleBuilder);
1855
- class RasterLayerStyleBuilder extends MapLayerStyleBuilder {
1856
- /**
1857
- * The opacity at which the image will be drawn.
1858
- *
1859
- * @param value - raster-opacity value (default `1`)
1860
- */
1861
- rasterOpacity(value) {
1862
- this.addStyle("raster-opacity", value);
1863
- return this;
1864
- }
1865
- /**
1866
- * Rotates hues around the color wheel.
1867
- *
1868
- * @param value - raster-hue-rotate value in degrees
1869
- */
1870
- rasterHueRotate(value) {
1871
- this.addStyle("raster-hue-rotate", value);
1872
- return this;
1873
- }
1874
- /**
1875
- * Increase or reduce the brightness of the image. The value is the minimum brightness.
1876
- *
1877
- * @param value - raster-brightness-min value
1878
- */
1879
- rasterBrightnessMin(value) {
1880
- this.addStyle("raster-brightness-min", value);
1881
- return this;
1882
- }
1883
- /**
1884
- * Increase or reduce the brightness of the image. The value is the maximum brightness.
1885
- *
1886
- * @param value - raster-brightness-max value (default `1`)
1887
- */
1888
- rasterBrightnessMax(value) {
1889
- this.addStyle("raster-brightness-max", value);
1890
- return this;
1891
- }
1892
- /**
1893
- * Increase or reduce the saturation of the image.
1894
- *
1895
- * @param value - raster-saturation value
1896
- */
1897
- rasterSaturation(value) {
1898
- this.addStyle("raster-saturation", value);
1899
- return this;
1900
- }
1901
- /**
1902
- * Increase or reduce the contrast of the image.
1903
- *
1904
- * @param value - raster-contrast value
1905
- */
1906
- rasterContrast(value) {
1907
- this.addStyle("raster-contrast", value);
1908
- return this;
1909
- }
1910
- /**
1911
- * The resampling/interpolation method to use for overscaling, also known as texture magnification filter
1912
- *
1913
- * Values:
1914
- * - linear: (Bi)linear filtering interpolates pixel values using the weighted average of the four closest original source pixels creating a smooth but blurry look when overscaled
1915
- * - nearest: Nearest neighbor filtering interpolates pixel values using the nearest original source pixel creating a sharp but pixelated look when overscaled
1916
- *
1917
- * @param value - raster-resampling value (default `linear`)
1918
- */
1919
- rasterResampling(value) {
1920
- this.addStyle("raster-resampling", value);
1921
- return this;
1922
- }
1923
- /**
1924
- * Fade duration when a new tile is added.
1925
- *
1926
- * @param value - raster-fade-duration value in milliseconds (default `300`)
1927
- */
1928
- rasterFadeDuration(value) {
1929
- this.addStyle("raster-fade-duration", value);
1930
- return this;
1931
- }
1932
- }
1933
- MapLayerStyleBuilder.registerStyleBuilder("raster", RasterLayerStyleBuilder);
1934
- class HillshadeLayerStyleBuilder extends MapLayerStyleBuilder {
1935
- /**
1936
- * The direction of the light source used to generate the hillshading with 0 as the top of the viewport if `hillshade-illumination-anchor` is set to `viewport` and due north if `hillshade-illumination-anchor` is set to `map`.
1937
- *
1938
- * @param value - hillshade-illumination-direction value (default `335`)
1939
- */
1940
- hillshadeIlluminationDirection(value) {
1941
- this.addStyle("hillshade-illumination-direction", value);
1942
- return this;
1943
- }
1944
- /**
1945
- * Direction of light source when map is rotated.
1946
- *
1947
- * Values:
1948
- * - map: The hillshade illumination is relative to the north direction.
1949
- * - viewport: The hillshade illumination is relative to the top of the viewport.
1950
- *
1951
- * @param value - hillshade-illumination-anchor value (default `viewport`)
1952
- */
1953
- hillshadeIlluminationAnchor(value) {
1954
- this.addStyle("hillshade-illumination-anchor", value);
1955
- return this;
1956
- }
1957
- /**
1958
- * Intensity of the hillshade
1959
- *
1960
- * @param value - hillshade-exaggeration value (default `0.5`)
1961
- */
1962
- hillshadeExaggeration(value) {
1963
- this.addStyle("hillshade-exaggeration", value);
1964
- return this;
1965
- }
1966
- /**
1967
- * The shading color of areas that face away from the light source.
1968
- *
1969
- * @param value - hillshade-shadow-color value (default `#000000`)
1970
- */
1971
- hillshadeShadowColor(value) {
1972
- this.addStyle("hillshade-shadow-color", value);
1973
- return this;
1974
- }
1975
- /**
1976
- * The shading color of areas that faces towards the light source.
1977
- *
1978
- * @param value - hillshade-highlight-color value (default `#FFFFFF`)
1979
- */
1980
- hillshadeHighlightColor(value) {
1981
- this.addStyle("hillshade-highlight-color", value);
1982
- return this;
1983
- }
1984
- /**
1985
- * The shading color used to accentuate rugged terrain like sharp cliffs and gorges.
1986
- *
1987
- * @param value - hillshade-accent-color value (default `#000000`)
1988
- */
1989
- hillshadeAccentColor(value) {
1990
- this.addStyle("hillshade-accent-color", value);
1991
- return this;
1992
- }
1993
- }
1994
- MapLayerStyleBuilder.registerStyleBuilder("hillshade", HillshadeLayerStyleBuilder);
1995
- class BackgroundLayerStyleBuilder extends MapLayerStyleBuilder {
1996
- /**
1997
- * The color with which the background will be drawn.
1998
- *
1999
- * @param value - background-color value (default `#000000`)
2000
- */
2001
- backgroundColor(value) {
2002
- this.addStyle("background-color", value);
2003
- return this;
2004
- }
2005
- /**
2006
- * Name of image in sprite to use for drawing an image background. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). Note that zoom-dependent expressions will be evaluated only at integer zoom levels.
2007
- *
2008
- * @param value - background-pattern value
2009
- */
2010
- backgroundPattern(value) {
2011
- this.addStyle("background-pattern", value);
2012
- return this;
2013
- }
2014
- /**
2015
- * The opacity at which the background will be drawn.
2016
- *
2017
- * @param value - background-opacity value (default `1`)
2018
- */
2019
- backgroundOpacity(value) {
2020
- this.addStyle("background-opacity", value);
2021
- return this;
2022
- }
2023
- }
2024
- MapLayerStyleBuilder.registerStyleBuilder("background", BackgroundLayerStyleBuilder);
2025
- function layerStyle(layerType) {
2026
- return MapLayerStyleBuilder.createStyleBuilder(layerType);
2027
- }
2028
-
2029
- var __defProp$5 = Object.defineProperty;
2030
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2031
- var __publicField$5 = (obj, key, value) => {
2032
- __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
2033
- return value;
2034
- };
2035
- const _MapStyle = class _MapStyle {
2036
- constructor() {
2037
- __publicField$5(this, "_state", null);
2038
- __publicField$5(this, "_baseStyle");
2039
- __publicField$5(this, "_sources", {});
2040
- __publicField$5(this, "_layers", {});
2041
- __publicField$5(this, "_layerOrder", []);
2042
- this._baseStyle = _MapStyle._defaultBaseStyle;
2043
- mobx.makeObservable(
2044
- this,
2045
- {
2046
- //observable
2047
- _sources: mobx.observable,
2048
- _layers: mobx.observable,
2049
- _layerOrder: mobx.observable,
2050
- _baseStyle: mobx.observable.ref,
2051
- //computed
2052
- styleSpecification: mobx.computed,
2053
- // actions
2054
- bindState: mobx.action,
2055
- setBaseStyle: mobx.action,
2056
- addSource: mobx.action,
2057
- removeSource: mobx.action,
2058
- addLayer: mobx.action,
2059
- removeLayer: mobx.action
2060
- },
2061
- { name: this.formattedName }
2062
- );
2063
- }
2064
- get styleSpecification() {
2065
- const spec = {
2066
- ...this._baseStyle,
2067
- sources: { ...this._baseStyle.sources },
2068
- layers: [...this._baseStyle.layers]
2069
- };
2070
- Object.values(this._sources).forEach((source) => {
2071
- spec.sources[source.id] = source.dataSourceSpecification;
2072
- });
2073
- this._layerOrder.forEach((id) => {
2074
- const layer = this._layers[id];
2075
- const layerSpec = layer.layerSpecification;
2076
- const baseLayerIndex = spec.layers.findIndex((l) => l.id === id);
2077
- if (baseLayerIndex >= 0) {
2078
- const baseLayer = spec.layers[baseLayerIndex];
2079
- const mergedBaseLayer = {
2080
- ...baseLayer,
2081
- paint: {
2082
- ...baseLayer.paint,
2083
- ...layerSpec.paint
2084
- },
2085
- layout: {
2086
- ...baseLayer.layout,
2087
- ...layerSpec.layout
2088
- }
2089
- };
2090
- spec.layers.splice(baseLayerIndex, 1, mergedBaseLayer);
2091
- } else {
2092
- const source = spec.sources[layer.source];
2093
- if (source.type === "vector" && randomId.isNil(layerSpec["source-layer"])) {
2094
- layerSpec["source-layer"] = "geometry";
2095
- }
2096
- const layerIndex = this.layerInsertionPoint(layer, spec);
2097
- spec.layers.splice(layerIndex, 0, layer.layerSpecification);
2098
- }
2099
- });
2100
- return spec;
2101
- }
2102
- get formattedName() {
2103
- return `MapStyle<${this._baseStyle.id}>`;
2104
- }
2105
- bindState(state) {
2106
- this._state = state;
2107
- state.transaction(() => {
2108
- Object.values(this._sources).forEach((source) => source.bindState(state));
2109
- Object.values(this._layers).forEach((layer) => layer.bindState(state));
2110
- });
2111
- return this;
2112
- }
2113
- setBaseStyle(style) {
2114
- this._baseStyle = style ? Object.freeze({ ...style }) : _MapStyle._defaultBaseStyle;
2115
- return this;
2116
- }
2117
- addSource(source) {
2118
- this._sources[source.id] = source;
2119
- source.bindState(this._state);
2120
- return this;
2121
- }
2122
- removeSource(id, removeLayers = false) {
2123
- if (!this._sources[id]) {
2124
- throw new mapFeatureStream.FlowError(`${this.formattedName}: no source with id '${id}'`);
2125
- }
2126
- const linkedLayers = Object.values(this._layers).filter((layer) => layer.source === id).map((layer) => layer.id);
2127
- if (removeLayers) {
2128
- linkedLayers.forEach((id2) => this.removeLayer(id2));
2129
- } else if (linkedLayers.length) {
2130
- throw new mapFeatureStream.FlowError(
2131
- `${this.formattedName}: cannot remove source with id '${id}' when in use by layers ${linkedLayers.join(", ")}`
2132
- );
2133
- }
2134
- delete this._sources[id];
2135
- return this;
2136
- }
2137
- getSource(id) {
2138
- const source = this._sources[id];
2139
- if (!source) {
2140
- throw new mapFeatureStream.FlowError(`${this.formattedName}: no source with id '${id}'`);
2141
- }
2142
- return source;
2143
- }
2144
- getSources(filter) {
2145
- return Object.values(this._sources).filter((source) => filter ? filter(source) : true);
2146
- }
2147
- addLayer(layer) {
2148
- if (!this._sources[layer.source] && !this._baseStyle.sources[layer.source]) {
2149
- throw new mapFeatureStream.FlowError(`${this.formattedName}: no source with id '${layer.source}'`);
2150
- }
2151
- this._layers[layer.id] = layer;
2152
- this._layerOrder.push(layer.id);
2153
- layer.bindState(this._state);
2154
- return this;
2155
- }
2156
- removeLayer(id) {
2157
- if (!this._layers[id]) {
2158
- throw new mapFeatureStream.FlowError(`${this.formattedName}: no layer with id '${id}'`);
2159
- }
2160
- delete this._layers[id];
2161
- const index = this._layerOrder.indexOf(id);
2162
- this._layerOrder.splice(index, 1);
2163
- return this;
2164
- }
2165
- getLayer(id) {
2166
- const layer = this._layers[id];
2167
- if (!layer) {
2168
- throw new mapFeatureStream.FlowError(`${this.formattedName}: no layer with id '${id}'`);
2169
- }
2170
- return layer;
2171
- }
2172
- getLayers(filter) {
2173
- return this._layerOrder.map((layerId) => this._layers[layerId]).filter((layer) => filter ? filter(layer) : true);
2174
- }
2175
- layerInsertionPoint(layer, spec) {
2176
- let insertionIndex = -1;
2177
- if (layer.above) {
2178
- insertionIndex = spec.layers.findIndex((l) => l.id === layer.above);
2179
- if (insertionIndex >= 0)
2180
- insertionIndex++;
2181
- } else if (layer.below) {
2182
- insertionIndex = spec.layers.findIndex((l) => l.id === layer.below);
2183
- } else {
2184
- const below = spec.metadata?.insertionPoints?.[layer.type];
2185
- insertionIndex = spec.layers.findIndex((l) => l.id === below);
2186
- }
2187
- if (insertionIndex === -1) {
2188
- insertionIndex = spec.layers.length;
2189
- }
2190
- return insertionIndex;
2191
- }
2192
- };
2193
- __publicField$5(_MapStyle, "_defaultBaseStyle", Object.freeze({
2194
- version: 8,
2195
- id: "default",
2196
- name: "Default base style",
2197
- sources: {},
2198
- layers: []
2199
- }));
2200
- let MapStyle = _MapStyle;
2201
-
2202
- var __defProp$4 = Object.defineProperty;
2203
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2204
- var __publicField$4 = (obj, key, value) => {
2205
- __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
2206
- return value;
2207
- };
2208
- Debug__default("flow:image-registry");
2209
- const unknownImageSVG = `data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512' class='flowicon'%3E%3C!--! Font Awesome Free 6.1.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc.--%3E%3Cpath d='M256 0C114.6 0 0 114.6 0 256s114.6 256 256 256 256-114.6 256-256S397.4 0 256 0zm0 400c-18 0-32-14-32-32s13.1-32 32-32c17.1 0 32 14 32 32s-14.9 32-32 32zm69.1-142L280 286v2c0 13-11 24-24 24s-24-11-24-24v-16c0-8 4-16 12-21l57-34c7-4 11-11 11-19 0-12-10.9-22-22.9-22H238c-12.9 0-22 10-22 22 0 13-11 24-24 24s-24-11-24-24c0-39 31-70 69.1-70h51.1c40.8 0 71.8 31 71.8 70 0 24-13 47-34.9 60z'/%3E%3C/svg%3E`;
2210
- class ImageRegistry {
2211
- constructor() {
2212
- __publicField$4(this, "_registry", /* @__PURE__ */ new Map());
2213
- __publicField$4(this, "_unknownImage", null);
2214
- }
2215
- get unknownImage() {
2216
- if (!this._unknownImage) {
2217
- const image = new Image(40, 40);
2218
- image.src = unknownImageSVG;
2219
- this._unknownImage = {
2220
- id: "unknown-image",
2221
- src: unknownImageSVG,
2222
- pixelDensity: 2,
2223
- image
2224
- };
2225
- }
2226
- return this._unknownImage;
2227
- }
2228
- /**
2229
- * Register a map icon image.
2230
- *
2231
- * @param id Image ID.
2232
- * @param src Image source URL.
2233
- * @param width Image display width.
2234
- * @param height Image display height.
2235
- * @param pixelDensity Image pixel density. Defaults to `2` - the source image should be @2x resolution to enable better quality rendering on high-resolution displays.
2236
- * @param recolor Set to `true` to allow recoloring of map icon image using map layer style properties.
2237
- */
2238
- registerImage(id, src, width, height, pixelDensity = 2, recolor = false) {
2239
- const entry = { id, src, width, height, pixelDensity, recolor };
2240
- this._registry.set(id, entry);
2241
- return entry;
2242
- }
2243
- /**
2244
- * Get an image registry entry.
2245
- *
2246
- * @param id Image ID.
2247
- * @returns The image registry entry.
2248
- */
2249
- getImage(id) {
2250
- const registryEntry = this._registry.get(id);
2251
- if (!registryEntry) {
2252
- return this.unknownImage;
2253
- }
2254
- if (!registryEntry.image) {
2255
- registryEntry.image = this.loadImage(
2256
- registryEntry.src,
2257
- registryEntry.width,
2258
- registryEntry.height,
2259
- registryEntry.pixelDensity
2260
- );
2261
- }
2262
- return registryEntry;
2263
- }
2264
- /**
2265
- *
2266
- * @param src Image source URL.
2267
- * @param width Image display width in pixels.
2268
- * @param height Image display height in pixels.
2269
- * @param pixelDensity Image pixel density. Defaults to `2` - the source image should be @2x resolution to enable better quality rendering on high-resolution displays.
2270
- */
2271
- loadImage(src, width, height, pixelDensity = 2) {
2272
- const image = new Image();
2273
- image.crossOrigin = "Anonymous";
2274
- image.width = width ? width * pixelDensity : image.width;
2275
- image.height = height ? height * pixelDensity : image.height;
2276
- image.src = src;
2277
- return image;
2278
- }
2279
- }
2280
-
2281
- var __defProp$3 = Object.defineProperty;
2282
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2283
- var __publicField$3 = (obj, key, value) => {
2284
- __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
2285
- return value;
2286
- };
2287
- const debug$1 = Debug__default("flow:map");
2288
- const MOUSE_MOVE_THROTTLE_DURATION = 100;
2289
- const _FlowCoreMap = class _FlowCoreMap extends EventEmitter__default {
2290
- constructor(options) {
2291
- super();
2292
- __publicField$3(this, "_context");
2293
- __publicField$3(this, "_initialized");
2294
- __publicField$3(this, "_loading", true);
2295
- __publicField$3(this, "_debouncedEmitSourceEvent");
2296
- __publicField$3(this, "_imageRegistry", new ImageRegistry());
2297
- __publicField$3(this, "_options");
2298
- __publicField$3(this, "_pluginManager");
2299
- __publicField$3(this, "_resolveInitialized", () => {
2300
- });
2301
- __publicField$3(this, "_style");
2302
- __publicField$3(this, "_styleUpdateSubscription", null);
2303
- __publicField$3(this, "_throttledMouseMove", throttle.throttle(this.handleMouseMove, MOUSE_MOVE_THROTTLE_DURATION, { context: this }));
2304
- __publicField$3(this, "maplibreMap");
2305
- __publicField$3(this, "updateMapStyle", (style) => {
2306
- const oldStyle = this.maplibreMap.getStyle();
2307
- const beforeEvent = new mapFeatureStream.MapStyleChangeEvent("beforeStyleChanged", this, oldStyle, style);
2308
- style = this._pluginManager.forwardStyleChangeEvent(
2309
- new mapFeatureStream.MapStyleChangeEvent("beforeStyleChanged", this, oldStyle, style)
2310
- );
2311
- this.emit(beforeEvent.type, beforeEvent);
2312
- debug$1(`${this.formattedName}: Updating style`, style);
2313
- this.maplibreMap.setStyle(style);
2314
- this.emitEvent(new mapFeatureStream.MapStyleChangeEvent("styleChanged", this, oldStyle, style));
2315
- });
2316
- this._options = {
2317
- id: randomId.randomId("map"),
2318
- ..._FlowCoreMap._defaultOptions,
2319
- ...options
2320
- };
2321
- this._style = new MapStyle();
2322
- this._debouncedEmitSourceEvent = throttle.debounceWithArgs(this.emitEvent, 20, {
2323
- hash: (event) => event.source,
2324
- context: this
2325
- });
2326
- this._initialized = new Promise((resolve) => {
2327
- this._resolveInitialized = resolve;
2328
- });
2329
- this._pluginManager = new mapFeatureStream.PluginManager(this);
2330
- this.initialize();
2331
- }
2332
- get context() {
2333
- return this._context;
2334
- }
2335
- get container() {
2336
- return this.maplibreMap.getContainer();
2337
- }
2338
- get id() {
2339
- return this._options.id;
2340
- }
2341
- get initialized() {
2342
- return this._initialized;
2343
- }
2344
- get styleSpecification() {
2345
- return this._style.styleSpecification;
2346
- }
2347
- /**
2348
- * @internal
2349
- *
2350
- * Used by map export to get images added to map.
2351
- */
2352
- get imageRegistry() {
2353
- return this._imageRegistry;
2354
- }
2355
- addLayer(layerOrOptions) {
2356
- const layer = randomId.isPlainObject(layerOrOptions) ? new mapFeatureStream.MapLayer(layerOrOptions) : layerOrOptions;
2357
- this._style.addLayer(layer);
2358
- return layer;
2359
- }
2360
- addSource(sourceOrOptions) {
2361
- const source = randomId.isPlainObject(sourceOrOptions) ? new mapFeatureStream.MapDataSource(sourceOrOptions) : sourceOrOptions;
2362
- this.emitEvent(new mapFeatureStream.MapSourceEvent("beforeSourceAdded", this, source.id));
2363
- source.setFlowEndpoint({
2364
- host: this.context.flowClient.baseUrl,
2365
- apiKey: this.context.flowClient.apiKey || void 0
2366
- });
2367
- this._style.addSource(source);
2368
- this.emitEvent(new mapFeatureStream.MapSourceEvent("sourceAdded", this, source.id));
2369
- return source;
2370
- }
2371
- destroy() {
2372
- this._pluginManager.removeAllPlugins();
2373
- this._styleUpdateSubscription?.unsubscribe();
2374
- this.maplibreMap?.remove();
2375
- if (this.context) {
2376
- this.context.maps.unregisterMap(this);
2377
- }
2378
- this.emit("destroyed", new mapFeatureStream.MapEvent("destroyed", this));
2379
- }
2380
- emitError(message, originalError) {
2381
- const error = new mapFeatureStream.FlowMapError(`${this.formattedName}: ${message}`, originalError);
2382
- this._pluginManager.forwardEvent("error", error);
2383
- if (this.listenerCount("error")) {
2384
- this.emit("error", error);
2385
- } else {
2386
- console.error(error);
2387
- }
2388
- }
2389
- emitEvent(event) {
2390
- this._pluginManager.forwardEvent(event.type, event);
2391
- this.emit(event.type, event);
2392
- }
2393
- featureStream(options) {
2394
- return new mapFeatureStream.MapFeatureStream({ map: this, ...options });
2395
- }
2396
- get formattedName() {
2397
- return `FlowMap<${this._options.id}>`;
2398
- }
2399
- getFeatureState(feature) {
2400
- return this.maplibreMap.getFeatureState(feature);
2401
- }
2402
- getLayer(id) {
2403
- return this._style.getLayer(id);
2404
- }
2405
- getLayers(filter) {
2406
- return this._style.getLayers(filter);
2407
- }
2408
- getPlugin(pluginOrName) {
2409
- return this._pluginManager.getPlugin(pluginOrName);
2410
- }
2411
- getSource(id) {
2412
- return this._style.getSource(id);
2413
- }
2414
- getSources(filter) {
2415
- return this._style.getSources(filter);
2416
- }
2417
- /**
2418
- * Register a map icon image.
2419
- *
2420
- * @param id Image ID.
2421
- * @param src Image source URL.
2422
- * @param width Image display width.
2423
- * @param height Image display height.
2424
- * @param pixelDensity Image pixel density. Defaults to `2` - the source image should be @2x resolution to enable better quality rendering on high-resolution displays.
2425
- * @param recolor Set to `true` to allow recoloring of map icon image using map layer style properties.
2426
- */
2427
- registerImage(id, src, width, height, pixelDensity = 2, recolor = false) {
2428
- debug$1(`${this.formattedName}: Registering image '${id}'`);
2429
- this._imageRegistry.registerImage(id, src, width, height, pixelDensity, recolor);
2430
- }
2431
- /**
2432
- * Programmatically remove feature state properties from a map feature.
2433
- *
2434
- * @param feature Feature to modify. Specify `null` to modify all map features.
2435
- * @param key Feature state key to remove. Specify `null` to remove all feature state for specified feature(s).
2436
- */
2437
- removeFeatureState(feature, key, fireEvent = true) {
2438
- if (randomId.isNil(feature.id) && randomId.isDefined(key)) {
2439
- const style = this.maplibreMap.style;
2440
- style._checkLoaded();
2441
- const sourceId = feature.source;
2442
- const sourceCache = style.sourceCaches[sourceId];
2443
- if (sourceCache === void 0) {
2444
- throw new mapFeatureStream.FlowError(`${this.formattedName}: the source '${sourceId}' does not exist in the map's style.`);
2445
- }
2446
- const sourceState = sourceCache._state;
2447
- const sourceType = sourceCache.getSource().type;
2448
- const sourceLayer = sourceType === "vector" ? feature.sourceLayer ?? "geometry" : "_geojsonTileLayer";
2449
- sourceState.deletedStates[sourceLayer] = sourceState.deletedStates[sourceLayer] || {};
2450
- const sourceLayerDeleted = sourceState.deletedStates[sourceLayer] === null;
2451
- if (sourceLayerDeleted) {
2452
- return;
2453
- }
2454
- if (sourceState.state[sourceLayer]) {
2455
- Object.keys(sourceState.state[sourceLayer]).forEach((feature2) => {
2456
- if (sourceState.deletedStates[sourceLayer][feature2] !== null) {
2457
- sourceState.deletedStates[sourceLayer][feature2] = sourceState.deletedStates[sourceLayer][feature2] || {};
2458
- sourceState.deletedStates[sourceLayer][feature2][key] = null;
2459
- }
2460
- });
2461
- }
2462
- this.maplibreMap._update();
2463
- } else {
2464
- this.maplibreMap.removeFeatureState(feature, key);
2465
- }
2466
- if (fireEvent) {
2467
- const sourceEvent = new mapFeatureStream.MapSourceEvent("sourceFeatureState", this, feature.source);
2468
- this._debouncedEmitSourceEvent(sourceEvent);
2469
- }
2470
- }
2471
- removeLayer(id) {
2472
- this._style.removeLayer(id);
2473
- return this;
2474
- }
2475
- removeSource(id, removeLayers = false) {
2476
- this.emitEvent(new mapFeatureStream.MapSourceEvent("beforeSourceRemoved", this, id));
2477
- this._style.removeSource(id, removeLayers);
2478
- this.emitEvent(new mapFeatureStream.MapSourceEvent("sourceRemoved", this, id));
2479
- return this;
2480
- }
2481
- async setBaseStyle(style) {
2482
- const baseStyle = await this.loadBaseStyle(style);
2483
- this._style.setBaseStyle(baseStyle);
2484
- }
2485
- getCenter() {
2486
- const lngLat = this.maplibreMap.getCenter();
2487
- const zoom = this.maplibreMap.getZoom();
2488
- const bearing = this.maplibreMap.getBearing();
2489
- const pitch = this.maplibreMap.getPitch();
2490
- return {
2491
- lng: lngLat.lng,
2492
- lat: lngLat.lat,
2493
- zoom,
2494
- bearing,
2495
- pitch
2496
- };
2497
- }
2498
- setCenter(center, animationOptions) {
2499
- const lngLat = randomId.isDefined(center.lng) && randomId.isDefined(center.lat) ? new maplibre__default.LngLat(center.lng, center.lat) : void 0;
2500
- let method = this.maplibreMap.jumpTo;
2501
- if (animationOptions) {
2502
- switch (animationOptions.mode) {
2503
- case "ease":
2504
- method = this.maplibreMap.easeTo;
2505
- break;
2506
- case "fly":
2507
- method = this.maplibreMap.flyTo;
2508
- break;
2509
- default:
2510
- method = this.maplibreMap.jumpTo;
2511
- }
2512
- }
2513
- const options = {
2514
- center: lngLat,
2515
- ...randomId.isDefined(center.zoom) && { zoom: center.zoom },
2516
- ...randomId.isDefined(center.bearing) && { bearing: center.bearing },
2517
- ...randomId.isDefined(center.pitch) && { pitch: center.pitch },
2518
- ...animationOptions
2519
- };
2520
- method.call(this.maplibreMap, options);
2521
- return this;
2522
- }
2523
- getBounds() {
2524
- const bounds = this.maplibreMap.getBounds();
2525
- return [bounds.getWest(), bounds.getSouth(), bounds.getEast(), bounds.getNorth()];
2526
- }
2527
- setBounds(bounds, options) {
2528
- const fitBoundsOptions = {
2529
- linear: !options || options.mode === "ease" || options.mode === "jump",
2530
- animate: !!options && options.mode !== "jump",
2531
- ...options
2532
- };
2533
- this.maplibreMap.fitBounds(bounds, fitBoundsOptions);
2534
- }
2535
- getVisibleBounds() {
2536
- const parentEl = this.container.parentElement;
2537
- if (!parentEl) {
2538
- return this.getBounds();
2539
- }
2540
- const mapRect = parentEl.getBoundingClientRect();
2541
- const topLeft = this.maplibreMap.unproject([mapRect.x, mapRect.y]);
2542
- const bottomRight = this.maplibreMap.unproject([mapRect.x + mapRect.width, mapRect.y + mapRect.height]);
2543
- const bounds = [topLeft.lng, bottomRight.lat, bottomRight.lng, topLeft.lat];
2544
- return bounds;
2545
- }
2546
- /**
2547
- * Programmatically set feature state properties for a map feature.
2548
- *
2549
- * @param feature Feature to modify.
2550
- * @param state Feature state properties to set.
2551
- */
2552
- setFeatureState(feature, state, fireEvent = true) {
2553
- const source = this.getSource(feature.source);
2554
- mapFeatureStream.assert(
2555
- randomId.isDefined(source.featureId),
2556
- `${this.formattedName}: cannot set feature state (source '${source.id}' has not featureId specified)`
2557
- );
2558
- if (source?.type === "vector") {
2559
- feature.sourceLayer = feature.sourceLayer || "geometry";
2560
- }
2561
- this.maplibreMap.setFeatureState(feature, state);
2562
- if (fireEvent) {
2563
- const sourceEvent = new mapFeatureStream.MapSourceEvent("sourceFeatureState", this, feature.source);
2564
- this._debouncedEmitSourceEvent(sourceEvent);
2565
- }
2566
- }
2567
- setFeatureStateBulk(sourceId, featureState) {
2568
- const source = this.getSource(sourceId.source);
2569
- mapFeatureStream.assert(randomId.isStringFull(source.featureId));
2570
- this.maplibreMap.style._checkLoaded();
2571
- const sourceCache = this.maplibreMap.style.sourceCaches[sourceId.source];
2572
- if (randomId.isUndefined(sourceCache)) {
2573
- throw new mapFeatureStream.FlowError(
2574
- `${this.formattedName}: the source '${sourceId.source}' does not exist in the map's style.`
2575
- );
2576
- }
2577
- const sourceLayer = sourceCache.getSource().type === "vector" ? sourceId.sourceLayer ?? "geometry" : "";
2578
- Object.keys(featureState).forEach((featureId) => {
2579
- sourceCache.setFeatureState(sourceLayer, featureId, featureState[featureId]);
2580
- });
2581
- this.maplibreMap._update();
2582
- const sourceEvent = new mapFeatureStream.MapSourceEvent("sourceFeatureState", this, sourceId.source);
2583
- this._debouncedEmitSourceEvent(sourceEvent);
2584
- }
2585
- transaction(fn) {
2586
- mobx.runInAction(() => fn());
2587
- }
2588
- usePlugin(plugin, options) {
2589
- return this._pluginManager.usePlugin(plugin, options);
2590
- }
2591
- usePlugins(plugins) {
2592
- plugins.forEach((plugin) => this.usePlugin(plugin));
2593
- }
2594
- bindMapEvents() {
2595
- this.maplibreMap.on("error", (e) => this.emitError(e.error.message, e.error));
2596
- this.maplibreMap.on("mousemove", this._throttledMouseMove);
2597
- this.maplibreMap.on("mouseout", this._throttledMouseMove);
2598
- this.maplibreMap.on("click", this.handleMouseClick("click").bind(this));
2599
- this.maplibreMap.on("dblclick", this.handleMouseClick("dblClick").bind(this));
2600
- this.maplibreMap.on("styleimagemissing", this.handleMissingImage.bind(this));
2601
- this.maplibreMap.on("sourcedata", this.handleLoading.bind(this));
2602
- this.maplibreMap.on("idle", this.handleLoading.bind(this));
2603
- const eventsToForward = ["moveEnd"];
2604
- eventsToForward.forEach((eventName) => {
2605
- this.maplibreMap.on(eventName.toLowerCase(), (event) => {
2606
- const flowEvent = mapFeatureStream.MapEvent.fromMaplibreEvent(eventName, this, event);
2607
- this.emitEvent(flowEvent);
2608
- });
2609
- });
2610
- }
2611
- featureFromMaplibreFeature(feature) {
2612
- return {
2613
- id: feature.id,
2614
- geometry: feature.geometry,
2615
- source: feature.source,
2616
- sourceLayer: feature.sourceLayer,
2617
- layer: feature.layer.id,
2618
- properties: feature.properties,
2619
- state: feature.state
2620
- };
2621
- }
2622
- featureQueryBox(event) {
2623
- const queryBox = this._options.featureClickTolerance ? [
2624
- [event.point.x - this._options.featureClickTolerance, event.point.y - this._options.featureClickTolerance],
2625
- [event.point.x + this._options.featureClickTolerance, event.point.y + this._options.featureClickTolerance]
2626
- ] : event.point;
2627
- return queryBox;
2628
- }
2629
- async handleLoading(event) {
2630
- let loading = false;
2631
- if (event.type === "sourcedata" && event.isSourceLoaded === false) {
2632
- loading = true;
2633
- } else if (event.type === "idle") {
2634
- loading = false;
2635
- } else {
2636
- loading = !!Object.values(this.maplibreMap.style.sourceCaches).find((cache) => !cache.loaded());
2637
- }
2638
- if (this._loading !== loading) {
2639
- const loadingEvent = new mapFeatureStream.MapLoadingEvent(this, loading);
2640
- this.emitEvent(loadingEvent);
2641
- this._loading = loading;
2642
- }
2643
- }
2644
- async handleMissingImage(event) {
2645
- const imageInfo = this._imageRegistry.getImage(event.id);
2646
- if (imageInfo === this._imageRegistry.unknownImage) {
2647
- console.error(`${this.formattedName}: Image '${event.id}' not registered`);
2648
- }
2649
- if (!imageInfo.image.complete) {
2650
- imageInfo.image.onload = () => {
2651
- this.maplibreMap.updateImage(event.id, imageInfo.image);
2652
- this.maplibreMap.redraw();
2653
- };
2654
- }
2655
- this.maplibreMap.addImage(event.id, imageInfo.image, {
2656
- pixelRatio: imageInfo.pixelDensity,
2657
- sdf: imageInfo.recolor
2658
- });
2659
- }
2660
- handleMouseClick(type) {
2661
- return (event) => {
2662
- const layerIds = this._style.getLayers((layer) => layer.interactive).map((layer) => layer.id);
2663
- const features = this.maplibreMap.queryRenderedFeatures(this.featureQueryBox(event), { layers: layerIds }).map(this.featureFromMaplibreFeature.bind(this));
2664
- if (features.length) {
2665
- debug$1(`${this.formattedName} Feature ${type}ed`, features[0]);
2666
- }
2667
- const flowEvent = mapFeatureStream.MapMouseEvent.fromMaplibreMouseEvent(type, event, this, features);
2668
- this.emitEvent(flowEvent);
2669
- };
2670
- }
2671
- handleMouseMove(event) {
2672
- if (event.type === "mousemove") {
2673
- const layerIds = this._style.getLayers((layer) => layer.interactive).map((layer) => layer.id);
2674
- const features = this.maplibreMap.queryRenderedFeatures(this.featureQueryBox(event), { layers: layerIds }).map(this.featureFromMaplibreFeature.bind(this));
2675
- const flowEvent = mapFeatureStream.MapMouseEvent.fromMaplibreMouseEvent("mouseMove", event, this, features);
2676
- this.emitEvent(flowEvent);
2677
- } else if (event.type === "mouseout") {
2678
- const flowEvent = mapFeatureStream.MapMouseEvent.fromMaplibreMouseEvent("mouseOut", event, this, []);
2679
- this.emitEvent(flowEvent);
2680
- }
2681
- }
2682
- async initialize() {
2683
- const globalContextRegistry = getGlobalState().globalContextRegistry;
2684
- this._context = await globalContextRegistry.getContext(this._options.contextId);
2685
- this._style.bindState(this._context.state);
2686
- const baseStyle = await this.loadBaseStyle(this._options.baseStyle);
2687
- this._style.setBaseStyle(baseStyle);
2688
- this.maplibreMap = new maplibre__default.Map({
2689
- ...this._options,
2690
- transformRequest: this.transformMapRequest.bind(this),
2691
- style: baseStyle
2692
- });
2693
- this.maplibreMap.once("load", () => {
2694
- this._styleUpdateSubscription = mobxUtils.toStream(() => this._style.styleSpecification, false).subscribe(
2695
- this.updateMapStyle
2696
- );
2697
- this.bindMapEvents();
2698
- this._resolveInitialized();
2699
- debug$1(`${this.formattedName}: initialized with options`, this._options);
2700
- this.context.maps.registerMap(this);
2701
- });
2702
- }
2703
- async loadBaseStyle(style) {
2704
- if (randomId.isURL(style)) {
2705
- return fetch(style).then((resp) => resp.json());
2706
- } else if (randomId.isString(style)) {
2707
- return this.context.flowClient.maps.get(style);
2708
- } else {
2709
- return style;
2710
- }
2711
- }
2712
- transformMapRequest(url, resourceType) {
2713
- const requestParameters = { url };
2714
- if (this.context.flowClient.accessToken && url.startsWith(this.context.flowClient.baseUrl)) {
2715
- requestParameters.headers = { Authorization: `Bearer ${this.context.flowClient.accessToken}` };
2716
- }
2717
- return requestParameters;
2718
- }
2719
- };
2720
- __publicField$3(_FlowCoreMap, "_defaultOptions", {
2721
- boxZoom: false,
2722
- doubleClickZoom: false,
2723
- featureClickTolerance: 0
2724
- });
2725
- let FlowCoreMap = _FlowCoreMap;
2726
-
2727
- var __defProp$2 = Object.defineProperty;
2728
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2729
- var __publicField$2 = (obj, key, value) => {
2730
- __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
2731
- return value;
2732
- };
2733
- class AsyncCommitter {
2734
- constructor() {
2735
- __publicField$2(this, "_requestId", 0);
2736
- __publicField$2(this, "_commitId", 0);
2737
- }
2738
- async resolve(promise) {
2739
- this._requestId += 1;
2740
- const currentRequestId = this._requestId;
2741
- const value = await promise;
2742
- if (currentRequestId <= this._commitId) {
2743
- return { succeeded: false };
2744
- }
2745
- this._commitId = currentRequestId;
2746
- return { succeeded: true, value };
2747
- }
2748
- async run(asyncFunction) {
2749
- return this.resolve(asyncFunction());
2750
- }
2751
- abandon() {
2752
- this._commitId = this._requestId;
2753
- }
2754
- }
2755
-
2756
- var __defProp$1 = Object.defineProperty;
2757
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2758
- var __publicField$1 = (obj, key, value) => {
2759
- __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
2760
- return value;
2761
- };
2762
- const debug = Debug__default("flow:query");
2763
- const DEFAULT_DELAY = 100;
2764
- const _Query = class _Query {
2765
- constructor(queryFn, transformFn, options) {
2766
- this.queryFn = queryFn;
2767
- __publicField$1(this, "_options");
2768
- __publicField$1(this, "_committer", new AsyncCommitter());
2769
- __publicField$1(this, "_disposer", null);
2770
- __publicField$1(this, "_transformFn", (results) => results);
2771
- __publicField$1(this, "results", null);
2772
- __publicField$1(this, "busy", false);
2773
- __publicField$1(this, "error", null);
2774
- this._options = {
2775
- ..._Query._defaultOptions,
2776
- ...options
2777
- };
2778
- this._options.id = this._options.id ?? randomId.randomId("query");
2779
- mobx.makeObservable(
2780
- this,
2781
- {
2782
- results: mobx.observable.ref,
2783
- busy: mobx.observable,
2784
- error: mobx.observable.ref
2785
- },
2786
- {
2787
- name: "flowQuery"
2788
- }
2789
- );
2790
- mobx.onBecomeObserved(this, "results", this.wake.bind(this));
2791
- mobx.onBecomeUnobserved(this, "results", this.sleep.bind(this));
2792
- if (transformFn) {
2793
- this._transformFn = transformFn;
2794
- }
2795
- getGlobalState().globalContextRegistry.getContext(this._options?.contextId).then((context) => {
2796
- context.queries.registerQuery(this);
2797
- });
2798
- }
2799
- static setDefaultOptions(options) {
2800
- this._defaultOptions = { ...this._defaultOptions, ...options };
2801
- }
2802
- get formattedName() {
2803
- return `Query<${this._options.id}>`;
2804
- }
2805
- get id() {
2806
- return this._options.id;
2807
- }
2808
- destroy() {
2809
- getGlobalState().globalContextRegistry.getContext(this._options?.contextId).then((context) => {
2810
- context.queries.unregisterQuery(this);
2811
- });
2812
- }
2813
- async runImmediately() {
2814
- const context = await getGlobalState().globalContextRegistry.getContext(this._options.contextId);
2815
- const queryDefinition = this.queryFn.call(context.state, context.state);
2816
- await this.runQuery(queryDefinition);
2817
- if (this.error) {
2818
- throw this.error;
2819
- }
2820
- return this.results;
2821
- }
2822
- async wake() {
2823
- this.sleep();
2824
- const context = await getGlobalState().globalContextRegistry.getContext(this._options.contextId);
2825
- this._disposer = mobx.reaction(
2826
- (r) => {
2827
- return this.queryFn.call(context.state, context.state);
2828
- },
2829
- (queryDefinition, prev, r) => {
2830
- this.runQuery(queryDefinition);
2831
- },
2832
- { name: this.formattedName, fireImmediately: this._options.fireImmediately, delay: this._options.delay }
2833
- );
2834
- }
2835
- sleep() {
2836
- if (this._disposer) {
2837
- mobx.runInAction(() => {
2838
- this.results = null;
2839
- this.error = null;
2840
- this.busy = false;
2841
- this._committer.abandon();
2842
- });
2843
- const disposer = this._disposer;
2844
- this._disposer = null;
2845
- disposer();
2846
- }
2847
- }
2848
- async runQuery(queryDefinition) {
2849
- debug(`${this.formattedName}: running query`, queryDefinition);
2850
- const context = await getGlobalState().globalContextRegistry.getContext(this._options.contextId);
2851
- try {
2852
- if (queryDefinition === null) {
2853
- mobx.runInAction(() => {
2854
- this.results = null;
2855
- this.error = null;
2856
- this.busy = false;
2857
- });
2858
- } else {
2859
- mobx.runInAction(() => {
2860
- this.busy = true;
2861
- this.error = null;
2862
- });
2863
- const response = await this._committer.run(() => {
2864
- return context.flowClient.datasets.query(queryDefinition);
2865
- });
2866
- if (response.succeeded) {
2867
- mobx.runInAction(() => {
2868
- this.results = this._transformFn(response.value);
2869
- this.busy = false;
2870
- });
2871
- } else {
2872
- }
2873
- }
2874
- } catch (e) {
2875
- console.error(`${this.formattedName}: ${e.message}`);
2876
- mobx.runInAction(() => {
2877
- this.results = null;
2878
- this.error = e;
2879
- this.busy = false;
2880
- });
2881
- }
2882
- }
2883
- };
2884
- __publicField$1(_Query, "_defaultOptions", {
2885
- fireImmediately: true,
2886
- delay: DEFAULT_DELAY
2887
- });
2888
- let Query = _Query;
2889
- function query(queryFn, transformFnOrOptions, options) {
2890
- if (typeof transformFnOrOptions === "object") {
2891
- options = transformFnOrOptions;
2892
- transformFnOrOptions = void 0;
2893
- }
2894
- return new Query(queryFn, transformFnOrOptions, options);
2895
- }
2896
- function queryMany(queryFn, transformFnOrOptions, options) {
2897
- if (typeof transformFnOrOptions === "object") {
2898
- options = transformFnOrOptions;
2899
- transformFnOrOptions = void 0;
2900
- }
2901
- return query(queryFn, transformFnOrOptions, options);
2902
- }
2903
- function queryOne(queryFn, transformFnOrOptions, options) {
2904
- if (typeof transformFnOrOptions === "object") {
2905
- options = transformFnOrOptions;
2906
- transformFnOrOptions = void 0;
2907
- }
2908
- const oneTransform = (results) => {
2909
- let oneResult = null;
2910
- if (results?.length) {
2911
- oneResult = results[0];
2912
- }
2913
- if (transformFnOrOptions && typeof transformFnOrOptions === "function") {
2914
- oneResult = transformFnOrOptions(oneResult);
2915
- }
2916
- return oneResult;
2917
- };
2918
- return query(queryFn, oneTransform, options);
2919
- }
2920
-
2921
- const storedAnnotationsSymbol = Symbol("flow-rdf-annotations");
2922
- function createDecoratorAnnotation(annotation) {
2923
- function decorator(target, property) {
2924
- storeAnnotation(target, property, annotation);
2925
- }
2926
- return Object.assign(decorator, annotation);
2927
- }
2928
- function storeAnnotation(prototype, key, annotation) {
2929
- var _a, _b;
2930
- if (!hasProp(prototype, storedAnnotationsSymbol)) {
2931
- addHiddenProp(prototype, storedAnnotationsSymbol, {
2932
- // Inherit annotations
2933
- ...prototype[storedAnnotationsSymbol]
2934
- });
2935
- }
2936
- (_a = prototype[storedAnnotationsSymbol])[_b = annotation.annotationType] ?? (_a[_b] = {});
2937
- assertNotDecorated(prototype, annotation, key);
2938
- prototype[storedAnnotationsSymbol][annotation.annotationType][key] = annotation;
2939
- }
2940
- function assertNotDecorated(prototype, annotation, key) {
2941
- if (hasProp(prototype[storedAnnotationsSymbol][annotation.annotationType], key)) {
2942
- const fieldName = `${prototype.constructor.name}.prototype.${key.toString()}`;
2943
- const currentAnnotationType = prototype[storedAnnotationsSymbol][key].annotationType_;
2944
- const requestedAnnotationType = annotation.annotationType;
2945
- mapFeatureStream.die(
2946
- `Cannot apply '@${requestedAnnotationType}' to '${fieldName}':
2947
- The field is already decorated with '@${currentAnnotationType}'.
2948
- Re-decorating fields is not allowed.
2949
- Use '@override' decorator for methods overridden by subclass.`
2950
- );
2951
- }
2952
- }
2953
- function collectStoredAnnotations(target, annotationType) {
2954
- return target[storedAnnotationsSymbol]?.[annotationType] ?? {};
2955
- }
2956
- function addHiddenProp(object, propName, value) {
2957
- Object.defineProperty(object, propName, {
2958
- enumerable: false,
2959
- writable: true,
2960
- configurable: true,
2961
- value
2962
- });
2963
- }
2964
- function hasProp(target, prop) {
2965
- return Object.hasOwnProperty.call(target, prop);
2966
- }
2967
-
2968
- const SYNC_ANNOTATION_TYPE = "state-sync-annotation";
2969
- const REACTIVE_ANNOTATION_TYPE = "state-reactive-annotation";
2970
- const serializeRaw = {
2971
- annotationType: SYNC_ANNOTATION_TYPE,
2972
- serialize(val) {
2973
- return mobx.toJS(val);
2974
- },
2975
- deserialize(val) {
2976
- return val;
2977
- }
2978
- };
2979
- const serializeString = {
2980
- annotationType: SYNC_ANNOTATION_TYPE,
2981
- serialize(val) {
2982
- return val.toString();
2983
- },
2984
- deserialize(val) {
2985
- return val;
2986
- }
2987
- };
2988
- const serializeNumber = {
2989
- annotationType: SYNC_ANNOTATION_TYPE,
2990
- serialize(val) {
2991
- return val.toString();
2992
- },
2993
- deserialize(val) {
2994
- return +val;
2995
- }
2996
- };
2997
- const serializeJson = {
2998
- annotationType: SYNC_ANNOTATION_TYPE,
2999
- serialize(val) {
3000
- return JSON.stringify(val);
3001
- },
3002
- deserialize(val) {
3003
- return JSON.parse(val);
3004
- }
3005
- };
3006
- const serializeState = {
3007
- annotationType: SYNC_ANNOTATION_TYPE,
3008
- serialize(val) {
3009
- return val.serialize();
3010
- },
3011
- deserialize(val, target) {
3012
- target.deserialize(val);
3013
- return target;
3014
- }
3015
- };
3016
- const serialize = Object.assign(createDecoratorAnnotation(serializeRaw), {
3017
- raw: createDecoratorAnnotation(serializeRaw),
3018
- string: createDecoratorAnnotation(serializeString),
3019
- number: createDecoratorAnnotation(serializeNumber),
3020
- json: createDecoratorAnnotation(serializeJson),
3021
- state: createDecoratorAnnotation(serializeState)
3022
- });
3023
- function createReactiveAnnotation(mobxAnnotation) {
3024
- return createDecoratorAnnotation({
3025
- annotationType: REACTIVE_ANNOTATION_TYPE,
3026
- mobxAnnotation
3027
- });
3028
- }
3029
- const observable = Object.assign(createReactiveAnnotation(mobx__namespace.observable), {
3030
- deep: createReactiveAnnotation(mobx__namespace.observable.deep),
3031
- ref: createReactiveAnnotation(mobx__namespace.observable.ref),
3032
- struct: createReactiveAnnotation(mobx__namespace.observable.struct),
3033
- shallow: createReactiveAnnotation(mobx__namespace.observable.shallow)
3034
- });
3035
- const computed = Object.assign(createReactiveAnnotation(mobx__namespace.computed), {
3036
- struct: createReactiveAnnotation(mobx__namespace.computed.struct)
3037
- });
3038
-
3039
- var __defProp = Object.defineProperty;
3040
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3041
- var __publicField = (obj, key, value) => {
3042
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
3043
- return value;
3044
- };
3045
- const StateStoreMarker = Symbol("FlowCoreStateStoreMarker");
3046
- const StateStorCache = Symbol("FlowCoreStateStorCache");
3047
- class StateStore {
3048
- constructor() {
3049
- __publicField(this, "serializationAnnotations", {});
3050
- __publicField(this, "id");
3051
- this.id = randomId.randomId("state");
3052
- }
3053
- get formattedName() {
3054
- return `StateStore<${this.id}>`;
3055
- }
3056
- get initialized() {
3057
- return mobx__namespace.isObservable(this);
3058
- }
3059
- get(path) {
3060
- this.checkInitialized();
3061
- const pathStr = path;
3062
- let value = this;
3063
- const p = pathStr.split(".");
3064
- let k;
3065
- while (k = p.shift()) {
3066
- value = value[k];
3067
- }
3068
- return value;
3069
- }
3070
- set(path, val) {
3071
- this.checkInitialized();
3072
- const pathArray = path.split(".");
3073
- let k;
3074
- let value = this;
3075
- while (pathArray.length > 1) {
3076
- k = pathArray.shift();
3077
- value = value[k];
3078
- }
3079
- k = pathArray.shift();
3080
- value[k] = val;
3081
- }
3082
- transaction(fn) {
3083
- this.checkInitialized();
3084
- mobx__namespace.runInAction(() => fn(this));
3085
- }
3086
- toggle(path) {
3087
- this.checkInitialized();
3088
- const val = !this.get(path);
3089
- this.set(path, val);
3090
- return val;
3091
- }
3092
- increment(path) {
3093
- this.checkInitialized();
3094
- const val = +this.get(path) + 1;
3095
- this.set(path, val);
3096
- return val;
3097
- }
3098
- decrement(path) {
3099
- this.checkInitialized();
3100
- const val = +this.get(path) - 1;
3101
- this.set(path, val);
3102
- return val;
3103
- }
3104
- bindControl(el, statePath, options) {
3105
- const toState = options?.toState ?? ((v) => v);
3106
- const fromState = options?.fromState ?? ((v) => v);
3107
- el.addEventListener("input", () => {
3108
- this.set(statePath, toState(el.value));
3109
- });
3110
- el.addEventListener("flow-ui-change", () => {
3111
- this.set(statePath, toState(el.value));
3112
- });
3113
- return this.toStream(statePath, true).subscribe((value) => {
3114
- if (value !== el.value) {
3115
- el.value = fromState(value);
3116
- }
3117
- });
3118
- }
3119
- bindElementProp(el, prop, statePath, options) {
3120
- const fromState = options?.fromState ?? ((v) => v);
3121
- return this.toStream(statePath, true).subscribe((value) => {
3122
- if (value !== el[prop]) {
3123
- el[prop] = fromState(value);
3124
- }
3125
- });
3126
- }
3127
- bindElementAttr(el, attr, statePath) {
3128
- return this.toStream(statePath, true).subscribe((value) => {
3129
- el.setAttribute(attr, value);
3130
- });
3131
- }
3132
- toStream(path, fireImmediately = true) {
3133
- this.checkInitialized();
3134
- return mobxUtils.toStream(() => this.get(path), fireImmediately);
3135
- }
3136
- autorun(autorunFn, name) {
3137
- this.checkInitialized();
3138
- return mobx__namespace.autorun(() => autorunFn(this), { name });
3139
- }
3140
- initialize(annotations = {}) {
3141
- if (this.initialized) {
3142
- throw new mapFeatureStream.FlowError(`${this.formattedName}: store has already been initialized`);
3143
- }
3144
- const annotationsByType = {
3145
- [REACTIVE_ANNOTATION_TYPE]: collectStoredAnnotations(this, REACTIVE_ANNOTATION_TYPE),
3146
- [SYNC_ANNOTATION_TYPE]: collectStoredAnnotations(this, SYNC_ANNOTATION_TYPE)
3147
- };
3148
- Object.keys(annotations).forEach((prop) => {
3149
- const propAnnotations = randomId.ensureArray(annotations[prop]);
3150
- propAnnotations.forEach((annotation) => {
3151
- const type = annotation.annotationType;
3152
- annotationsByType[type] ?? (annotationsByType[type] = {});
3153
- annotationsByType[type][prop] = annotation;
3154
- });
3155
- });
3156
- this.serializationAnnotations = annotationsByType[SYNC_ANNOTATION_TYPE];
3157
- if (Object.keys(annotationsByType[REACTIVE_ANNOTATION_TYPE]).length) {
3158
- const mobxAnnotations = Object.keys(annotationsByType[REACTIVE_ANNOTATION_TYPE]).reduce((accum, prop) => {
3159
- accum[prop] = annotationsByType[REACTIVE_ANNOTATION_TYPE][prop].mobxAnnotation;
3160
- return accum;
3161
- }, {});
3162
- this.makeObservable(mobxAnnotations);
3163
- } else {
3164
- this.makeAutoObservable();
3165
- }
3166
- }
3167
- makeObservable(overrides) {
3168
- if (this.initialized) {
3169
- throw new mapFeatureStream.FlowError(`${this.formattedName}: store is already observable`);
3170
- }
3171
- overrides = {
3172
- ...overrides,
3173
- set: mobx__namespace.action,
3174
- toggle: mobx__namespace.action,
3175
- increment: mobx__namespace.action,
3176
- decrement: mobx__namespace.action
3177
- };
3178
- mobx__namespace.makeObservable(this, overrides, { name: this.formattedName });
3179
- }
3180
- makeAutoObservable(overrides = {}) {
3181
- if (this.initialized) {
3182
- throw new mapFeatureStream.FlowError(`${this.formattedName}: store is already observable`);
3183
- }
3184
- const target = this;
3185
- overrides = {
3186
- ...overrides,
3187
- _initialized: false,
3188
- $mobx: false,
3189
- constructor: false
3190
- };
3191
- let annotations = target[StateStorCache];
3192
- if (!annotations) {
3193
- annotations = {};
3194
- let current = target;
3195
- while (current && !Object.prototype.hasOwnProperty.call(current, StateStoreMarker)) {
3196
- Reflect.ownKeys(current).forEach((k) => {
3197
- annotations[k] = !overrides ? true : k in overrides ? overrides[k] : true;
3198
- });
3199
- current = Object.getPrototypeOf(current);
3200
- }
3201
- const proto = Object.getPrototypeOf(target);
3202
- if (proto) {
3203
- Object.defineProperty(proto, StateStorCache, { value: annotations });
3204
- }
3205
- }
3206
- annotations = {
3207
- ...annotations,
3208
- set: mobx__namespace.action,
3209
- toggle: mobx__namespace.action,
3210
- increment: mobx__namespace.action,
3211
- decrement: mobx__namespace.action
3212
- };
3213
- return mobx__namespace.makeObservable(target, annotations, { name: this.formattedName });
3214
- }
3215
- serialize(format = "raw") {
3216
- const annotations = this.serializationAnnotations;
3217
- const serializedProps = Object.keys(annotations).reduce((accum, prop) => {
3218
- const val = this[prop];
3219
- if (randomId.isDefined(val)) {
3220
- const serializedValue = annotations[prop].serialize(val);
3221
- accum[prop] = serializedValue;
3222
- }
3223
- return accum;
3224
- }, {});
3225
- switch (format) {
3226
- case "json":
3227
- return JSON.stringify(serializedProps);
3228
- case "lz":
3229
- return lzString__default.compressToEncodedURIComponent(JSON.stringify(serializedProps));
3230
- default:
3231
- return serializedProps;
3232
- }
3233
- }
3234
- deserialize(value, format = "raw") {
3235
- let deserializedValue;
3236
- switch (format) {
3237
- case "json":
3238
- deserializedValue = JSON.parse(value);
3239
- break;
3240
- case "lz":
3241
- deserializedValue = JSON.parse(lzString__default.decompressFromEncodedURIComponent(value));
3242
- break;
3243
- default:
3244
- deserializedValue = value;
3245
- break;
3246
- }
3247
- this.transaction(() => {
3248
- const annotations = this.serializationAnnotations;
3249
- Object.keys(deserializedValue).forEach((prop) => {
3250
- const annotation = annotations[prop];
3251
- if (annotation) {
3252
- this[prop] = annotation.deserialize(deserializedValue[prop], this[prop]);
3253
- }
3254
- });
3255
- });
3256
- }
3257
- checkInitialized() {
3258
- if (!this.initialized) {
3259
- throw new mapFeatureStream.FlowError(
3260
- `${this.formattedName} not initialized. Please use one of the recommended methods to make this state store observable.`
3261
- );
3262
- }
3263
- }
3264
- }
3265
- StateStore.prototype[StateStoreMarker] = true;
3266
-
3267
- function traceReaction() {
3268
- mobx.trace();
3269
- }
3270
-
3271
- mobx.configure({ isolateGlobalState: false, useProxies: "always" });
3272
- const globalContextRegistry = getGlobalState().globalContextRegistry;
3273
- const initializeContext = globalContextRegistry.initializeContext.bind(globalContextRegistry);
3274
- const uninitializeContext = globalContextRegistry.uninitializeContext.bind(globalContextRegistry);
3275
- const getContext = globalContextRegistry.getContext.bind(globalContextRegistry);
3276
-
3277
- exports.makeAutoObservable = mobx.makeAutoObservable;
3278
- exports.makeObservable = mobx.makeObservable;
3279
- exports.MapDataSource = mapFeatureStream.MapDataSource;
3280
- exports.MapLayer = mapFeatureStream.MapLayer;
3281
- exports.ReactiveExpression = mapFeatureStream.ReactiveExpression;
3282
- exports.BackgroundLayerStyleBuilder = BackgroundLayerStyleBuilder;
3283
- exports.CircleLayerStyleBuilder = CircleLayerStyleBuilder;
3284
- exports.ContextRegistry = ContextRegistry;
3285
- exports.DEFAULT_CONTEXT_ID = DEFAULT_CONTEXT_ID;
3286
- exports.FillExtrusionLayerStyleBuilder = FillExtrusionLayerStyleBuilder;
3287
- exports.FillLayerStyleBuilder = FillLayerStyleBuilder;
3288
- exports.FlowContext = FlowContext;
3289
- exports.FlowCoreMap = FlowCoreMap;
3290
- exports.FlowRdfCoreGlobals = FlowRdfCoreGlobals;
3291
- exports.HeatmapLayerStyleBuilder = HeatmapLayerStyleBuilder;
3292
- exports.HillshadeLayerStyleBuilder = HillshadeLayerStyleBuilder;
3293
- exports.LineLayerStyleBuilder = LineLayerStyleBuilder;
3294
- exports.MapLayerStyleBuilder = MapLayerStyleBuilder;
3295
- exports.MapRegistry = MapRegistry;
3296
- exports.MapStyle = MapStyle;
3297
- exports.Query = Query;
3298
- exports.QueryRegistry = QueryRegistry;
3299
- exports.RasterLayerStyleBuilder = RasterLayerStyleBuilder;
3300
- exports.StateStore = StateStore;
3301
- exports.StyleExpression = StyleExpression;
3302
- exports.SymbolLayerStyleBuilder = SymbolLayerStyleBuilder;
3303
- exports.computed = computed;
3304
- exports.expr = expr;
3305
- exports.getContext = getContext;
3306
- exports.getGlobalState = getGlobalState;
3307
- exports.initializeContext = initializeContext;
3308
- exports.isolateGlobalState = isolateGlobalState;
3309
- exports.layerStyle = layerStyle;
3310
- exports.observable = observable;
3311
- exports.query = query;
3312
- exports.queryMany = queryMany;
3313
- exports.queryOne = queryOne;
3314
- exports.serialize = serialize;
3315
- exports.traceReaction = traceReaction;
3316
- exports.uninitializeContext = uninitializeContext;