@mapcomponents/react-maplibre 0.1.92 → 0.1.95

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -57,6 +57,10 @@ var reactColor = require('react-color');
57
57
  var TuneIcon = require('@mui/icons-material/Tune');
58
58
  var ScatterPlotIcon = require('@mui/icons-material/ScatterPlot');
59
59
  var PolylineIcon = require('@mui/icons-material/Polyline');
60
+ var csv2geojson = require('csv2geojson');
61
+ var osm2geojson = require('osm2geojson-lite');
62
+ var topojsonClient = require('topojson-client');
63
+ var externParser = require('@tmcw/togeojson');
60
64
  var d3 = require('d3');
61
65
  var core = require('@dnd-kit/core');
62
66
  var modifiers = require('@dnd-kit/modifiers');
@@ -64,10 +68,6 @@ var PlaylistAddIcon = require('@mui/icons-material/PlaylistAdd');
64
68
  var DynamicFeedIcon = require('@mui/icons-material/DynamicFeed');
65
69
  var AddBoxIcon = require('@mui/icons-material/AddBox');
66
70
  var IndeterminateCheckBoxIcon = require('@mui/icons-material/IndeterminateCheckBox');
67
- var csv2geojson = require('csv2geojson');
68
- var topojsonClient = require('topojson-client');
69
- var osm2geojson = require('osm2geojson-lite');
70
- var externParser = require('@tmcw/togeojson');
71
71
  var KeyboardArrowDownIcon = require('@mui/icons-material/KeyboardArrowDown');
72
72
  var KeyboardArrowUpIcon = require('@mui/icons-material/KeyboardArrowUp');
73
73
  var AppBar = require('@mui/material/AppBar');
@@ -151,14 +151,14 @@ var Tooltip__default = /*#__PURE__*/_interopDefaultLegacy(Tooltip);
151
151
  var TuneIcon__default = /*#__PURE__*/_interopDefaultLegacy(TuneIcon);
152
152
  var ScatterPlotIcon__default = /*#__PURE__*/_interopDefaultLegacy(ScatterPlotIcon);
153
153
  var PolylineIcon__default = /*#__PURE__*/_interopDefaultLegacy(PolylineIcon);
154
+ var csv2geojson__namespace = /*#__PURE__*/_interopNamespace(csv2geojson);
155
+ var osm2geojson__default = /*#__PURE__*/_interopDefaultLegacy(osm2geojson);
156
+ var externParser__namespace = /*#__PURE__*/_interopNamespace(externParser);
154
157
  var d3__namespace = /*#__PURE__*/_interopNamespace(d3);
155
158
  var PlaylistAddIcon__default = /*#__PURE__*/_interopDefaultLegacy(PlaylistAddIcon);
156
159
  var DynamicFeedIcon__default = /*#__PURE__*/_interopDefaultLegacy(DynamicFeedIcon);
157
160
  var AddBoxIcon__default = /*#__PURE__*/_interopDefaultLegacy(AddBoxIcon);
158
161
  var IndeterminateCheckBoxIcon__default = /*#__PURE__*/_interopDefaultLegacy(IndeterminateCheckBoxIcon);
159
- var csv2geojson__namespace = /*#__PURE__*/_interopNamespace(csv2geojson);
160
- var osm2geojson__default = /*#__PURE__*/_interopDefaultLegacy(osm2geojson);
161
- var externParser__namespace = /*#__PURE__*/_interopNamespace(externParser);
162
162
  var KeyboardArrowDownIcon__default = /*#__PURE__*/_interopDefaultLegacy(KeyboardArrowDownIcon);
163
163
  var KeyboardArrowUpIcon__default = /*#__PURE__*/_interopDefaultLegacy(KeyboardArrowUpIcon);
164
164
  var AppBar__default = /*#__PURE__*/_interopDefaultLegacy(AppBar);
@@ -2437,7 +2437,7 @@ function useLayer(props) {
2437
2437
  var initializedRef = React.useRef(false);
2438
2438
  var layerId = React.useRef(props.layerId || (props.idPrefix ? props.idPrefix : 'Layer-') + mapHook.componentId);
2439
2439
  var createLayer = React.useCallback(function () {
2440
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
2440
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
2441
2441
  if (!mapHook.map || (mapHook === null || mapHook === void 0 ? void 0 : mapHook.map.cancelled))
2442
2442
  return;
2443
2443
  if (mapHook.map.map.getLayer(layerId.current)) {
@@ -2451,26 +2451,36 @@ function useLayer(props) {
2451
2451
  return;
2452
2452
  }
2453
2453
  }
2454
+ if (typeof ((_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.source) !== 'string' &&
2455
+ !props.geojson &&
2456
+ !((_d = (_c = props === null || props === void 0 ? void 0 : props.options) === null || _c === void 0 ? void 0 : _c.source) === null || _d === void 0 ? void 0 : _d.data) &&
2457
+ ((_e = props === null || props === void 0 ? void 0 : props.options) === null || _e === void 0 ? void 0 : _e.type) !== 'background') {
2458
+ return;
2459
+ }
2454
2460
  if (typeof props.options.type === 'undefined') {
2455
2461
  return;
2456
2462
  }
2457
2463
  initializedRef.current = true;
2458
2464
  try {
2459
2465
  mapHook.map.addLayer(__assign(__assign(__assign(__assign({}, props.options), (props.geojson &&
2460
- (!((_b = props.options) === null || _b === void 0 ? void 0 : _b.source) ||
2461
- (((_d = (_c = props.options) === null || _c === void 0 ? void 0 : _c.source) === null || _d === void 0 ? void 0 : _d.attribution) && !((_f = (_e = props.options) === null || _e === void 0 ? void 0 : _e.source) === null || _f === void 0 ? void 0 : _f.type))) // if either options.source isn't defined or only options.source.attribution is defined
2466
+ (!((_f = props.options) === null || _f === void 0 ? void 0 : _f.source) ||
2467
+ (typeof ((_g = props === null || props === void 0 ? void 0 : props.options) === null || _g === void 0 ? void 0 : _g.source) !== 'string' &&
2468
+ ((_j = (_h = props.options) === null || _h === void 0 ? void 0 : _h.source) === null || _j === void 0 ? void 0 : _j.attribution) &&
2469
+ !((_l = (_k = props.options) === null || _k === void 0 ? void 0 : _k.source) === null || _l === void 0 ? void 0 : _l.type))) // if either options.source isn't defined or only options.source.attribution is defined
2462
2470
  ? {
2463
2471
  source: {
2464
2472
  type: 'geojson',
2465
2473
  data: props.geojson,
2466
- attribution: ((_g = props.options.source) === null || _g === void 0 ? void 0 : _g.attribution)
2467
- ? (_h = props.options.source) === null || _h === void 0 ? void 0 : _h.attribution
2474
+ attribution: typeof ((_m = props === null || props === void 0 ? void 0 : props.options) === null || _m === void 0 ? void 0 : _m.source) !== 'string' && ((_o = props.options.source) === null || _o === void 0 ? void 0 : _o.attribution)
2475
+ ? (_p = props.options.source) === null || _p === void 0 ? void 0 : _p.attribution
2468
2476
  : '',
2469
2477
  },
2478
+ // eslint-disable-next-line no-mixed-spaces-and-tabs
2470
2479
  }
2471
- : {})), (typeof ((_j = props.options) === null || _j === void 0 ? void 0 : _j.source) === 'string'
2480
+ : {})), (typeof ((_q = props.options) === null || _q === void 0 ? void 0 : _q.source) === 'string'
2472
2481
  ? {
2473
2482
  source: props.options.source,
2483
+ // eslint-disable-next-line no-mixed-spaces-and-tabs
2474
2484
  }
2475
2485
  : {})), { id: layerId.current }), props.insertBeforeLayer
2476
2486
  ? props.insertBeforeLayer
@@ -2495,28 +2505,29 @@ function useLayer(props) {
2495
2505
  mapHook.map.on('styledata', function () {
2496
2506
  var _a;
2497
2507
  if (initializedRef.current && !((_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map.getLayer(layerId.current))) {
2498
- console.log('Recreate Layer');
2499
2508
  createLayer();
2500
2509
  }
2501
2510
  }, mapHook.componentId);
2502
- layerPaintConfRef.current = JSON.stringify((_k = props.options) === null || _k === void 0 ? void 0 : _k.paint);
2503
- layerLayoutConfRef.current = JSON.stringify((_l = props.options) === null || _l === void 0 ? void 0 : _l.layout);
2511
+ layerPaintConfRef.current = JSON.stringify((_r = props.options) === null || _r === void 0 ? void 0 : _r.paint);
2512
+ layerLayoutConfRef.current = JSON.stringify((_s = props.options) === null || _s === void 0 ? void 0 : _s.layout);
2504
2513
  layerTypeRef.current = props.options.type;
2505
- }, [props, mapHook.map]);
2514
+ }, [props, mapHook]);
2506
2515
  React.useEffect(function () {
2507
- var _a, _b, _c, _d;
2516
+ var _a, _b, _c, _d, _e;
2508
2517
  if (!mapHook.map)
2509
2518
  return;
2510
- if (((_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.cancelled) === false &&
2519
+ if (!props.geojson && !props.options.source && ((_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.type) !== 'background')
2520
+ return;
2521
+ if (((_b = mapHook.map) === null || _b === void 0 ? void 0 : _b.cancelled) === false &&
2511
2522
  initializedRef.current &&
2512
- ((_d = (_c = (_b = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _b === void 0 ? void 0 : _b.map) === null || _c === void 0 ? void 0 : _c.getLayer) === null || _d === void 0 ? void 0 : _d.call(_c, layerId.current)) &&
2523
+ ((_e = (_d = (_c = mapHook === null || mapHook === void 0 ? void 0 : mapHook.map) === null || _c === void 0 ? void 0 : _c.map) === null || _d === void 0 ? void 0 : _d.getLayer) === null || _e === void 0 ? void 0 : _e.call(_d, layerId.current)) &&
2513
2524
  (legalLayerTypes.indexOf(props.options.type) === -1 ||
2514
2525
  (legalLayerTypes.indexOf(props.options.type) !== -1 &&
2515
2526
  props.options.type === layerTypeRef.current))) {
2516
2527
  return;
2517
2528
  }
2518
2529
  createLayer();
2519
- }, [mapHook.map, mapHook.mapIsReady, props.options, createLayer]);
2530
+ }, [mapHook.map, mapHook.mapIsReady, props, createLayer]);
2520
2531
  React.useEffect(function () {
2521
2532
  var _a, _b, _c, _d, _e, _f;
2522
2533
  if (((_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.cancelled) === true ||
@@ -2705,27 +2716,41 @@ function useSource(props) {
2705
2716
  var mapHook = useMap({
2706
2717
  mapId: props.mapId,
2707
2718
  });
2708
- var initializedRef = React.useRef(false);
2709
2719
  var _b = React.useState(), source = _b[0], setSource = _b[1];
2710
2720
  var sourceId = React.useRef(props.sourceId || (props.idPrefix ? props.idPrefix : 'Source-') + mapHook.componentId);
2721
+ var removeSource = React.useCallback(function () {
2722
+ var _a, _b;
2723
+ if (mapHook.map && ((_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.style) === null || _b === void 0 ? void 0 : _b._layers)) {
2724
+ for (var _i = 0, _c = Object.entries(mapHook.map.map.style._layers); _i < _c.length; _i++) {
2725
+ var _d = _c[_i], layerId = _d[0], layer = _d[1];
2726
+ if (layer.source === sourceId.current) {
2727
+ mapHook.map.removeLayer(layerId);
2728
+ }
2729
+ }
2730
+ if (mapHook.map.getSource(sourceId.current)) {
2731
+ mapHook.map.removeSource(sourceId.current);
2732
+ }
2733
+ }
2734
+ }, [mapHook.map]);
2711
2735
  var createSource = React.useCallback(function () {
2712
2736
  var _a;
2713
2737
  if (!mapHook.map)
2714
2738
  return;
2715
- initializedRef.current = true;
2739
+ if (props.source.type === 'geojson' && !props.source.data)
2740
+ return;
2716
2741
  if (mapHook.map.map.getSource(sourceId.current)) {
2717
- mapHook.cleanup();
2742
+ removeSource();
2718
2743
  }
2719
- (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.addSource(sourceId.current, __assign({}, props.source), mapHook.componentId);
2744
+ (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.addSource(sourceId.current, __assign({}, props.source));
2720
2745
  setSource(mapHook.map.map.getSource(sourceId.current));
2721
- }, [props, mapHook.map]);
2746
+ }, [props, mapHook, removeSource]);
2722
2747
  React.useEffect(function () {
2723
2748
  var _a, _b, _c, _d;
2724
- if (!initializedRef.current || !((_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.getSource(props.sourceId)))
2749
+ if (!((_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.getSource(sourceId.current)))
2725
2750
  return;
2726
2751
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2727
2752
  //@ts-ignore setData only exists on GeoJsonSource
2728
- (_d = (_c = mapHook.map.map.getSource(props.sourceId)) === null || _c === void 0 ? void 0 : _c.setData) === null || _d === void 0 ? void 0 : _d.call(_c, props.source.data);
2753
+ (_d = (_c = mapHook.map.map.getSource(sourceId.current)) === null || _c === void 0 ? void 0 : _c.setData) === null || _d === void 0 ? void 0 : _d.call(_c, props.source.data);
2729
2754
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2730
2755
  //@ts-ignore data only exists on GeoJsonSource
2731
2756
  }, [(_a = props.source) === null || _a === void 0 ? void 0 : _a.data]);
@@ -2739,19 +2764,9 @@ function useSource(props) {
2739
2764
  //cleanup
2740
2765
  React.useEffect(function () {
2741
2766
  return function () {
2742
- var _a, _b, _c;
2743
- initializedRef.current = false;
2744
- if (mapHook.map && ((_c = (_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.style) === null || _c === void 0 ? void 0 : _c._layers)) {
2745
- for (var _i = 0, _d = Object.entries(mapHook.map.map.style._layers); _i < _d.length; _i++) {
2746
- var _e = _d[_i], layerId = _e[0], layer = _e[1];
2747
- if (layer.source === sourceId.current) {
2748
- mapHook.map.map.removeLayer(layerId);
2749
- }
2750
- }
2751
- mapHook.map.map.removeSource(sourceId.current);
2752
- }
2767
+ removeSource();
2753
2768
  };
2754
- }, [mapHook.map]);
2769
+ }, [removeSource]);
2755
2770
  return {
2756
2771
  map: mapHook.map,
2757
2772
  source: source,
@@ -2766,7 +2781,7 @@ function useSource(props) {
2766
2781
  * @component
2767
2782
  */
2768
2783
  var MlGeoJsonLayer = function (props) {
2769
- var _a, _b, _c;
2784
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2770
2785
  var layerType = props.type || getDefaulLayerTypeByGeometry(props.geojson);
2771
2786
  var layerId = React.useRef(props.layerId || 'MlGeoJsonLayer-' + uuid.v4());
2772
2787
  var labelLayerId = "label-".concat(layerId.current);
@@ -2780,31 +2795,27 @@ var MlGeoJsonLayer = function (props) {
2780
2795
  }, [props.layerId]);
2781
2796
  useSource({
2782
2797
  mapId: props.mapId,
2783
- sourceId: layerId.current,
2784
- source: {
2785
- type: 'geojson',
2786
- data: props.geojson,
2787
- },
2798
+ sourceId: 'source-' + layerId.current,
2799
+ source: __assign({ type: 'geojson', data: props.geojson }, (typeof ((_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.source) !== 'undefined' &&
2800
+ typeof ((_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.source) !== 'string'
2801
+ ? props.options.source
2802
+ : {})),
2788
2803
  });
2789
2804
  useLayer({
2790
2805
  mapId: props.mapId,
2791
2806
  layerId: layerId.current,
2792
- options: __assign(__assign({ source: layerId.current }, props.options), { paint: __assign(__assign({}, (props.paint || getDefaultPaintPropsByType(layerType, props.defaultPaintOverrides))), (_a = props === null || props === void 0 ? void 0 : props.options) === null || _a === void 0 ? void 0 : _a.paint), layout: __assign(__assign({}, ((props === null || props === void 0 ? void 0 : props.layout) || {})), (_b = props === null || props === void 0 ? void 0 : props.options) === null || _b === void 0 ? void 0 : _b.layout), type: layerType }),
2807
+ options: __assign(__assign({}, props.options), { source: 'source-' + layerId.current, paint: __assign(__assign({}, (props.paint || getDefaultPaintPropsByType(layerType, props.defaultPaintOverrides))), (_c = props === null || props === void 0 ? void 0 : props.options) === null || _c === void 0 ? void 0 : _c.paint), layout: __assign(__assign({}, ((props === null || props === void 0 ? void 0 : props.layout) || {})), (_d = props === null || props === void 0 ? void 0 : props.options) === null || _d === void 0 ? void 0 : _d.layout), type: layerType }),
2793
2808
  insertBeforeLayer: props.insertBeforeLayer,
2794
2809
  onHover: props.onHover,
2795
2810
  onClick: props.onClick,
2796
2811
  onLeave: props.onLeave,
2797
2812
  });
2798
- if (props.labelProp) {
2799
- useLayer({
2800
- mapId: props.mapId,
2801
- options: __assign(__assign({ source: props.labelProp ? layerId.current : undefined, id: labelLayerId, type: 'symbol', maxzoom: 24, minzoom: 1 }, ((props === null || props === void 0 ? void 0 : props.labelOptions) ? props.labelOptions : {})), { layout: __assign({ 'text-font': ['Open Sans Regular'], 'text-field': "{".concat(props.labelProp, "}") }, (((_c = props === null || props === void 0 ? void 0 : props.labelOptions) === null || _c === void 0 ? void 0 : _c.layout) ? props.labelOptions.layout : {})), paint: {
2802
- 'text-halo-width': 1,
2803
- 'text-halo-color': '#121212',
2804
- 'text-color': '#fefefe',
2805
- } }),
2806
- });
2807
- }
2813
+ // Label useLayer hook can't be called conditionally.
2814
+ // Using it with geojson and options.source undefined will cause it to return without creating a layer.
2815
+ useLayer({
2816
+ mapId: props.mapId,
2817
+ options: __assign(__assign(__assign({ source: props.labelProp ? 'source-' + layerId.current : undefined, id: labelLayerId, type: 'symbol', maxzoom: 24, minzoom: 1 }, ((props === null || props === void 0 ? void 0 : props.labelOptions) ? props.labelOptions : {})), (((_e = props === null || props === void 0 ? void 0 : props.options) === null || _e === void 0 ? void 0 : _e.filter) ? { filter: props.options.filter } : {})), { layout: __assign(__assign({ 'text-font': ['Open Sans Regular'], 'text-field': "{".concat(props.labelProp, "}"), 'text-size': 12, 'text-anchor': 'top' }, (((_f = props === null || props === void 0 ? void 0 : props.labelOptions) === null || _f === void 0 ? void 0 : _f.layout) ? props.labelOptions.layout : {})), (((_g = props === null || props === void 0 ? void 0 : props.layout) === null || _g === void 0 ? void 0 : _g.visibility) ? { visibility: props.layout.visibility } : {})), paint: __assign({ 'text-halo-width': 1, 'text-halo-color': '#fefefe', 'text-color': '#121212' }, (((_h = props === null || props === void 0 ? void 0 : props.labelOptions) === null || _h === void 0 ? void 0 : _h.paint) ? props.labelOptions.paint : {})) }),
2818
+ });
2808
2819
  return React__default["default"].createElement(React__default["default"].Fragment, null);
2809
2820
  };
2810
2821
 
@@ -3016,10 +3027,10 @@ var MlMeasureTool = function (props) {
3016
3027
  value = result * 1000000;
3017
3028
  }
3018
3029
  if (getUnitLabel(props.unit) === 'mi') {
3019
- label = 'in';
3020
- value = result * 63360;
3030
+ label = 'Yard';
3031
+ value = result * 1760;
3021
3032
  if (props.measureType === 'polygon') {
3022
- value = result * 4014489599.4792;
3033
+ value = result * 3097600;
3023
3034
  }
3024
3035
  }
3025
3036
  setDisplayValue({ value: value, label: label });
@@ -6253,13 +6264,18 @@ var MlTemporalController = function (props) {
6253
6264
  };
6254
6265
  }, [mapHook.map, props.onClick, props.onHover, props.onLeave]);
6255
6266
  return (React__default["default"].createElement(React__default["default"].Fragment, null,
6256
- filteredData && props.ownLayer && (React__default["default"].createElement(MlGeoJsonLayer, { type: props.type, mapId: props.mapId, layerId: "timeController", insertBeforeLayer: props.insertBeforeLayer || 'timeControllerLabels', geojson: filteredData, paint: props.paint ||
6267
+ filteredData && props.ownLayer && (React__default["default"].createElement(MlGeoJsonLayer, { type: props.type, mapId: props.mapId,
6268
+ //layerId="timeController"
6269
+ //insertBeforeLayer={props.insertBeforeLayer || 'timeControllerLabels'}
6270
+ paint: props.paint ||
6257
6271
  paint, options: {
6258
6272
  source: {
6273
+ type: 'geojson',
6259
6274
  attribution: props.attribution,
6275
+ data: filteredData
6260
6276
  },
6261
6277
  } })),
6262
- props.label && (React__default["default"].createElement(MlTemporalControllerLabels, { data: filteredData, currentVal: currentVal, fadeIn: props.labelFadeIn, fadeOut: props.labelFadeOut, step: props.step, labelField: labelField, labelColor: labelColor, timeField: props.timeField, minVal: minVal, accumulate: props.accumulate, isPlaying: isPlaying })),
6278
+ filteredData && props.label && (React__default["default"].createElement(MlTemporalControllerLabels, { data: filteredData, currentVal: currentVal, fadeIn: props.labelFadeIn, fadeOut: props.labelFadeOut, step: props.step, labelField: labelField, labelColor: labelColor, timeField: props.timeField, minVal: minVal, accumulate: props.accumulate, isPlaying: isPlaying })),
6263
6279
  React__default["default"].createElement(TemporalControllerPlayer, { currentVal: currentVal, isPlaying: isPlaying, step: props.step, interval: props.interval, minVal: minVal, maxVal: maxVal, returnCurrent: setCurrentVal, returnPlaying: setIsPlaying, open: false, fadeIn: props.fadeIn, fadeOut: props.fadeOut, featuresColor: featuresColor, labels: props.label, labelColor: labelColor, labelFadeIn: props.labelFadeIn, labelFadeOut: props.labelFadeOut, accumulate: props.accumulate, display: props.displayCurrentValue })));
6264
6280
  };
6265
6281
  MlTemporalController.defaultProps = {
@@ -7182,143 +7198,427 @@ useAddProtocol.defaultProps = {
7182
7198
  mapId: undefined,
7183
7199
  };
7184
7200
 
7185
- var SimpleDataContext = /*#__PURE__*/React__default["default"].createContext({});
7186
- var SimpleDataContextProvider = SimpleDataContext.Provider;
7187
-
7188
- var SimpleDataProvider = function SimpleDataProvider(props) {
7189
- var _useState = React.useState(null),
7190
- _useState2 = _slicedToArray(_useState, 2),
7191
- data = _useState2[0],
7192
- setData = _useState2[1];
7193
- React.useEffect(function () {
7194
- if (!props.url) return;
7195
- var data_promise = null;
7196
- if (props.format === "json") {
7197
- data_promise = d3__namespace.json(props.url);
7198
- } else if (props.format === "csv") {
7199
- data_promise = d3__namespace.csv(props.url);
7200
- } else if (props.format === "xml") {
7201
- data_promise = d3__namespace.xml(props.url);
7202
- }
7203
- if (data_promise) {
7204
- data_promise.then(function (received_data) {
7205
- if (props.format === "xml") {
7206
- if (props.nodeType) {
7207
- var dataTmp = [];
7208
- received_data.querySelectorAll(props.nodeType).forEach(function (el) {
7209
- dataTmp.push(props.formatData(el));
7210
- });
7211
- setData(dataTmp);
7212
- }
7213
- } else {
7214
- if (props.data_property) {
7215
- received_data = received_data[props.data_property];
7216
- }
7217
- if (typeof props.formatData === "function") {
7218
- setData(received_data.map(props.formatData));
7219
- } else {
7220
- setData(received_data);
7221
- }
7222
- }
7223
- if (typeof props.onData === "function") {
7224
- props.onData();
7225
- }
7226
- });
7227
- }
7228
- }, [props.url, props]);
7229
- var value = {
7230
- data: data,
7231
- setData: setData
7232
- };
7233
- return /*#__PURE__*/React__default["default"].createElement(SimpleDataContextProvider, {
7234
- value: value
7235
- }, props.children);
7236
- };
7237
- SimpleDataProvider.propTypes = {
7238
- children: PropTypes__default["default"].node.isRequired
7239
- };
7201
+ function protocolPathParser(url) {
7202
+ var test = url.split('?');
7203
+ var urlParts = test[0].split('://');
7204
+ var protocolId = urlParts[0];
7205
+ var csvUrl = urlParts.length > 2 ? urlParts[1] + '://' + urlParts[2] : urlParts[1];
7206
+ var csvParts = csvUrl.split('/');
7207
+ var filename = csvParts.join('/');
7208
+ var optionsString = decodeURI(test[1]);
7209
+ var options = Object.fromEntries(new URLSearchParams(optionsString));
7210
+ return {
7211
+ protocolId: protocolId,
7212
+ filename: filename,
7213
+ options: options,
7214
+ };
7215
+ }
7240
7216
 
7241
- var ListStyled = material.styled(material.List)({
7242
- marginTop: '15px',
7243
- });
7244
- function LayerList(props) {
7245
- return React__default["default"].createElement(ListStyled, null, props === null || props === void 0 ? void 0 : props.children);
7217
+ function getProtocolData(path) {
7218
+ return __awaiter(this, void 0, void 0, function () {
7219
+ var response, rawData, error_1;
7220
+ return __generator(this, function (_a) {
7221
+ switch (_a.label) {
7222
+ case 0:
7223
+ _a.trys.push([0, 3, , 4]);
7224
+ return [4 /*yield*/, fetch(path)];
7225
+ case 1:
7226
+ response = _a.sent();
7227
+ return [4 /*yield*/, response.text()];
7228
+ case 2:
7229
+ rawData = _a.sent();
7230
+ return [2 /*return*/, rawData];
7231
+ case 3:
7232
+ error_1 = _a.sent();
7233
+ console.error('File could not be loaded: ', error_1);
7234
+ return [2 /*return*/, error_1];
7235
+ case 4: return [2 /*return*/];
7236
+ }
7237
+ });
7238
+ });
7246
7239
  }
7247
7240
 
7248
- var IconButtonStyled = material.styled(material.IconButton)({
7249
- padding: '4px',
7250
- marginTop: '-3px',
7251
- background: 'none',
7252
- '&:hover': {
7253
- background: 'none',
7254
- },
7255
- });
7256
- function LayerListItemFactory(props) {
7257
- var _a, _b;
7258
- var layerContext = useLayerContext();
7259
- var mapHook = useMap({ mapId: undefined });
7260
- //useCallback Hook
7261
- function fitLayer(layer) {
7262
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
7263
- var layerSource = layer.id && ((_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.getLayer(layer.id)) === null || _b === void 0 ? void 0 : _b.source)
7264
- ? (_c = mapHook.map) === null || _c === void 0 ? void 0 : _c.getLayer(layer.id).source
7265
- : undefined;
7266
- var _bbox = null;
7267
- switch (layer.type) {
7268
- case 'geojson':
7269
- if ((_d = layer.config) === null || _d === void 0 ? void 0 : _d.geojson) {
7270
- (_e = mapHook.map) === null || _e === void 0 ? void 0 : _e.fitBounds(turf.bbox((_f = layer.config) === null || _f === void 0 ? void 0 : _f.geojson), props.fitBoundsOptions);
7271
- }
7272
- else {
7273
- if (!layerSource) {
7274
- return;
7275
- }
7276
- var _geojson = {
7277
- type: 'FeatureCollection',
7278
- features: (_g = mapHook.map) === null || _g === void 0 ? void 0 : _g.querySourceFeatures(layerSource),
7279
- };
7280
- if (_geojson.features.length === 0) {
7281
- (_h = mapHook.map) === null || _h === void 0 ? void 0 : _h.zoomTo(1);
7282
- _geojson.features = (_j = mapHook.map) === null || _j === void 0 ? void 0 : _j.querySourceFeatures(layerSource);
7283
- }
7284
- _bbox = turf.bbox(_geojson);
7285
- }
7286
- break;
7287
- case 'vt':
7288
- console.log('vt');
7289
- break;
7290
- case 'wms':
7291
- _bbox = (_o = (_m = (_l = (_k = layer === null || layer === void 0 ? void 0 : layer.config) === null || _k === void 0 ? void 0 : _k.config) === null || _l === void 0 ? void 0 : _l.layers) === null || _m === void 0 ? void 0 : _m[0]) === null || _o === void 0 ? void 0 : _o.EX_GeographicBoundingBox;
7292
- break;
7293
- default:
7294
- return;
7241
+ function convertCsv(filename, options) {
7242
+ return __awaiter(this, void 0, void 0, function () {
7243
+ var geojson;
7244
+ return __generator(this, function (_a) {
7245
+ switch (_a.label) {
7246
+ case 0: return [4 /*yield*/, new Promise(function (resolve, reject) {
7247
+ var useOptions = options || {};
7248
+ var extension = filename.substring(filename.length - 3);
7249
+ if (extension === 'tsv') {
7250
+ options.delimiter = '\t';
7251
+ }
7252
+ getProtocolData(filename).then(function (rawData) {
7253
+ // Use the csv2geojson library to convert the CSV to GeoJSON
7254
+ csv2geojson__namespace.csv2geojson(rawData, useOptions, function (err, data) {
7255
+ if (err) {
7256
+ reject(err);
7257
+ }
7258
+ else {
7259
+ resolve(data);
7260
+ }
7261
+ });
7262
+ });
7263
+ })];
7264
+ case 1:
7265
+ geojson = _a.sent();
7266
+ return [2 /*return*/, geojson];
7267
+ }
7268
+ });
7269
+ });
7270
+ }
7271
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
7272
+ var CSVProtocolHandler = function (params, callback) {
7273
+ var parsedParams = protocolPathParser(params.url);
7274
+ convertCsv(parsedParams.filename, parsedParams.options).then(function (data) {
7275
+ if (data !== undefined) {
7276
+ callback(null, data, null, null);
7295
7277
  }
7296
- if (_bbox) {
7297
- (_p = mapHook.map) === null || _p === void 0 ? void 0 : _p.fitBounds(_bbox, props.fitBoundsOptions);
7278
+ else {
7279
+ callback(new Error('CSV not found'));
7298
7280
  }
7299
- }
7300
- var orderLayers = React.useMemo(function () {
7301
- var layerIds = __spreadArray(__spreadArray([
7302
- 'order-background'
7303
- ], __spreadArray([], layerContext.layers, true).map(function (_el, idx) { return 'content_order_' + idx; }), true), [
7304
- 'order-labels',
7305
- ], false);
7306
- return layerIds.reverse();
7307
- }, [layerContext.layers]);
7308
- var layers = React.useMemo(function () {
7309
- if (props.layers)
7310
- return props.layers;
7311
- if (layerContext === null || layerContext === void 0 ? void 0 : layerContext.layers)
7312
- return layerContext.layers;
7313
- return [];
7314
- }, [props.layers, layerContext.layers]);
7315
- var setLayers = React.useMemo(function () {
7316
- if (props.setLayers)
7317
- return props.setLayers;
7318
- return layerContext.setLayers;
7319
- }, [props.setLayers, layerContext.setLayers]);
7320
- var pointerSensor = core.useSensor(core.PointerSensor, {
7321
- activationConstraint: {
7281
+ });
7282
+ return { cancel: function () { } };
7283
+ };
7284
+
7285
+ function convertOSM(params) {
7286
+ return __awaiter(this, void 0, void 0, function () {
7287
+ var options, geojson;
7288
+ return __generator(this, function (_a) {
7289
+ switch (_a.label) {
7290
+ case 0:
7291
+ options = params.options || {};
7292
+ return [4 /*yield*/, new Promise(function (resolve, reject) {
7293
+ getProtocolData(params.filename).then(function (rawData) {
7294
+ var newData = osm2geojson__default["default"](rawData, options);
7295
+ if (!newData) {
7296
+ reject('Conversion failed');
7297
+ }
7298
+ else {
7299
+ resolve(newData);
7300
+ }
7301
+ });
7302
+ })];
7303
+ case 1:
7304
+ geojson = _a.sent();
7305
+ return [2 /*return*/, geojson];
7306
+ }
7307
+ });
7308
+ });
7309
+ }
7310
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
7311
+ var OSMProtocolHandler = function (params, callback) {
7312
+ var parsedParams = protocolPathParser(params.url);
7313
+ convertOSM(parsedParams).then(function (data) {
7314
+ if (data !== undefined) {
7315
+ callback(null, data, null, null);
7316
+ }
7317
+ else {
7318
+ callback(new Error('OSM File not found'));
7319
+ }
7320
+ });
7321
+ return { cancel: function () { } };
7322
+ };
7323
+
7324
+ function reduceFeatures(geojson) {
7325
+ var newFeatures = [];
7326
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
7327
+ geojson.features.forEach(function (e) {
7328
+ if (!e.features) {
7329
+ newFeatures.push({
7330
+ type: e.type,
7331
+ geometry: e.geometry,
7332
+ properties: e.properties,
7333
+ });
7334
+ }
7335
+ else {
7336
+ e.features.forEach(function (el) {
7337
+ newFeatures.push({ type: el.type, geometry: el.geometry, properties: el.properties });
7338
+ });
7339
+ }
7340
+ });
7341
+ return newFeatures;
7342
+ }
7343
+ function convertTopojson(params) {
7344
+ return __awaiter(this, void 0, void 0, function () {
7345
+ var geojson;
7346
+ return __generator(this, function (_a) {
7347
+ switch (_a.label) {
7348
+ case 0: return [4 /*yield*/, new Promise(function (resolve) {
7349
+ var topoJsonData = {
7350
+ type: 'Topology',
7351
+ objects: { key: '' },
7352
+ arcs: []
7353
+ };
7354
+ getProtocolData(params.filename).then(function (rawData) {
7355
+ try {
7356
+ topoJsonData = JSON.parse(rawData);
7357
+ }
7358
+ catch (e) {
7359
+ throw 'Invalid TopoJson';
7360
+ }
7361
+ // Convert the data
7362
+ var result = {
7363
+ type: 'FeatureCollection',
7364
+ features: [],
7365
+ };
7366
+ if (topoJsonData.type === 'Topology' && topoJsonData.objects !== undefined) {
7367
+ // add the "fromObject" property in each topojson feature
7368
+ Object.keys(topoJsonData.objects).map(function (key) {
7369
+ var _a, _b, _c, _d, _e, _f, _g;
7370
+ if (((_a = topoJsonData.objects) === null || _a === void 0 ? void 0 : _a[key].type) === 'GeometryCollection') {
7371
+ (_c = (_b = topoJsonData.objects) === null || _b === void 0 ? void 0 : _b[key].geometries) === null || _c === void 0 ? void 0 : _c.forEach(function (e) { return (e.properties = __assign({ fromObject: key }, e.properties)); });
7372
+ }
7373
+ else if (((_d = topoJsonData === null || topoJsonData === void 0 ? void 0 : topoJsonData.objects) === null || _d === void 0 ? void 0 : _d[key]) &&
7374
+ ((_f = (_e = topoJsonData === null || topoJsonData === void 0 ? void 0 : topoJsonData.objects) === null || _e === void 0 ? void 0 : _e[key]) === null || _f === void 0 ? void 0 : _f.type) !== 'GeometryCollection') {
7375
+ topoJsonData.objects[key].properties = __assign({ fromObject: key }, (_g = topoJsonData.objects) === null || _g === void 0 ? void 0 : _g[key].properties);
7376
+ }
7377
+ });
7378
+ //convert the data into a geoJson object
7379
+ result = {
7380
+ type: 'FeatureCollection',
7381
+ features: Object.keys(topoJsonData.objects).map(function (key) {
7382
+ return topojsonClient.feature(topoJsonData, key);
7383
+ }),
7384
+ };
7385
+ result.features = reduceFeatures(result);
7386
+ }
7387
+ resolve(result);
7388
+ });
7389
+ })];
7390
+ case 1:
7391
+ geojson = _a.sent();
7392
+ return [2 /*return*/, geojson];
7393
+ }
7394
+ });
7395
+ });
7396
+ }
7397
+ var TopojsonProtocolHandler = function (params, callback) {
7398
+ var parsedParams = protocolPathParser(params.url);
7399
+ convertTopojson(parsedParams).then(function (data) {
7400
+ if (data !== undefined) {
7401
+ callback(null, data, null, null);
7402
+ }
7403
+ else {
7404
+ callback(new Error('Topojson not found'));
7405
+ }
7406
+ });
7407
+ return { cancel: function () { } };
7408
+ };
7409
+
7410
+ function convertXML(params) {
7411
+ return __awaiter(this, void 0, void 0, function () {
7412
+ var geojson;
7413
+ return __generator(this, function (_a) {
7414
+ switch (_a.label) {
7415
+ case 0: return [4 /*yield*/, new Promise(function (resolve, reject) {
7416
+ getProtocolData(params.filename).then(function (rawData) {
7417
+ var newData = function () {
7418
+ // use an extern converter for tcx files
7419
+ if (params.protocolId === 'tcx') {
7420
+ return externParser__namespace[params.protocolId](new DOMParser().parseFromString(rawData, 'text/xml'));
7421
+ // use the projects gpxConverter function for gpx and kml files
7422
+ }
7423
+ else {
7424
+ return toGeoJSON[params.protocolId](new DOMParser().parseFromString(rawData, 'text/xml'));
7425
+ }
7426
+ };
7427
+ if (!newData()) {
7428
+ reject('Conversion failed');
7429
+ }
7430
+ else {
7431
+ resolve(newData());
7432
+ }
7433
+ });
7434
+ })];
7435
+ case 1:
7436
+ geojson = _a.sent();
7437
+ return [2 /*return*/, geojson];
7438
+ }
7439
+ });
7440
+ });
7441
+ }
7442
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
7443
+ var XMLProtocolHandler = function (params, callback) {
7444
+ var parsedParams = protocolPathParser(params.url);
7445
+ convertXML(parsedParams).then(function (data) {
7446
+ if (data !== undefined) {
7447
+ callback(null, data, null, null);
7448
+ }
7449
+ else {
7450
+ callback(new Error('XML not found'));
7451
+ }
7452
+ });
7453
+ return { cancel: function () { } };
7454
+ };
7455
+
7456
+ /**
7457
+ *
7458
+ */
7459
+ var useAddImage = function (props) {
7460
+ var mapHook = useMap({
7461
+ mapId: undefined,
7462
+ });
7463
+ var initializedRef = React.useRef(false);
7464
+ React.useEffect(function () {
7465
+ var _a;
7466
+ if (!mapHook.map || initializedRef.current)
7467
+ return;
7468
+ (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.loadImage(props.imagePath, function (error, image) {
7469
+ var _a;
7470
+ if (error)
7471
+ throw error;
7472
+ (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.addImage(props.imageId, image);
7473
+ return function () {
7474
+ var _a;
7475
+ (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.removeImage(props.imageId);
7476
+ };
7477
+ });
7478
+ }, [mapHook.map, props]);
7479
+ return;
7480
+ };
7481
+ useAddImage.defaultProps = {
7482
+ mapId: undefined,
7483
+ };
7484
+
7485
+ var SimpleDataContext = /*#__PURE__*/React__default["default"].createContext({});
7486
+ var SimpleDataContextProvider = SimpleDataContext.Provider;
7487
+
7488
+ var SimpleDataProvider = function SimpleDataProvider(props) {
7489
+ var _useState = React.useState(null),
7490
+ _useState2 = _slicedToArray(_useState, 2),
7491
+ data = _useState2[0],
7492
+ setData = _useState2[1];
7493
+ React.useEffect(function () {
7494
+ if (!props.url) return;
7495
+ var data_promise = null;
7496
+ if (props.format === "json") {
7497
+ data_promise = d3__namespace.json(props.url);
7498
+ } else if (props.format === "csv") {
7499
+ data_promise = d3__namespace.csv(props.url);
7500
+ } else if (props.format === "xml") {
7501
+ data_promise = d3__namespace.xml(props.url);
7502
+ }
7503
+ if (data_promise) {
7504
+ data_promise.then(function (received_data) {
7505
+ if (props.format === "xml") {
7506
+ if (props.nodeType) {
7507
+ var dataTmp = [];
7508
+ received_data.querySelectorAll(props.nodeType).forEach(function (el) {
7509
+ dataTmp.push(props.formatData(el));
7510
+ });
7511
+ setData(dataTmp);
7512
+ }
7513
+ } else {
7514
+ if (props.data_property) {
7515
+ received_data = received_data[props.data_property];
7516
+ }
7517
+ if (typeof props.formatData === "function") {
7518
+ setData(received_data.map(props.formatData));
7519
+ } else {
7520
+ setData(received_data);
7521
+ }
7522
+ }
7523
+ if (typeof props.onData === "function") {
7524
+ props.onData();
7525
+ }
7526
+ });
7527
+ }
7528
+ }, [props.url, props]);
7529
+ var value = {
7530
+ data: data,
7531
+ setData: setData
7532
+ };
7533
+ return /*#__PURE__*/React__default["default"].createElement(SimpleDataContextProvider, {
7534
+ value: value
7535
+ }, props.children);
7536
+ };
7537
+ SimpleDataProvider.propTypes = {
7538
+ children: PropTypes__default["default"].node.isRequired
7539
+ };
7540
+
7541
+ var ListStyled = material.styled(material.List)({
7542
+ marginTop: '15px',
7543
+ });
7544
+ function LayerList(props) {
7545
+ return React__default["default"].createElement(ListStyled, null, props === null || props === void 0 ? void 0 : props.children);
7546
+ }
7547
+
7548
+ var IconButtonStyled = material.styled(material.IconButton)({
7549
+ padding: '4px',
7550
+ marginTop: '-3px',
7551
+ background: 'none',
7552
+ '&:hover': {
7553
+ background: 'none',
7554
+ },
7555
+ });
7556
+ function LayerListItemFactory(props) {
7557
+ var _a, _b;
7558
+ var layerContext = useLayerContext();
7559
+ var mapHook = useMap({ mapId: undefined });
7560
+ //useCallback Hook
7561
+ function fitLayer(layer) {
7562
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
7563
+ var layerSource = layer.id && ((_b = (_a = mapHook.map) === null || _a === void 0 ? void 0 : _a.getLayer(layer.id)) === null || _b === void 0 ? void 0 : _b.source)
7564
+ ? (_c = mapHook.map) === null || _c === void 0 ? void 0 : _c.getLayer(layer.id).source
7565
+ : undefined;
7566
+ var _bbox = null;
7567
+ switch (layer.type) {
7568
+ case 'geojson':
7569
+ if ((_d = layer.config) === null || _d === void 0 ? void 0 : _d.geojson) {
7570
+ (_e = mapHook.map) === null || _e === void 0 ? void 0 : _e.fitBounds(turf.bbox((_f = layer.config) === null || _f === void 0 ? void 0 : _f.geojson), props.fitBoundsOptions);
7571
+ }
7572
+ else {
7573
+ if (!layerSource) {
7574
+ return;
7575
+ }
7576
+ var _geojson = {
7577
+ type: 'FeatureCollection',
7578
+ features: (_g = mapHook.map) === null || _g === void 0 ? void 0 : _g.querySourceFeatures(layerSource),
7579
+ };
7580
+ if (_geojson.features.length === 0) {
7581
+ (_h = mapHook.map) === null || _h === void 0 ? void 0 : _h.zoomTo(1);
7582
+ _geojson.features = (_j = mapHook.map) === null || _j === void 0 ? void 0 : _j.querySourceFeatures(layerSource);
7583
+ }
7584
+ _bbox = turf.bbox(_geojson);
7585
+ }
7586
+ break;
7587
+ case 'vt':
7588
+ console.log('vt');
7589
+ break;
7590
+ case 'wms':
7591
+ _bbox = (_o = (_m = (_l = (_k = layer === null || layer === void 0 ? void 0 : layer.config) === null || _k === void 0 ? void 0 : _k.config) === null || _l === void 0 ? void 0 : _l.layers) === null || _m === void 0 ? void 0 : _m[0]) === null || _o === void 0 ? void 0 : _o.EX_GeographicBoundingBox;
7592
+ break;
7593
+ default:
7594
+ return;
7595
+ }
7596
+ if (_bbox) {
7597
+ (_p = mapHook.map) === null || _p === void 0 ? void 0 : _p.fitBounds(_bbox, props.fitBoundsOptions);
7598
+ }
7599
+ }
7600
+ var orderLayers = React.useMemo(function () {
7601
+ var layerIds = __spreadArray(__spreadArray([
7602
+ 'order-background'
7603
+ ], __spreadArray([], layerContext.layers, true).map(function (_el, idx) { return 'content_order_' + idx; }), true), [
7604
+ 'order-labels',
7605
+ ], false);
7606
+ return layerIds.reverse();
7607
+ }, [layerContext.layers]);
7608
+ var layers = React.useMemo(function () {
7609
+ if (props.layers)
7610
+ return props.layers;
7611
+ if (layerContext === null || layerContext === void 0 ? void 0 : layerContext.layers)
7612
+ return layerContext.layers;
7613
+ return [];
7614
+ }, [props.layers, layerContext.layers]);
7615
+ var setLayers = React.useMemo(function () {
7616
+ if (props.setLayers)
7617
+ return props.setLayers;
7618
+ return layerContext.setLayers;
7619
+ }, [props.setLayers, layerContext.setLayers]);
7620
+ var pointerSensor = core.useSensor(core.PointerSensor, {
7621
+ activationConstraint: {
7322
7622
  distance: 5,
7323
7623
  },
7324
7624
  });
@@ -7556,261 +7856,6 @@ function OsmOptionsFomular(props) {
7556
7856
  })))));
7557
7857
  }
7558
7858
 
7559
- function protocolPathParser(url) {
7560
- var test = url.split('?');
7561
- var urlParts = test[0].split('://');
7562
- var protocolId = urlParts[0];
7563
- var csvUrl = urlParts.length > 2 ? urlParts[1] + '://' + urlParts[2] : urlParts[1];
7564
- var csvParts = csvUrl.split('/');
7565
- var filename = csvParts.join('/');
7566
- var optionsString = decodeURI(test[1]);
7567
- var options = Object.fromEntries(new URLSearchParams(optionsString));
7568
- return {
7569
- protocolId: protocolId,
7570
- filename: filename,
7571
- options: options,
7572
- };
7573
- }
7574
-
7575
- function getProtocolData(path) {
7576
- return __awaiter(this, void 0, void 0, function () {
7577
- var response, rawData, error_1;
7578
- return __generator(this, function (_a) {
7579
- switch (_a.label) {
7580
- case 0:
7581
- _a.trys.push([0, 3, , 4]);
7582
- return [4 /*yield*/, fetch(path)];
7583
- case 1:
7584
- response = _a.sent();
7585
- return [4 /*yield*/, response.text()];
7586
- case 2:
7587
- rawData = _a.sent();
7588
- return [2 /*return*/, rawData];
7589
- case 3:
7590
- error_1 = _a.sent();
7591
- console.error('File could not be loaded: ', error_1);
7592
- return [2 /*return*/, error_1];
7593
- case 4: return [2 /*return*/];
7594
- }
7595
- });
7596
- });
7597
- }
7598
-
7599
- function convertCsv(filename, options) {
7600
- return __awaiter(this, void 0, void 0, function () {
7601
- var geojson;
7602
- return __generator(this, function (_a) {
7603
- switch (_a.label) {
7604
- case 0: return [4 /*yield*/, new Promise(function (resolve, reject) {
7605
- var useOptions = options || {};
7606
- var extension = filename.substring(filename.length - 3);
7607
- if (extension === 'tsv') {
7608
- options.delimiter = '\t';
7609
- }
7610
- getProtocolData(filename).then(function (rawData) {
7611
- // Use the csv2geojson library to convert the CSV to GeoJSON
7612
- csv2geojson__namespace.csv2geojson(rawData, useOptions, function (err, data) {
7613
- if (err) {
7614
- reject(err);
7615
- }
7616
- else {
7617
- resolve(data);
7618
- }
7619
- });
7620
- });
7621
- })];
7622
- case 1:
7623
- geojson = _a.sent();
7624
- return [2 /*return*/, geojson];
7625
- }
7626
- });
7627
- });
7628
- }
7629
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7630
- var CSVProtocolHandler = function (params, callback) {
7631
- var parsedParams = protocolPathParser(params.url);
7632
- convertCsv(parsedParams.filename, parsedParams.options).then(function (data) {
7633
- if (data !== undefined) {
7634
- callback(null, data, null, null);
7635
- }
7636
- else {
7637
- callback(new Error('CSV not found'));
7638
- }
7639
- });
7640
- return { cancel: function () { } };
7641
- };
7642
-
7643
- function reduceFeatures(geojson) {
7644
- var newFeatures = [];
7645
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7646
- geojson.features.forEach(function (e) {
7647
- if (!e.features) {
7648
- newFeatures.push({
7649
- type: e.type,
7650
- geometry: e.geometry,
7651
- properties: e.properties,
7652
- });
7653
- }
7654
- else {
7655
- e.features.forEach(function (el) {
7656
- newFeatures.push({ type: el.type, geometry: el.geometry, properties: el.properties });
7657
- });
7658
- }
7659
- });
7660
- return newFeatures;
7661
- }
7662
- function convertTopojson(params) {
7663
- return __awaiter(this, void 0, void 0, function () {
7664
- var geojson;
7665
- return __generator(this, function (_a) {
7666
- switch (_a.label) {
7667
- case 0: return [4 /*yield*/, new Promise(function (resolve) {
7668
- var topoJsonData = {
7669
- type: 'Topology',
7670
- objects: { key: '' },
7671
- arcs: []
7672
- };
7673
- getProtocolData(params.filename).then(function (rawData) {
7674
- try {
7675
- topoJsonData = JSON.parse(rawData);
7676
- }
7677
- catch (e) {
7678
- throw 'Invalid TopoJson';
7679
- }
7680
- // Convert the data
7681
- var result = {
7682
- type: 'FeatureCollection',
7683
- features: [],
7684
- };
7685
- if (topoJsonData.type === 'Topology' && topoJsonData.objects !== undefined) {
7686
- // add the "fromObject" property in each topojson feature
7687
- Object.keys(topoJsonData.objects).map(function (key) {
7688
- var _a, _b, _c, _d, _e, _f, _g;
7689
- if (((_a = topoJsonData.objects) === null || _a === void 0 ? void 0 : _a[key].type) === 'GeometryCollection') {
7690
- (_c = (_b = topoJsonData.objects) === null || _b === void 0 ? void 0 : _b[key].geometries) === null || _c === void 0 ? void 0 : _c.forEach(function (e) { return (e.properties = __assign({ fromObject: key }, e.properties)); });
7691
- }
7692
- else if (((_d = topoJsonData === null || topoJsonData === void 0 ? void 0 : topoJsonData.objects) === null || _d === void 0 ? void 0 : _d[key]) &&
7693
- ((_f = (_e = topoJsonData === null || topoJsonData === void 0 ? void 0 : topoJsonData.objects) === null || _e === void 0 ? void 0 : _e[key]) === null || _f === void 0 ? void 0 : _f.type) !== 'GeometryCollection') {
7694
- topoJsonData.objects[key].properties = __assign({ fromObject: key }, (_g = topoJsonData.objects) === null || _g === void 0 ? void 0 : _g[key].properties);
7695
- }
7696
- });
7697
- //convert the data into a geoJson object
7698
- result = {
7699
- type: 'FeatureCollection',
7700
- features: Object.keys(topoJsonData.objects).map(function (key) {
7701
- return topojsonClient.feature(topoJsonData, key);
7702
- }),
7703
- };
7704
- result.features = reduceFeatures(result);
7705
- }
7706
- resolve(result);
7707
- });
7708
- })];
7709
- case 1:
7710
- geojson = _a.sent();
7711
- return [2 /*return*/, geojson];
7712
- }
7713
- });
7714
- });
7715
- }
7716
- var TopojsonProtocolHandler = function (params, callback) {
7717
- var parsedParams = protocolPathParser(params.url);
7718
- convertTopojson(parsedParams).then(function (data) {
7719
- if (data !== undefined) {
7720
- callback(null, data, null, null);
7721
- }
7722
- else {
7723
- callback(new Error('Topojson not found'));
7724
- }
7725
- });
7726
- return { cancel: function () { } };
7727
- };
7728
-
7729
- function convertOSM(params) {
7730
- return __awaiter(this, void 0, void 0, function () {
7731
- var options, geojson;
7732
- return __generator(this, function (_a) {
7733
- switch (_a.label) {
7734
- case 0:
7735
- options = params.options || {};
7736
- return [4 /*yield*/, new Promise(function (resolve, reject) {
7737
- getProtocolData(params.filename).then(function (rawData) {
7738
- var newData = osm2geojson__default["default"](rawData, options);
7739
- if (!newData) {
7740
- reject('Conversion failed');
7741
- }
7742
- else {
7743
- resolve(newData);
7744
- }
7745
- });
7746
- })];
7747
- case 1:
7748
- geojson = _a.sent();
7749
- return [2 /*return*/, geojson];
7750
- }
7751
- });
7752
- });
7753
- }
7754
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7755
- var OSMProtocolHandler = function (params, callback) {
7756
- var parsedParams = protocolPathParser(params.url);
7757
- convertOSM(parsedParams).then(function (data) {
7758
- if (data !== undefined) {
7759
- callback(null, data, null, null);
7760
- }
7761
- else {
7762
- callback(new Error('OSM File not found'));
7763
- }
7764
- });
7765
- return { cancel: function () { } };
7766
- };
7767
-
7768
- function convertXML(params) {
7769
- return __awaiter(this, void 0, void 0, function () {
7770
- var geojson;
7771
- return __generator(this, function (_a) {
7772
- switch (_a.label) {
7773
- case 0: return [4 /*yield*/, new Promise(function (resolve, reject) {
7774
- getProtocolData(params.filename).then(function (rawData) {
7775
- var newData = function () {
7776
- // use an extern converter for tcx files
7777
- if (params.protocolId === 'tcx') {
7778
- return externParser__namespace[params.protocolId](new DOMParser().parseFromString(rawData, 'text/xml'));
7779
- // use the projects gpxConverter function for gpx and kml files
7780
- }
7781
- else {
7782
- return toGeoJSON[params.protocolId](new DOMParser().parseFromString(rawData, 'text/xml'));
7783
- }
7784
- };
7785
- if (!newData()) {
7786
- reject('Conversion failed');
7787
- }
7788
- else {
7789
- resolve(newData());
7790
- }
7791
- });
7792
- })];
7793
- case 1:
7794
- geojson = _a.sent();
7795
- return [2 /*return*/, geojson];
7796
- }
7797
- });
7798
- });
7799
- }
7800
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7801
- var XMLProtocolHandler = function (params, callback) {
7802
- var parsedParams = protocolPathParser(params.url);
7803
- convertXML(parsedParams).then(function (data) {
7804
- if (data !== undefined) {
7805
- callback(null, data, null, null);
7806
- }
7807
- else {
7808
- callback(new Error('XML not found'));
7809
- }
7810
- });
7811
- return { cancel: function () { } };
7812
- };
7813
-
7814
7859
  var handlers = {
7815
7860
  csv: CSVProtocolHandler,
7816
7861
  topojson: TopojsonProtocolHandler,
@@ -21111,6 +21156,7 @@ SpeedDial.defaultProps = {
21111
21156
 
21112
21157
  exports.AddLayerButton = AddLayerButton;
21113
21158
  exports.AddLayerPopup = AddLayerPopup;
21159
+ exports.CSVProtocolHandler = CSVProtocolHandler;
21114
21160
  exports.ColorPicker = PaintPropsColorPicker;
21115
21161
  exports.ConfirmDialog = ConfirmDialog;
21116
21162
  exports.GeoJsonContext = GeoJsonContext;
@@ -21164,6 +21210,7 @@ exports.MlWmsFeatureInfoPopup = MlWmsFeatureInfoPopup;
21164
21210
  exports.MlWmsLayer = MlWmsLayer;
21165
21211
  exports.MlWmsLoader = MlWmsLoader;
21166
21212
  exports.MonokaiStyle = MonokaiStyle;
21213
+ exports.OSMProtocolHandler = OSMProtocolHandler;
21167
21214
  exports.OceanicNextStyle = OceanicNextStyle;
21168
21215
  exports.PdfContext = PdfContext;
21169
21216
  exports.PdfForm = PdfForm;
@@ -21175,9 +21222,16 @@ exports.SimpleDataProvider = SimpleDataProvider;
21175
21222
  exports.SolarizedStyle = SolarizedStyle;
21176
21223
  exports.SpeedDial = SpeedDial;
21177
21224
  exports.TopToolbar = TopToolbar;
21225
+ exports.TopojsonProtocolHandler = TopojsonProtocolHandler;
21178
21226
  exports.UploadButton = UploadButton;
21179
21227
  exports.WmsLayerForm = WmsLayerForm;
21228
+ exports.XMLProtocolHandler = XMLProtocolHandler;
21229
+ exports.convertCsv = convertCsv;
21230
+ exports.convertOSM = convertOSM;
21231
+ exports.convertTopojson = convertTopojson;
21232
+ exports.convertXML = convertXML;
21180
21233
  exports.getTheme = getTheme;
21234
+ exports.useAddImage = useAddImage;
21181
21235
  exports.useAddProtocol = useAddProtocol;
21182
21236
  exports.useCameraFollowPath = useCameraFollowPath;
21183
21237
  exports.useExportMap = useExportMap;