@emuanalytics/flow-rdf-core 4.0.0-preview.2 → 4.0.0-preview.3

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.
@@ -17,6 +17,7 @@ const turfCircle = require('@turf/circle');
17
17
  const turfDistance = require('@turf/distance');
18
18
  const helpers = require('@turf/helpers');
19
19
  const mobx = require('mobx');
20
+ const fileSaver = require('file-saver');
20
21
  require('@emuanalytics/maplibre-gl-style-spec');
21
22
  require('mobx-utils');
22
23
  require('parsimmon');
@@ -51,21 +52,21 @@ const maplibre__default = /*#__PURE__*/_interopDefaultCompat(maplibre);
51
52
  const turfCircle__default = /*#__PURE__*/_interopDefaultCompat(turfCircle);
52
53
  const turfDistance__default = /*#__PURE__*/_interopDefaultCompat(turfDistance);
53
54
 
54
- var __defProp$a = Object.defineProperty;
55
- var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
56
- var __publicField$a = (obj, key, value) => {
57
- __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
55
+ var __defProp$c = Object.defineProperty;
56
+ var __defNormalProp$c = (obj, key, value) => key in obj ? __defProp$c(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
57
+ var __publicField$c = (obj, key, value) => {
58
+ __defNormalProp$c(obj, typeof key !== "symbol" ? key + "" : key, value);
58
59
  return value;
59
60
  };
60
61
  class AnnotationEvent extends mapFeatureStream.MapEvent {
61
62
  constructor(type, map, data) {
62
63
  super(type, map);
63
- __publicField$a(this, "mode");
64
- __publicField$a(this, "canUndo");
65
- __publicField$a(this, "canRedo");
66
- __publicField$a(this, "activeFeatureId");
67
- __publicField$a(this, "activeFeatureType");
68
- __publicField$a(this, "features");
64
+ __publicField$c(this, "mode");
65
+ __publicField$c(this, "canUndo");
66
+ __publicField$c(this, "canRedo");
67
+ __publicField$c(this, "activeFeatureId");
68
+ __publicField$c(this, "activeFeatureType");
69
+ __publicField$c(this, "features");
69
70
  this.mode = data.mode;
70
71
  this.canUndo = data.canUndo;
71
72
  this.canRedo = data.canRedo;
@@ -75,17 +76,17 @@ class AnnotationEvent extends mapFeatureStream.MapEvent {
75
76
  }
76
77
  }
77
78
 
78
- var __defProp$9 = Object.defineProperty;
79
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
80
- var __publicField$9 = (obj, key, value) => {
81
- __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
79
+ var __defProp$b = Object.defineProperty;
80
+ var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
81
+ var __publicField$b = (obj, key, value) => {
82
+ __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
82
83
  return value;
83
84
  };
84
85
  class MapPluginBase extends EventEmitter.EventEmitter {
85
86
  constructor(pluginManager, options) {
86
87
  super();
87
- __publicField$9(this, "_pluginManager");
88
- __publicField$9(this, "options");
88
+ __publicField$b(this, "_pluginManager");
89
+ __publicField$b(this, "options");
89
90
  this._pluginManager = pluginManager;
90
91
  this.options = options ?? {};
91
92
  }
@@ -101,10 +102,10 @@ function isFeatureWithId(f) {
101
102
  return stringUtils.isDefined(f) && stringUtils.isDefined(f.source) && stringUtils.isDefined(f.id);
102
103
  }
103
104
 
104
- var __defProp$8 = Object.defineProperty;
105
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
106
- var __publicField$8 = (obj, key, value) => {
107
- __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
105
+ var __defProp$a = Object.defineProperty;
106
+ var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
107
+ var __publicField$a = (obj, key, value) => {
108
+ __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
108
109
  return value;
109
110
  };
110
111
  Debug__default("flow:map-popup");
@@ -121,12 +122,12 @@ class MapPopup extends EventEmitter__default {
121
122
  super();
122
123
  this.map = map;
123
124
  this.options = options;
124
- __publicField$8(this, "_feature");
125
- __publicField$8(this, "_contentContainer");
126
- __publicField$8(this, "_featureStream", null);
125
+ __publicField$a(this, "_feature");
126
+ __publicField$a(this, "_contentContainer");
127
+ __publicField$a(this, "_featureStream", null);
127
128
  //private _featureStreamSubscription: ISubscription | null = null;
128
- __publicField$8(this, "_maplibrePopup", null);
129
- __publicField$8(this, "_featureStreamDisposer");
129
+ __publicField$a(this, "_maplibrePopup", null);
130
+ __publicField$a(this, "_featureStreamDisposer");
130
131
  this.options = {
131
132
  // Defaults
132
133
  closeButton: true,
@@ -251,18 +252,18 @@ class MapPopup extends EventEmitter__default {
251
252
  }
252
253
  }
253
254
 
254
- var __defProp$7 = Object.defineProperty;
255
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
256
- var __publicField$7 = (obj, key, value) => {
257
- __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
255
+ var __defProp$9 = Object.defineProperty;
256
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
257
+ var __publicField$9 = (obj, key, value) => {
258
+ __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
258
259
  return value;
259
260
  };
260
261
  class PopupPlugin extends MapPluginBase {
261
262
  constructor(pluginManager) {
262
263
  super(pluginManager);
263
- __publicField$7(this, "_popupTemplates", /* @__PURE__ */ new Map());
264
- __publicField$7(this, "_popups", /* @__PURE__ */ new Set());
265
- __publicField$7(this, "name", "PopupPlugin");
264
+ __publicField$9(this, "_popupTemplates", /* @__PURE__ */ new Map());
265
+ __publicField$9(this, "_popups", /* @__PURE__ */ new Set());
266
+ __publicField$9(this, "name", "PopupPlugin");
266
267
  }
267
268
  registerPopup(id, options) {
268
269
  this._popupTemplates.set(id, options);
@@ -299,40 +300,40 @@ class PopupPlugin extends MapPluginBase {
299
300
  }
300
301
  }
301
302
 
302
- var __defProp$6 = Object.defineProperty;
303
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
304
- var __publicField$6 = (obj, key, value) => {
305
- __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
303
+ var __defProp$8 = Object.defineProperty;
304
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
305
+ var __publicField$8 = (obj, key, value) => {
306
+ __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
306
307
  return value;
307
308
  };
308
309
  class SelectionEvent extends mapFeatureStream.MapEvent {
309
310
  constructor(type, map, sourceIdentifier, features) {
310
311
  super(type, map);
311
- __publicField$6(this, "source");
312
- __publicField$6(this, "sourceLayer");
313
- __publicField$6(this, "features");
312
+ __publicField$8(this, "source");
313
+ __publicField$8(this, "sourceLayer");
314
+ __publicField$8(this, "features");
314
315
  this.source = sourceIdentifier.source;
315
316
  this.sourceLayer = sourceIdentifier.sourceLayer;
316
317
  this.features = features;
317
318
  }
318
319
  }
319
320
 
320
- var __defProp$5 = Object.defineProperty;
321
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
322
- var __publicField$5 = (obj, key, value) => {
323
- __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
321
+ var __defProp$7 = Object.defineProperty;
322
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
323
+ var __publicField$7 = (obj, key, value) => {
324
+ __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
324
325
  return value;
325
326
  };
326
327
  class SourceSelection {
327
328
  constructor(plugin, source, options) {
328
- __publicField$5(this, "_featureStream");
329
- __publicField$5(this, "_map");
330
- __publicField$5(this, "_options");
331
- __publicField$5(this, "_plugin");
332
- __publicField$5(this, "_popups", /* @__PURE__ */ new Map());
333
- __publicField$5(this, "_selectedFeatureIds", /* @__PURE__ */ new Set());
334
- __publicField$5(this, "_sourceId");
335
- __publicField$5(this, "_stateSubscription", null);
329
+ __publicField$7(this, "_featureStream");
330
+ __publicField$7(this, "_map");
331
+ __publicField$7(this, "_options");
332
+ __publicField$7(this, "_plugin");
333
+ __publicField$7(this, "_popups", /* @__PURE__ */ new Map());
334
+ __publicField$7(this, "_selectedFeatureIds", /* @__PURE__ */ new Set());
335
+ __publicField$7(this, "_sourceId");
336
+ __publicField$7(this, "_stateSubscription", null);
336
337
  this._plugin = plugin;
337
338
  this._map = plugin.map;
338
339
  this._options = options;
@@ -465,18 +466,18 @@ class SourceSelection {
465
466
  }
466
467
  }
467
468
 
468
- var __defProp$4 = Object.defineProperty;
469
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
470
- var __publicField$4 = (obj, key, value) => {
471
- __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
469
+ var __defProp$6 = Object.defineProperty;
470
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
471
+ var __publicField$6 = (obj, key, value) => {
472
+ __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
472
473
  return value;
473
474
  };
474
475
  class SelectionPlugin extends MapPluginBase {
475
476
  constructor(pluginManager) {
476
477
  super(pluginManager);
477
- __publicField$4(this, "_sourceSelections", /* @__PURE__ */ new Map());
478
- __publicField$4(this, "_enablePopups", true);
479
- __publicField$4(this, "name", "SelectionPlugin");
478
+ __publicField$6(this, "_sourceSelections", /* @__PURE__ */ new Map());
479
+ __publicField$6(this, "_enablePopups", true);
480
+ __publicField$6(this, "name", "SelectionPlugin");
480
481
  }
481
482
  clearSelection(source) {
482
483
  const sourceSelection = this._sourceSelections.get(source);
@@ -899,31 +900,31 @@ DragCircleMode.toDisplayFeatures = function(state, geojson, display) {
899
900
  };
900
901
  const DragCircleMode$1 = DragCircleMode;
901
902
 
902
- var __defProp$3 = Object.defineProperty;
903
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
904
- var __publicField$3 = (obj, key, value) => {
905
- __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
903
+ var __defProp$5 = Object.defineProperty;
904
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
905
+ var __publicField$5 = (obj, key, value) => {
906
+ __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
906
907
  return value;
907
908
  };
908
909
  Debug__default("flow:annotation-plugin");
909
910
  const _AnnotationPlugin = class _AnnotationPlugin extends MapPluginBase {
910
911
  constructor(pluginManager, options) {
911
912
  super(pluginManager, options);
912
- __publicField$3(this, "name", "AnnotationPlugin");
913
+ __publicField$5(this, "name", "AnnotationPlugin");
913
914
  // Feature data model
914
- __publicField$3(this, "_features", /* @__PURE__ */ new Map());
915
- __publicField$3(this, "_featureIds", []);
915
+ __publicField$5(this, "_features", /* @__PURE__ */ new Map());
916
+ __publicField$5(this, "_featureIds", []);
916
917
  // Undo/redo stacks
917
- __publicField$3(this, "_undoStack", []);
918
- __publicField$3(this, "_redoStack", []);
918
+ __publicField$5(this, "_undoStack", []);
919
+ __publicField$5(this, "_redoStack", []);
919
920
  // Editing state
920
- __publicField$3(this, "_mode", "idle");
921
- __publicField$3(this, "_activeFeatureId", null);
922
- __publicField$3(this, "_activeFeatureType", null);
923
- __publicField$3(this, "_onCommitCleanup", []);
924
- __publicField$3(this, "_annotationDataSource");
925
- __publicField$3(this, "_drawControl", null);
926
- __publicField$3(this, "_removeKeyboardShortcuts", null);
921
+ __publicField$5(this, "_mode", "idle");
922
+ __publicField$5(this, "_activeFeatureId", null);
923
+ __publicField$5(this, "_activeFeatureType", null);
924
+ __publicField$5(this, "_onCommitCleanup", []);
925
+ __publicField$5(this, "_annotationDataSource");
926
+ __publicField$5(this, "_drawControl", null);
927
+ __publicField$5(this, "_removeKeyboardShortcuts", null);
927
928
  this.options = { ..._AnnotationPlugin._defaultOptions, ...options };
928
929
  this.options.defaultStyle = { ..._AnnotationPlugin._defaultOptions.defaultStyle, ...options?.defaultStyle };
929
930
  }
@@ -1356,7 +1357,7 @@ const _AnnotationPlugin = class _AnnotationPlugin extends MapPluginBase {
1356
1357
  this.emit("annotationStateChanged", new AnnotationEvent("annotationStateChanged", this.map, eventData));
1357
1358
  }
1358
1359
  };
1359
- __publicField$3(_AnnotationPlugin, "_defaultOptions", {
1360
+ __publicField$5(_AnnotationPlugin, "_defaultOptions", {
1360
1361
  interactive: true,
1361
1362
  defaultStyle: {
1362
1363
  labelSize: 10,
@@ -1378,10 +1379,10 @@ __publicField$3(_AnnotationPlugin, "_defaultOptions", {
1378
1379
  });
1379
1380
  let AnnotationPlugin = _AnnotationPlugin;
1380
1381
 
1381
- var __defProp$2 = Object.defineProperty;
1382
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1383
- var __publicField$2 = (obj, key, value) => {
1384
- __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
1382
+ var __defProp$4 = Object.defineProperty;
1383
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1384
+ var __publicField$4 = (obj, key, value) => {
1385
+ __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
1385
1386
  return value;
1386
1387
  };
1387
1388
  const debug$1 = Debug__default("flow:data-join-map-plugin");
@@ -1389,10 +1390,10 @@ const _DataJoin = class _DataJoin {
1389
1390
  constructor(id, map, options) {
1390
1391
  this.id = id;
1391
1392
  this.map = map;
1392
- __publicField$2(this, "autorunDisposer", null);
1393
- __publicField$2(this, "dataExpression", null);
1394
- __publicField$2(this, "options");
1395
- __publicField$2(this, "parameterExpressions", {});
1393
+ __publicField$4(this, "autorunDisposer", null);
1394
+ __publicField$4(this, "dataExpression", null);
1395
+ __publicField$4(this, "options");
1396
+ __publicField$4(this, "parameterExpressions", {});
1396
1397
  this.options = {
1397
1398
  ..._DataJoin.defaultOptions,
1398
1399
  ...options
@@ -1499,7 +1500,7 @@ const _DataJoin = class _DataJoin {
1499
1500
  }
1500
1501
  }
1501
1502
  };
1502
- __publicField$2(_DataJoin, "defaultOptions", {
1503
+ __publicField$4(_DataJoin, "defaultOptions", {
1503
1504
  clear: false,
1504
1505
  parameters: []
1505
1506
  });
@@ -1507,8 +1508,8 @@ let DataJoin = _DataJoin;
1507
1508
  class DataJoinPlugin extends MapPluginBase {
1508
1509
  constructor(pluginManager) {
1509
1510
  super(pluginManager);
1510
- __publicField$2(this, "_joins", /* @__PURE__ */ new Map());
1511
- __publicField$2(this, "name", "DataJoinPlugin");
1511
+ __publicField$4(this, "_joins", /* @__PURE__ */ new Map());
1512
+ __publicField$4(this, "name", "DataJoinPlugin");
1512
1513
  }
1513
1514
  addDataJoin(id, options) {
1514
1515
  const dataJoin = new DataJoin(id, this.map, options);
@@ -1541,6 +1542,194 @@ class DataJoinPlugin extends MapPluginBase {
1541
1542
  }
1542
1543
  }
1543
1544
 
1545
+ var __defProp$3 = Object.defineProperty;
1546
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1547
+ var __publicField$3 = (obj, key, value) => {
1548
+ __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
1549
+ return value;
1550
+ };
1551
+ const _MapExporter = class _MapExporter {
1552
+ constructor(map) {
1553
+ this.map = map;
1554
+ __publicField$3(this, "nativePixelRatio", window.devicePixelRatio);
1555
+ }
1556
+ async export(options) {
1557
+ options = { ..._MapExporter.defaultOptions, ...options };
1558
+ const [container, mapCopy] = await this.createMapCopy(options);
1559
+ return new Promise((resolve, reject) => {
1560
+ const fileName = `${options.name}.${options.format}`;
1561
+ const mapCanvas = mapCopy.getCanvas();
1562
+ const exportCanvas = this.createExportCanvas(container, mapCanvas);
1563
+ const exportContext = exportCanvas.getContext("2d");
1564
+ if (!exportContext) {
1565
+ this.destroyMapCopy(container, mapCopy);
1566
+ reject(new Error("Failed to create export canvas context"));
1567
+ return;
1568
+ }
1569
+ const drawOverlayCallback = (err) => {
1570
+ if (err) {
1571
+ this.destroyMapCopy(container, mapCopy);
1572
+ reject(err);
1573
+ } else {
1574
+ switch (options.format) {
1575
+ case "png":
1576
+ exportCanvas.toBlob((blob) => {
1577
+ blob && fileSaver.saveAs(blob, fileName);
1578
+ });
1579
+ break;
1580
+ case "pdf":
1581
+ throw new Error("Export to PDF is not currently supported");
1582
+ }
1583
+ this.destroyMapCopy(container, mapCopy);
1584
+ resolve(fileName);
1585
+ }
1586
+ };
1587
+ const mapImage = new Image();
1588
+ mapImage.onload = () => {
1589
+ exportContext.drawImage(mapImage, 0, 0);
1590
+ if (stringUtils.isFunction(options.drawOverlayFn)) {
1591
+ options.drawOverlayFn(
1592
+ exportContext,
1593
+ exportCanvas.width,
1594
+ exportCanvas.height,
1595
+ options.dpmm,
1596
+ drawOverlayCallback
1597
+ );
1598
+ } else {
1599
+ drawOverlayCallback(null);
1600
+ }
1601
+ };
1602
+ mapImage.src = mapCopy.getCanvas().toDataURL();
1603
+ });
1604
+ }
1605
+ createMapCopy(options) {
1606
+ const geoBounds = options.bounds || this.map.maplibreMap.getBounds().toArray().flat();
1607
+ const geoBottomLeft = [geoBounds[0], geoBounds[1]];
1608
+ const geoTopRight = [geoBounds[2], geoBounds[3]];
1609
+ const geoCenter = [
1610
+ (geoBottomLeft[0] + geoTopRight[0]) / 2,
1611
+ (geoBottomLeft[1] + geoTopRight[1]) / 2
1612
+ ];
1613
+ const pxBottomLeft = this.map.maplibreMap.project(geoBottomLeft);
1614
+ const pxTopRight = this.map.maplibreMap.project(geoTopRight);
1615
+ const pxWidth = pxTopRight.x - pxBottomLeft.x;
1616
+ const pxHeight = pxBottomLeft.y - pxTopRight.y;
1617
+ const exportWidth = options.width * options.dpmm;
1618
+ const exportHeight = options.height * options.dpmm;
1619
+ const aspectRatios = {
1620
+ width: pxWidth / exportWidth,
1621
+ height: pxHeight / exportHeight
1622
+ };
1623
+ const coverRatio = Math.max(aspectRatios.width, aspectRatios.height);
1624
+ const copyWidth = exportWidth * coverRatio;
1625
+ const copyHeight = exportHeight * coverRatio;
1626
+ const pixelRatio = exportWidth / copyWidth;
1627
+ this.setDevicePixelRatio(pixelRatio);
1628
+ const container = document.createElement("div");
1629
+ container.id = mapFeatureStream.randomId("export");
1630
+ container.classList.add("maplibregl-export-container");
1631
+ container.style.width = `${copyWidth}px`;
1632
+ container.style.height = `${copyHeight}px`;
1633
+ this.map.container.insertBefore(container, this.map.container.firstChild);
1634
+ const mapCopy = new maplibre__default.Map({
1635
+ container,
1636
+ center: geoCenter,
1637
+ zoom: this.map.maplibreMap.getZoom(),
1638
+ style: { ...this.map.maplibreMap.getStyle(), transition: { delay: 0, duration: 0 } },
1639
+ bearing: this.map.maplibreMap.getBearing(),
1640
+ pitch: this.map.maplibreMap.getPitch(),
1641
+ interactive: false,
1642
+ attributionControl: false,
1643
+ fadeDuration: 0,
1644
+ preserveDrawingBuffer: true,
1645
+ transformRequest: this.transformMapRequest.bind(this)
1646
+ });
1647
+ mapCopy.on("styleimagemissing", this.handleMissingImage.bind(this));
1648
+ return new Promise((resolve) => {
1649
+ mapCopy.once("load", () => {
1650
+ Object.keys(this.map.maplibreMap.style.sourceCaches).forEach((sourceId) => {
1651
+ mapCopy.style.sourceCaches[sourceId]._state.stateChanges = this.map.maplibreMap.style.sourceCaches[sourceId]._state.state;
1652
+ });
1653
+ mapCopy._update();
1654
+ setTimeout(() => resolve([container, mapCopy]), 500);
1655
+ });
1656
+ });
1657
+ }
1658
+ destroyMapCopy(container, map) {
1659
+ this.setDevicePixelRatio(this.nativePixelRatio);
1660
+ map.remove();
1661
+ container.parentNode.removeChild(container);
1662
+ }
1663
+ createExportCanvas(container, mapCanvas) {
1664
+ const canvasContainer = container.getElementsByClassName("maplibregl-canvas-container")[0];
1665
+ const overlayCanvas = document.createElement("canvas");
1666
+ overlayCanvas.id = mapFeatureStream.randomId("overlay");
1667
+ overlayCanvas.width = mapCanvas.width;
1668
+ overlayCanvas.height = mapCanvas.height;
1669
+ overlayCanvas.style.position = "absolute";
1670
+ overlayCanvas.style.width = mapCanvas.style.width;
1671
+ overlayCanvas.style.height = mapCanvas.style.height;
1672
+ canvasContainer.appendChild(overlayCanvas);
1673
+ return overlayCanvas;
1674
+ }
1675
+ setDevicePixelRatio(pixelRatio) {
1676
+ Object.defineProperty(window, "devicePixelRatio", {
1677
+ get: () => pixelRatio
1678
+ });
1679
+ }
1680
+ async handleMissingImage(e) {
1681
+ const imageInfo = this.map.imageRegistry.getImage(e.id);
1682
+ if (imageInfo === this.map.imageRegistry.unknownImage) {
1683
+ console.error(`Map ${this.map.id}: Image '${e.id}' not registered`);
1684
+ }
1685
+ if (!imageInfo.image.complete) {
1686
+ imageInfo.image.onload = () => {
1687
+ this.map.maplibreMap.updateImage(e.id, imageInfo.image);
1688
+ this.map.maplibreMap.redraw();
1689
+ };
1690
+ }
1691
+ this.map.maplibreMap.addImage(e.id, imageInfo.image, {
1692
+ pixelRatio: imageInfo.pixelDensity,
1693
+ sdf: imageInfo.recolor
1694
+ });
1695
+ }
1696
+ transformMapRequest(url, _resourceType) {
1697
+ if (this.map.context.flowClient.accessToken && url.startsWith(this.map.context.flowClient.baseUrl)) {
1698
+ return {
1699
+ url,
1700
+ headers: { Authorization: `Bearer ${this.map.context.flowClient.accessToken}` }
1701
+ };
1702
+ } else {
1703
+ return { url };
1704
+ }
1705
+ }
1706
+ };
1707
+ __publicField$3(_MapExporter, "defaultOptions", {
1708
+ name: "map",
1709
+ width: 297,
1710
+ height: 210,
1711
+ dpmm: 12,
1712
+ format: "png"
1713
+ });
1714
+ let MapExporter = _MapExporter;
1715
+
1716
+ var __defProp$2 = Object.defineProperty;
1717
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1718
+ var __publicField$2 = (obj, key, value) => {
1719
+ __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
1720
+ return value;
1721
+ };
1722
+ class ExportPlugin extends MapPluginBase {
1723
+ constructor(pluginManager) {
1724
+ super(pluginManager);
1725
+ __publicField$2(this, "name", "ExportPlugin");
1726
+ }
1727
+ exportMap(options) {
1728
+ const mapExporter = new MapExporter(this.map);
1729
+ return mapExporter.export(options);
1730
+ }
1731
+ }
1732
+
1544
1733
  var __defProp$1 = Object.defineProperty;
1545
1734
  var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1546
1735
  var __publicField$1 = (obj, key, value) => {
@@ -1650,6 +1839,7 @@ exports.AnnotationEvent = AnnotationEvent;
1650
1839
  exports.AnnotationPlugin = AnnotationPlugin;
1651
1840
  exports.DataJoin = DataJoin;
1652
1841
  exports.DataJoinPlugin = DataJoinPlugin;
1842
+ exports.ExportPlugin = ExportPlugin;
1653
1843
  exports.HoverEffectPlugin = HoverEffectPlugin;
1654
1844
  exports.MapPluginBase = MapPluginBase;
1655
1845
  exports.PopupPlugin = PopupPlugin;
@@ -1,5 +1,5 @@
1
- import { Y as MapEvent, y as FlowMap, w as MapSourceIdentifier, Z as MapFeatureId, _ as MapPluginBase, $ as PluginManager, a0 as MapSourceEvent, a1 as MapMouseEvent, a2 as MapFeatureStream, a3 as PartialBy, r as MapAnimationOptions, a4 as MapStyleChangeEvent, M as MapStyleSpecification, S as StateStore, u as MapFeatureIdentifier, t as MapFeature } from '../../../shared/flow-rdf-core.42d7cda4.cjs';
2
- export { a8 as EventHandlers, a7 as PluginConstructor, a6 as PluginEventsType, a5 as PluginOptionsType } from '../../../shared/flow-rdf-core.42d7cda4.cjs';
1
+ import { Z as MapEvent, y as FlowMap, w as MapSourceIdentifier, _ as MapFeatureId, $ as MapPluginBase, a0 as PluginManager, a1 as MapSourceEvent, a2 as MapMouseEvent, a3 as MapFeatureStream, a4 as PartialBy, r as MapAnimationOptions, a5 as MapStyleChangeEvent, M as MapStyleSpecification, S as StateStore, u as MapFeatureIdentifier, t as MapFeature } from '../../../shared/flow-rdf-core.2f79285b.cjs';
2
+ export { a9 as EventHandlers, a8 as PluginConstructor, a7 as PluginEventsType, a6 as PluginOptionsType } from '../../../shared/flow-rdf-core.2f79285b.cjs';
3
3
  import { F as Func } from '../../../shared/flow-rdf-core.08975378.cjs';
4
4
  import EventEmitter from 'eventemitter3';
5
5
  import * as lit from 'lit-html';
@@ -206,6 +206,42 @@ declare class DataJoinPlugin extends MapPluginBase {
206
206
  removeDataJoin(id: string): void;
207
207
  }
208
208
 
209
+ /** Callback function to indicate map export overlay drawing has finished. */
210
+ type DrawOverlayCallback = (error: Error) => void;
211
+ /** Function to draw an overlay on an exported map. */
212
+ type DrawOverlayFn = (ctx: CanvasRenderingContext2D, width: number, height: number, dpmm: number, callback: DrawOverlayCallback) => void;
213
+ /**
214
+ * Options for [[FlowCoreMap.export]].
215
+ */
216
+ interface FlowMapExportOptions {
217
+ /** Name of exported file. */
218
+ name: string;
219
+ /** Width of exported map in millimeters. */
220
+ width: number;
221
+ /** Height of exported map in millimeters. */
222
+ height: number;
223
+ /** Resolution of exported map. Dots/mm. */
224
+ dpmm: number;
225
+ /** Format of exported map. */
226
+ format: 'png' | 'pdf';
227
+ /**
228
+ * Geographic bounds of area to export ([left, bottom, right top]).
229
+ *
230
+ * This should be a subregion of the full map area.
231
+ */
232
+ bounds?: number[];
233
+ /** Function called to draw overlay on exported map. */
234
+ drawOverlayFn?: DrawOverlayFn;
235
+ }
236
+
237
+ interface ExportPluginOptions {
238
+ }
239
+ declare class ExportPlugin extends MapPluginBase<ExportPluginOptions> {
240
+ readonly name = "ExportPlugin";
241
+ constructor(pluginManager: PluginManager);
242
+ exportMap(options: FlowMapExportOptions): Promise<string>;
243
+ }
244
+
209
245
  declare class HoverEffectPlugin extends MapPluginBase {
210
246
  private hoveredFeature;
211
247
  readonly name = "HoverEffectPlugin";
@@ -306,4 +342,4 @@ declare class UrlSyncPlugin extends MapPluginBase {
306
342
  private hashToMapState;
307
343
  }
308
344
 
309
- export { AnnotationEvent, AnnotationEventData, AnnotationEventType, AnnotationEventTypes, AnnotationFeature, AnnotationFeatureProps, AnnotationFeatureType, AnnotationMode, AnnotationOperation, AnnotationPlugin, AnnotationPluginOptions, AnnotationStyle, AnnotationsServiceConfig, DataJoin, DataJoinOptions, DataJoinPlugin, HoverEffectPlugin, MapPluginBase, PluginManager, PopupPlugin, SelectionEvent, SelectionEventType, SelectionEventTypes, SelectionMode, SelectionOptions, SelectionPlugin, UrlSyncPlugin };
345
+ export { AnnotationEvent, AnnotationEventData, AnnotationEventType, AnnotationEventTypes, AnnotationFeature, AnnotationFeatureProps, AnnotationFeatureType, AnnotationMode, AnnotationOperation, AnnotationPlugin, AnnotationPluginOptions, AnnotationStyle, AnnotationsServiceConfig, DataJoin, DataJoinOptions, DataJoinPlugin, DrawOverlayCallback, DrawOverlayFn, ExportPlugin, ExportPluginOptions, FlowMapExportOptions, HoverEffectPlugin, MapPluginBase, PluginManager, PopupPlugin, SelectionEvent, SelectionEventType, SelectionEventTypes, SelectionMode, SelectionOptions, SelectionPlugin, UrlSyncPlugin };
@@ -1,5 +1,5 @@
1
- import { Y as MapEvent, y as FlowMap, w as MapSourceIdentifier, Z as MapFeatureId, _ as MapPluginBase, $ as PluginManager, a0 as MapSourceEvent, a1 as MapMouseEvent, a2 as MapFeatureStream, a3 as PartialBy, r as MapAnimationOptions, a4 as MapStyleChangeEvent, M as MapStyleSpecification, S as StateStore, u as MapFeatureIdentifier, t as MapFeature } from '../../../shared/flow-rdf-core.42d7cda4.mjs';
2
- export { a8 as EventHandlers, a7 as PluginConstructor, a6 as PluginEventsType, a5 as PluginOptionsType } from '../../../shared/flow-rdf-core.42d7cda4.mjs';
1
+ import { Z as MapEvent, y as FlowMap, w as MapSourceIdentifier, _ as MapFeatureId, $ as MapPluginBase, a0 as PluginManager, a1 as MapSourceEvent, a2 as MapMouseEvent, a3 as MapFeatureStream, a4 as PartialBy, r as MapAnimationOptions, a5 as MapStyleChangeEvent, M as MapStyleSpecification, S as StateStore, u as MapFeatureIdentifier, t as MapFeature } from '../../../shared/flow-rdf-core.2f79285b.mjs';
2
+ export { a9 as EventHandlers, a8 as PluginConstructor, a7 as PluginEventsType, a6 as PluginOptionsType } from '../../../shared/flow-rdf-core.2f79285b.mjs';
3
3
  import { F as Func } from '../../../shared/flow-rdf-core.08975378.mjs';
4
4
  import EventEmitter from 'eventemitter3';
5
5
  import * as lit from 'lit-html';
@@ -206,6 +206,42 @@ declare class DataJoinPlugin extends MapPluginBase {
206
206
  removeDataJoin(id: string): void;
207
207
  }
208
208
 
209
+ /** Callback function to indicate map export overlay drawing has finished. */
210
+ type DrawOverlayCallback = (error: Error) => void;
211
+ /** Function to draw an overlay on an exported map. */
212
+ type DrawOverlayFn = (ctx: CanvasRenderingContext2D, width: number, height: number, dpmm: number, callback: DrawOverlayCallback) => void;
213
+ /**
214
+ * Options for [[FlowCoreMap.export]].
215
+ */
216
+ interface FlowMapExportOptions {
217
+ /** Name of exported file. */
218
+ name: string;
219
+ /** Width of exported map in millimeters. */
220
+ width: number;
221
+ /** Height of exported map in millimeters. */
222
+ height: number;
223
+ /** Resolution of exported map. Dots/mm. */
224
+ dpmm: number;
225
+ /** Format of exported map. */
226
+ format: 'png' | 'pdf';
227
+ /**
228
+ * Geographic bounds of area to export ([left, bottom, right top]).
229
+ *
230
+ * This should be a subregion of the full map area.
231
+ */
232
+ bounds?: number[];
233
+ /** Function called to draw overlay on exported map. */
234
+ drawOverlayFn?: DrawOverlayFn;
235
+ }
236
+
237
+ interface ExportPluginOptions {
238
+ }
239
+ declare class ExportPlugin extends MapPluginBase<ExportPluginOptions> {
240
+ readonly name = "ExportPlugin";
241
+ constructor(pluginManager: PluginManager);
242
+ exportMap(options: FlowMapExportOptions): Promise<string>;
243
+ }
244
+
209
245
  declare class HoverEffectPlugin extends MapPluginBase {
210
246
  private hoveredFeature;
211
247
  readonly name = "HoverEffectPlugin";
@@ -306,4 +342,4 @@ declare class UrlSyncPlugin extends MapPluginBase {
306
342
  private hashToMapState;
307
343
  }
308
344
 
309
- export { AnnotationEvent, AnnotationEventData, AnnotationEventType, AnnotationEventTypes, AnnotationFeature, AnnotationFeatureProps, AnnotationFeatureType, AnnotationMode, AnnotationOperation, AnnotationPlugin, AnnotationPluginOptions, AnnotationStyle, AnnotationsServiceConfig, DataJoin, DataJoinOptions, DataJoinPlugin, HoverEffectPlugin, MapPluginBase, PluginManager, PopupPlugin, SelectionEvent, SelectionEventType, SelectionEventTypes, SelectionMode, SelectionOptions, SelectionPlugin, UrlSyncPlugin };
345
+ export { AnnotationEvent, AnnotationEventData, AnnotationEventType, AnnotationEventTypes, AnnotationFeature, AnnotationFeatureProps, AnnotationFeatureType, AnnotationMode, AnnotationOperation, AnnotationPlugin, AnnotationPluginOptions, AnnotationStyle, AnnotationsServiceConfig, DataJoin, DataJoinOptions, DataJoinPlugin, DrawOverlayCallback, DrawOverlayFn, ExportPlugin, ExportPluginOptions, FlowMapExportOptions, HoverEffectPlugin, MapPluginBase, PluginManager, PopupPlugin, SelectionEvent, SelectionEventType, SelectionEventTypes, SelectionMode, SelectionOptions, SelectionPlugin, UrlSyncPlugin };