@mapcomponents/react-maplibre 0.1.12 → 0.1.16

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 (133) hide show
  1. package/.github/workflows/storybook.yml +4 -2
  2. package/CHANGELOG.md +33 -0
  3. package/README.md +22 -6
  4. package/coverage/clover.xml +893 -760
  5. package/coverage/coverage-final.json +22 -17
  6. package/coverage/lcov-report/index.html +183 -123
  7. package/coverage/lcov-report/{components → src/components}/MapLibreMap/MapLibreMap.js.html +10 -10
  8. package/coverage/lcov-report/{components → src/components}/MapLibreMap/index.html +10 -10
  9. package/coverage/lcov-report/{components → src/components}/MlCreatePdfButton/MlCreatePdfButton.js.html +10 -10
  10. package/coverage/lcov-report/{components → src/components}/MlCreatePdfButton/index.html +10 -10
  11. package/coverage/lcov-report/{components → src/components}/MlFeatureEditor/MlFeatureEditor.js.html +10 -10
  12. package/coverage/lcov-report/{components → src/components}/MlFeatureEditor/index.html +10 -10
  13. package/coverage/lcov-report/{components → src/components}/MlFillExtrusionLayer/MlFillExtrusionLayer.js.html +10 -10
  14. package/coverage/lcov-report/{components → src/components}/MlFillExtrusionLayer/index.html +10 -10
  15. package/coverage/lcov-report/{components → src/components}/MlFollowGps/MlFollowGps.js.html +148 -136
  16. package/coverage/lcov-report/{components → src/components}/MlFollowGps/index.html +24 -24
  17. package/coverage/lcov-report/{components → src/components}/MlGPXViewer/MlGPXViewer.js.html +66 -60
  18. package/coverage/lcov-report/{components → src/components}/MlGPXViewer/gpxConverter.js.html +49 -70
  19. package/coverage/lcov-report/{components → src/components}/MlGPXViewer/index.html +25 -25
  20. package/coverage/lcov-report/{components → src/components}/MlGeoJsonLayer/MlGeoJsonLayer.js.html +155 -47
  21. package/coverage/lcov-report/{components → src/components}/MlGeoJsonLayer/index.html +28 -28
  22. package/coverage/lcov-report/{components/MlLayer/MlLayer.js.html → src/components/MlImageMarkerLayer/MlImageMarkerLayer.js.html} +88 -121
  23. package/coverage/lcov-report/{components → src/components}/MlImageMarkerLayer/index.html +28 -28
  24. package/coverage/lcov-report/{components/MlImageMarkerLayer/MlImageMarkerLayer.js.html → src/components/MlLayer/MlLayer.js.html} +116 -125
  25. package/coverage/lcov-report/src/components/MlLayer/index.html +117 -0
  26. package/coverage/lcov-report/{components → src/components}/MlLayerMagnify/MlLayerMagnify.js.html +41 -41
  27. package/coverage/lcov-report/{components → src/components}/MlLayerMagnify/index.html +24 -24
  28. package/coverage/lcov-report/{components → src/components}/MlLayerSwipe/MlLayerSwipe.js.html +38 -41
  29. package/coverage/lcov-report/{components → src/components}/MlLayerSwipe/index.html +24 -24
  30. package/coverage/lcov-report/src/components/MlLayerSwitcher/MlLayerSwitcher.js.html +755 -0
  31. package/coverage/lcov-report/src/components/MlLayerSwitcher/components/LayerBox.js.html +380 -0
  32. package/coverage/lcov-report/src/components/MlLayerSwitcher/components/index.html +117 -0
  33. package/coverage/lcov-report/src/components/MlLayerSwitcher/index.html +117 -0
  34. package/coverage/lcov-report/{components → src/components}/MlMarker/MlMarker.js.html +11 -11
  35. package/coverage/lcov-report/{components → src/components}/MlMarker/index.html +10 -10
  36. package/coverage/lcov-report/{components → src/components}/MlNavigationCompass/MlNavigationCompass.js.html +10 -10
  37. package/coverage/lcov-report/{components → src/components}/MlNavigationCompass/index.html +10 -10
  38. package/coverage/lcov-report/{components → src/components}/MlNavigationTools/MlNavigationTools.js.html +50 -41
  39. package/coverage/lcov-report/{components → src/components}/MlNavigationTools/index.html +18 -18
  40. package/coverage/lcov-report/{components → src/components}/MlOsmLayer/MlOsmLayer.js.html +10 -10
  41. package/coverage/lcov-report/{components → src/components}/MlOsmLayer/index.html +10 -10
  42. package/coverage/lcov-report/{components → src/components}/MlScaleReference/MlScaleReference.js.html +10 -10
  43. package/coverage/lcov-report/{components → src/components}/MlScaleReference/index.html +10 -10
  44. package/coverage/lcov-report/{components → src/components}/MlShareMapState/MlShareMapState.js.html +217 -25
  45. package/coverage/lcov-report/{components → src/components}/MlShareMapState/index.html +18 -18
  46. package/coverage/lcov-report/{components → src/components}/MlSpatialElevationProfile/MlSpatialElevationProfile.js.html +10 -10
  47. package/coverage/lcov-report/{components → src/components}/MlSpatialElevationProfile/index.html +10 -10
  48. package/coverage/lcov-report/{components → src/components}/MlThreeJsLayer/MlThreeJsLayer.js.html +30 -54
  49. package/coverage/lcov-report/{components → src/components}/MlThreeJsLayer/index.html +24 -24
  50. package/coverage/lcov-report/{components → src/components}/MlUseMapDebugger/MlUseMapDebugger.js.html +10 -10
  51. package/coverage/lcov-report/{components → src/components}/MlUseMapDebugger/index.html +10 -10
  52. package/coverage/lcov-report/{components → src/components}/MlVectorTileLayer/MlVectorTileLayer.js.html +10 -10
  53. package/coverage/lcov-report/{components → src/components}/MlVectorTileLayer/index.html +10 -10
  54. package/coverage/lcov-report/{components → src/components}/MlWmsFeatureInfoPopup/MlWmsFeatureInfoPopup.js.html +10 -10
  55. package/coverage/lcov-report/{components → src/components}/MlWmsFeatureInfoPopup/index.html +10 -10
  56. package/coverage/lcov-report/{components → src/components}/MlWmsLayer/MlWmsLayer.js.html +13 -13
  57. package/coverage/lcov-report/{components → src/components}/MlWmsLayer/index.html +14 -14
  58. package/coverage/lcov-report/{components → src/components}/MlWmsLoader/MlWmsLoader.js.html +31 -19
  59. package/coverage/lcov-report/{components → src/components}/MlWmsLoader/index.html +16 -16
  60. package/coverage/lcov-report/src/hooks/index.html +147 -0
  61. package/coverage/lcov-report/src/hooks/useMap.js.html +296 -0
  62. package/coverage/lcov-report/{hooks → src/hooks}/useMapState.js.html +91 -91
  63. package/coverage/lcov-report/{hooks → src/hooks}/useWms.js.html +18 -18
  64. package/coverage/lcov-report/src/i18n.js.html +167 -0
  65. package/coverage/lcov-report/src/index.html +117 -0
  66. package/coverage/lcov-report/src/translations/english.js.html +95 -0
  67. package/coverage/lcov-report/src/translations/german.js.html +95 -0
  68. package/coverage/lcov-report/src/translations/index.html +132 -0
  69. package/coverage/lcov.info +1610 -1314
  70. package/dist/b556faa3bc6829d2.png +0 -0
  71. package/dist/index.esm.js +934 -668
  72. package/dist/index.esm.js.map +1 -1
  73. package/package.json +3 -1
  74. package/public/assets/dop.png +0 -0
  75. package/public/assets/historic.png +0 -0
  76. package/public/assets/osm.png +0 -0
  77. package/public/thumbnails/MlFollowGps.png +0 -0
  78. package/public/thumbnails/MlThreeJsLayer.png +0 -0
  79. package/src/components/MapLibreMap/lib/MapLibreGlWrapper.js +53 -67
  80. package/src/components/MlComponentTemplate/MlComponentTemplate.js +6 -31
  81. package/src/components/MlFeatureEditor/MlFeatureEditor.meta.json +2 -2
  82. package/src/components/MlFollowGps/MlFollowGps.js +92 -88
  83. package/src/components/MlFollowGps/MlFollowGps.meta.json +2 -2
  84. package/src/components/MlFollowGps/MlFollowGps.test.js +3 -5
  85. package/src/components/MlFollowGps/assets/marker.png +0 -0
  86. package/src/components/MlGPXViewer/MlGPXViewer.js +45 -43
  87. package/src/components/MlGPXViewer/gpxConverter.js +22 -29
  88. package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.js +45 -9
  89. package/src/components/MlImageMarkerLayer/MlImageMarkerLayer.js +21 -57
  90. package/src/components/MlImageMarkerLayer/MlImageMarkerLayer.test.js +6 -7
  91. package/src/components/MlLayer/MlLayer.js +28 -6
  92. package/src/components/MlLayer/MlLayer.test.js +12 -10
  93. package/src/components/MlLayerMagnify/MlLayerMagnify.js +3 -3
  94. package/src/components/MlLayerSwipe/MlLayerSwipe.js +4 -5
  95. package/src/components/MlLayerSwitcher/MlLayerSwitcher.css +17 -0
  96. package/src/components/MlLayerSwitcher/MlLayerSwitcher.doc.de.md +3 -0
  97. package/src/components/MlLayerSwitcher/MlLayerSwitcher.js +223 -0
  98. package/src/components/MlLayerSwitcher/MlLayerSwitcher.meta_.json +15 -0
  99. package/src/components/MlLayerSwitcher/MlLayerSwitcher.stories.js +106 -0
  100. package/src/components/MlLayerSwitcher/assets/sample_1.json +26 -0
  101. package/src/components/MlLayerSwitcher/assets/sample_2.json +22 -0
  102. package/src/components/MlLayerSwitcher/components/LayerBox.js +98 -0
  103. package/src/components/MlMarker/MlMarker.js +1 -1
  104. package/src/components/MlNavigationTools/MlNavigationTools.js +29 -26
  105. package/src/components/MlScaleReference/MlScaleReference.meta.json +1 -1
  106. package/src/components/MlScaleReference/MlScaleReference.stories.js +25 -21
  107. package/src/components/MlShareMapState/MlShareMapState.js +73 -9
  108. package/src/components/MlShareMapState/MlShareMapState.stories.js +24 -1
  109. package/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.stories.js +12 -6
  110. package/src/components/MlThreeJsLayer/MlThreeJsLayer.js +8 -15
  111. package/src/components/MlWmsLayer/MlWmsLayer.js +1 -1
  112. package/src/components/MlWmsLoader/MlWmsLoader.js +8 -4
  113. package/src/components/MlWmsLoader/MlWmsLoader.meta.json +1 -1
  114. package/src/components/MlWmsLoader/MlWmsLoader.stories.js +5 -4
  115. package/src/decorators/EmptyMapContextDecorator.js +11 -6
  116. package/src/decorators/MapContext3DDecorator.js +25 -20
  117. package/src/decorators/MapContextDashboardDecorator.js +7 -2
  118. package/src/decorators/MapContextDecorator.js +7 -3
  119. package/src/decorators/MapContextKlokantechBasicDecorator.js +8 -4
  120. package/src/decorators/MultiMapContextDecorator.js +2 -1
  121. package/src/hooks/useMap.js +33 -62
  122. package/src/hooks/useMapState.js +3 -3
  123. package/src/hooks/useWms.js +7 -6
  124. package/src/i18n.js +28 -0
  125. package/src/index.js +3 -0
  126. package/src/translations/english.js +4 -0
  127. package/src/translations/german.js +4 -0
  128. package/src/ui_components/ImageLoader.js +73 -0
  129. package/src/ui_components/Sidebar.js +75 -20
  130. package/src/ui_components/TopToolbar.js +18 -18
  131. package/coverage/lcov-report/components/MlLayer/index.html +0 -117
  132. package/coverage/lcov-report/hooks/index.html +0 -147
  133. package/coverage/lcov-report/hooks/useMap.js.html +0 -383
package/dist/index.esm.js CHANGED
@@ -5,17 +5,18 @@ import maplibregl from 'maplibre-gl/dist/maplibre-gl';
5
5
  import 'maplibre-gl/dist/maplibre-gl.css';
6
6
  import { v4 } from 'uuid';
7
7
  import Button from '@mui/material/Button';
8
+ import RoomIcon from '@mui/icons-material/Room';
9
+ import { lineString, length, lineChunk, point, circle, bbox, lineOffset, distance } from '@turf/turf';
8
10
  import maplibregl$1, { Popup } from 'maplibre-gl';
9
11
  import jsPDF from 'jspdf';
10
12
  import PrinterIcon from '@mui/icons-material/Print';
11
- import { lineString, length, lineChunk, point, bbox } from '@turf/turf';
12
13
  import ButtonGroup from '@mui/material/ButtonGroup';
13
14
  import ControlPointIcon from '@mui/icons-material/ControlPoint';
14
15
  import RemoveCircleOutlineIcon from '@mui/icons-material/RemoveCircleOutline';
15
16
  import GpsFixedIcon from '@mui/icons-material/GpsFixed';
16
17
  import _styled from '@emotion/styled/base';
17
18
  import { css } from '@emotion/css';
18
- import RoomIcon from '@mui/icons-material/Room';
19
+ import useMediaQuery from '@mui/material/useMediaQuery';
19
20
  import '@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css';
20
21
  import MapboxDraw from '@mapbox/mapbox-gl-draw';
21
22
  import Point from '@mapbox/point-geometry';
@@ -30,6 +31,7 @@ import FileCopy from '@mui/icons-material/FileCopy';
30
31
  import List from '@mui/material/List';
31
32
  import ListItem from '@mui/material/ListItem';
32
33
  import ListItemText from '@mui/material/ListItemText';
34
+ import { lineString as lineString$1, polygon } from '@turf/helpers';
33
35
 
34
36
  function ownKeys(object, enumerableOnly) {
35
37
  var keys = Object.keys(object);
@@ -287,7 +289,7 @@ var MapLibreGlWrapper = function MapLibreGlWrapper(props) {
287
289
  on: function on(eventName, handler, options, componentId) {
288
290
  if (!self.eventHandlers[eventName]) return;
289
291
 
290
- if (typeof options === 'string') {
292
+ if (typeof options === "string") {
291
293
  componentId = options;
292
294
  options = {};
293
295
  }
@@ -340,7 +342,7 @@ var MapLibreGlWrapper = function MapLibreGlWrapper(props) {
340
342
  /**
341
343
  * Array containing an object for each layer in the MapLibre instance providing information on visibility, loading state, order, paint & layout properties
342
344
  */
343
- layerState: {},
345
+ layerState: [],
344
346
 
345
347
  /**
346
348
  * Maps layerIds to layerState in JSON string form for quick deep comparisons
@@ -428,7 +430,7 @@ var MapLibreGlWrapper = function MapLibreGlWrapper(props) {
428
430
  */
429
431
  oldViewportStateString: "{}",
430
432
  getViewport: function getViewport() {
431
- return typeof self.map.getCenter === 'function' ? {
433
+ return typeof self.map.getCenter === "function" ? {
432
434
  center: function (_ref) {
433
435
  var lng = _ref.lng,
434
436
  lat = _ref.lat,
@@ -444,24 +446,8 @@ var MapLibreGlWrapper = function MapLibreGlWrapper(props) {
444
446
  pitch: self.map.getPitch()
445
447
  } : {};
446
448
  },
447
- viewportRefreshEnabled: true,
448
- viewportRefreshWaiting: false,
449
- refreshViewport: function refreshViewport(force) {
450
- if (self.wrapper.viewportRefreshEnabled || force) {
451
- self.wrapper.viewportRefreshEnabled = false;
452
- self.wrapper.viewportState = self.wrapper.getViewport();
453
- self.wrapper.viewportStateString = JSON.stringify(self.wrapper.viewportState);
454
- setTimeout(function () {
455
- self.wrapper.viewportRefreshEnabled = true;
456
-
457
- if (self.wrapper.viewportRefreshWaiting) {
458
- self.wrapper.viewportRefreshWaiting = false;
459
- self.wrapper.refreshViewport();
460
- }
461
- }, 50);
462
- } else {
463
- self.wrapper.viewportRefreshWaiting = true;
464
- }
449
+ refreshViewport: function refreshViewport() {
450
+ self.wrapper.viewportState = self.wrapper.getViewport();
465
451
  }
466
452
  };
467
453
  /**
@@ -738,7 +724,7 @@ var MapLibreGlWrapper = function MapLibreGlWrapper(props) {
738
724
  if (response.ok) {
739
725
  return response.json();
740
726
  } else {
741
- throw new Error('error loading map style.json');
727
+ throw new Error("error loading map style.json");
742
728
  }
743
729
  }).then(function (styleJson) {
744
730
  styleJson.layers.forEach(function (item) {
@@ -757,15 +743,11 @@ var MapLibreGlWrapper = function MapLibreGlWrapper(props) {
757
743
  case 3:
758
744
  self.map = new maplibregl.Map(props.mapOptions);
759
745
  self.addNativeMaplibreFunctionsAndProps();
760
- self.wrapper.refreshViewport(true);
746
+ self.wrapper.refreshViewport();
761
747
  self.wrapper.fire("viewportchange");
762
748
  self.map.on("move", function () {
763
- self.wrapper.refreshViewport();
764
-
765
- if (self.wrapper.viewportStateString !== self.wrapper.oldViewportStateString) {
766
- self.wrapper.oldViewportStateString = self.wrapper.viewportStateString;
767
- self.wrapper.fire("viewportchange");
768
- }
749
+ self.wrapper.viewportState = self.wrapper.getViewport();
750
+ self.wrapper.fire("viewportchange");
769
751
  });
770
752
  self.map.on("data", function () {
771
753
  self.wrapper.refreshLayerState();
@@ -873,28 +855,74 @@ MapLibreMap.propTypes = {
873
855
  };
874
856
 
875
857
  /**
876
- * TODO: Add short & useful description
877
- *
878
- * @param {object} props
879
- * @param {string} props.mapId Id of the target MapLibre instance in mapContext
858
+ * React hook that allows subscribing to map state changes
880
859
  *
881
860
  * @component
882
861
  */
883
862
 
884
- var MlComponentTemplate = function MlComponentTemplate(props) {
863
+ function useMapState(props) {
885
864
  // Use a useRef hook to reference the layer object to be able to access it later inside useEffect hooks
886
865
  var mapContext = useContext(MapContext);
887
866
  var initializedRef = useRef(false);
888
867
  var mapRef = useRef(undefined);
889
- var componentId = useRef((props.idPrefix ? props.idPrefix : "MlComponentTemplate-") + v4());
868
+
869
+ var _useState = useState(undefined),
870
+ _useState2 = _slicedToArray(_useState, 2),
871
+ center = _useState2[0],
872
+ setCenter = _useState2[1];
873
+
874
+ var _useState3 = useState(undefined),
875
+ _useState4 = _slicedToArray(_useState3, 2),
876
+ viewport = _useState4[0],
877
+ setViewport = _useState4[1];
878
+
879
+ var viewportRef = useRef(undefined);
880
+
881
+ var _useState5 = useState(undefined),
882
+ _useState6 = _slicedToArray(_useState5, 2),
883
+ layers = _useState6[0],
884
+ setLayers = _useState6[1];
885
+
886
+ var layersRef = useRef(undefined); //const mapRef = useRef(props.map);
887
+
888
+ var componentId = useRef(v4());
889
+ /**
890
+ * returns the element if it matches the defined filter criteria
891
+ * to be used as filter function on the layers array
892
+ *
893
+ * @param {object} layer
894
+ */
895
+
896
+ var layerIdFilter = useCallback(function (layer) {
897
+ var _props$filter, _props$filter2;
898
+
899
+ if (!(props !== null && props !== void 0 && (_props$filter = props.filter) !== null && _props$filter !== void 0 && _props$filter.includeBaseLayers) && layer.baseLayer) {
900
+ return false;
901
+ }
902
+
903
+ if (typeof ((_props$filter2 = props.filter) === null || _props$filter2 === void 0 ? void 0 : _props$filter2.matchLayerIds) !== "undefined") {
904
+ if (props.filter.matchLayerIds instanceof RegExp) {
905
+ return props.filter.matchLayerIds.test(layer.id);
906
+ } else {
907
+ return layer.id.includes(props.filter.matchLayerIds);
908
+ }
909
+ }
910
+
911
+ return true;
912
+ }, [props.filter]);
913
+ var refreshLayerState = useCallback(function () {
914
+ var _layerState = mapRef.current.wrapper.layerState.filter(layerIdFilter);
915
+
916
+ var _layerStateString = JSON.stringify(_layerState);
917
+
918
+ if (layersRef.current !== _layerStateString) {
919
+ layersRef.current = _layerStateString;
920
+ setLayers(_layerState);
921
+ }
922
+ }, [layerIdFilter]);
890
923
  useEffect(function () {
891
924
  var _componentId = componentId.current;
892
925
  return function () {
893
- // This is the cleanup function, it is called when this react component is removed from react-dom
894
- // try to remove anything this component has added to the MapLibre-gl instance
895
- // e.g.: remove the layer
896
- // mapContext.getMap(props.mapId).removeLayer(layerRef.current);
897
- // check for the existence of map.style before calling getLayer or getSource
898
926
  if (mapRef.current) {
899
927
  mapRef.current.cleanup(_componentId);
900
928
  mapRef.current = undefined;
@@ -904,13 +932,177 @@ var MlComponentTemplate = function MlComponentTemplate(props) {
904
932
  };
905
933
  }, []);
906
934
  useEffect(function () {
935
+ var _props$watch, _props$watch2;
936
+
907
937
  if (!mapContext.mapExists(props.mapId) || initializedRef.current) return; // the MapLibre-gl instance (mapContext.getMap(props.mapId)) is accessible here
908
938
  // initialize the layer and add it to the MapLibre-gl instance or do something else with it
909
939
 
910
940
  initializedRef.current = true;
911
941
  mapRef.current = mapContext.getMap(props.mapId);
912
- mapRef.current.setCenter([7.132122000552613, 50.716405378037706]);
913
- }, [mapContext.mapIds, mapContext, props.mapId]);
942
+ /*
943
+ mapRef.current.on(
944
+ "move",
945
+ () => {
946
+ setCenter(mapRef.current.getCenter());
947
+ },
948
+ componentId.current
949
+ );
950
+ */
951
+
952
+ if (props !== null && props !== void 0 && (_props$watch = props.watch) !== null && _props$watch !== void 0 && _props$watch.viewport) {
953
+ setViewport(mapRef.current.wrapper.viewportState);
954
+ mapRef.current.wrapper.on("viewportchange", function () {
955
+ var _mapRef$current;
956
+
957
+ if (viewportRef.current !== ((_mapRef$current = mapRef.current) === null || _mapRef$current === void 0 ? void 0 : _mapRef$current.wrapper.viewportStateString)) {
958
+ var _mapRef$current2, _mapRef$current3, _mapRef$current3$wrap;
959
+
960
+ setViewport((_mapRef$current2 = mapRef.current) === null || _mapRef$current2 === void 0 ? void 0 : _mapRef$current2.wrapper.viewportState);
961
+ setCenter((_mapRef$current3 = mapRef.current) === null || _mapRef$current3 === void 0 ? void 0 : (_mapRef$current3$wrap = _mapRef$current3.wrapper.viewportState) === null || _mapRef$current3$wrap === void 0 ? void 0 : _mapRef$current3$wrap.center);
962
+ }
963
+ }, componentId.current);
964
+ }
965
+
966
+ if (props !== null && props !== void 0 && (_props$watch2 = props.watch) !== null && _props$watch2 !== void 0 && _props$watch2.layers) {
967
+ var _props$filter3, _props$filter4;
968
+
969
+ refreshLayerState();
970
+ mapRef.current.wrapper.on("layerchange", refreshLayerState, {
971
+ includeBaseLayers: props === null || props === void 0 ? void 0 : (_props$filter3 = props.filter) === null || _props$filter3 === void 0 ? void 0 : _props$filter3.includeBaseLayers,
972
+ matchLayerIds: props === null || props === void 0 ? void 0 : (_props$filter4 = props.filter) === null || _props$filter4 === void 0 ? void 0 : _props$filter4.matchLayerIds
973
+ }, componentId.current);
974
+ }
975
+ }, [mapContext.mapIds, mapContext, props.mapId, refreshLayerState]);
976
+ return {
977
+ layers: layers,
978
+ viewport: viewport
979
+ };
980
+ }
981
+
982
+ useMapState.defaultProps = {
983
+ mapId: undefined,
984
+ watch: {
985
+ layers: true,
986
+ sources: false,
987
+ viewport: false
988
+ },
989
+ filter: {
990
+ includeBaseLayers: false
991
+ }
992
+ };
993
+ useMapState.propTypes = {
994
+ /**
995
+ * Id of the target MapLibre instance in mapContext
996
+ */
997
+ mapId: PropTypes.string,
998
+
999
+ /**
1000
+ * Defines map Resources to watch
1001
+ */
1002
+ watch: PropTypes.shape({
1003
+ layers: PropTypes.bool,
1004
+ sources: PropTypes.bool,
1005
+ viewport: PropTypes.bool
1006
+ }),
1007
+
1008
+ /**
1009
+ * Filter string or RegExp to more explicitly define the elements watched and increase performance
1010
+ * strings will be matched using layerId.includes(matchString)
1011
+ * RegExps will be matched using matchRegExp.test(layerId)
1012
+ */
1013
+ filter: PropTypes.shape({
1014
+ includeBaseLayers: PropTypes.bool,
1015
+ matchLayerIds: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(RegExp)]),
1016
+ matchSourceIds: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(RegExp)])
1017
+ })
1018
+ };
1019
+
1020
+ function useMap(props) {
1021
+ // Use a useRef hook to reference the layer object to be able to access it later inside useEffect hooks
1022
+ var mapContext = useContext(MapContext);
1023
+ var mapState = useMapState({
1024
+ mapId: props.mapId,
1025
+ watch: {
1026
+ viewport: false,
1027
+ layers: true,
1028
+ sources: false
1029
+ }
1030
+ });
1031
+ var initializedRef = useRef(false);
1032
+ var mapRef = useRef(undefined);
1033
+ var componentId = useRef(v4());
1034
+
1035
+ var _useState = useState(undefined),
1036
+ _useState2 = _slicedToArray(_useState, 2),
1037
+ mapIsReady = _useState2[0],
1038
+ setMapIsReady = _useState2[1];
1039
+
1040
+ useEffect(function () {
1041
+ var _componentId = componentId.current;
1042
+ return function () {
1043
+ if (mapRef.current) {
1044
+ mapRef.current.cleanup(_componentId);
1045
+ mapRef.current = undefined;
1046
+ }
1047
+
1048
+ initializedRef.current = false;
1049
+ setMapIsReady(false);
1050
+ };
1051
+ }, []);
1052
+ useEffect(function () {
1053
+ if (!mapContext.mapExists(props.mapId) || initializedRef.current) return; //check if insertBeforeLayer exists
1054
+
1055
+ if (props.waitForLayer) {
1056
+ var _mapState$layers;
1057
+
1058
+ var layerFound = false;
1059
+ mapState === null || mapState === void 0 ? void 0 : (_mapState$layers = mapState.layers) === null || _mapState$layers === void 0 ? void 0 : _mapState$layers.forEach(function (layer) {
1060
+ if (layer.id === props.waitForLayer) {
1061
+ layerFound = true;
1062
+ }
1063
+ });
1064
+
1065
+ if (!layerFound) {
1066
+ return;
1067
+ }
1068
+ } // the MapLibre-gl instance (mapContext.getMap(props.mapId)) is accessible here
1069
+ // initialize the layer and add it to the MapLibre-gl instance or do something else with it
1070
+
1071
+
1072
+ initializedRef.current = true;
1073
+ mapRef.current = mapContext.getMap(props.mapId);
1074
+ setMapIsReady(true);
1075
+ }, [mapContext.mapIds, mapState.layers, mapContext, props.mapId]);
1076
+ return {
1077
+ map: mapRef.current,
1078
+ mapIsReady: mapIsReady,
1079
+ componentId: componentId.current,
1080
+ layers: mapState.layers
1081
+ };
1082
+ }
1083
+
1084
+ /**
1085
+ * TODO: Add short & useful description
1086
+ *
1087
+ * @param {object} props
1088
+ * @param {string} props.mapId Id of the target MapLibre instance in mapContext
1089
+ *
1090
+ * @component
1091
+ */
1092
+
1093
+ var MlComponentTemplate = function MlComponentTemplate(props) {
1094
+ var mapHook = useMap({
1095
+ mapId: props.mapId,
1096
+ waitForLayer: props.insertBeforeLayer
1097
+ });
1098
+ var initializedRef = useRef(false);
1099
+ useEffect(function () {
1100
+ if (!mapHook.mapIsReady || initializedRef.current) return; // the MapLibre-gl instance (mapHook.map) is accessible here
1101
+ // initialize the layer and add it to the MapLibre-gl instance or do something else with it
1102
+
1103
+ initializedRef.current = true;
1104
+ mapHook.map.setCenter([7.132122000552613, 50.716405378037706]);
1105
+ }, [mapHook.map, props.mapId]);
914
1106
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null);
915
1107
  };
916
1108
 
@@ -1057,219 +1249,32 @@ MlFillExtrusionLayer.propTypes = {
1057
1249
  insertBeforeLayer: PropTypes.string
1058
1250
  };
1059
1251
 
1060
- var nmMap = {
1061
- street: ["footway", "street", "road", "street_name", "residential", "path", "pedestrian", "road_reference", "road_reference_intl", "square", "place"],
1062
- number: ["house_number", "street_number"],
1063
- place: ["city", "village", "hamlet", "locality", "croft", "neighbourhood", "suburb", "city_district", "district", "quarter", "borough", "city_block", "residential", "commercial", "industrial", "houses", "subdivision", "allotments", "postal_city", "town", "municipality", "local_administrative_area"],
1064
- zip: ["postcode", "partial_postcode"],
1065
- state: ["state", "province", "state_code"]
1066
- };
1252
+ var _showNextTransitionSegment = function _showNextTransitionSegment(props, layerId, map, transitionInProgressRef, transitionGeojsonDataRef, transitionGeojsonCommonDataRef, currentTransitionStepRef, msPerStep, transitionTimeoutRef) {
1253
+ var _arguments = arguments;
1067
1254
 
1068
- var nmConverter = function nmConverter(nmAddress) {
1069
- var addressArr = [];
1255
+ if (typeof map.getSource(layerId) === "undefined" || !transitionInProgressRef.current) {
1256
+ transitionTimeoutRef.current = setTimeout(function () {
1257
+ return _showNextTransitionSegment.apply(void 0, _toConsumableArray(_arguments));
1258
+ }, msPerStep);
1259
+ return;
1260
+ }
1070
1261
 
1071
- for (var key in nmMap) {
1072
- nmMap[key].some(function (element) {
1073
- if (nmAddress.hasOwnProperty(element)) {
1074
- addressArr.push(nmAddress[element]);
1075
- return true;
1076
- }
1262
+ if (typeof transitionGeojsonDataRef.current[currentTransitionStepRef.current] !== "undefined") {
1263
+ var _map$getSource;
1077
1264
 
1078
- return false;
1079
- });
1080
- }
1265
+ var newData = currentTransitionStepRef.current + 1 === transitionGeojsonDataRef.current.length ? props.geojson : lineString([].concat(_toConsumableArray(transitionGeojsonCommonDataRef.current), _toConsumableArray(transitionGeojsonDataRef.current[currentTransitionStepRef.current].geometry.coordinates)));
1081
1266
 
1082
- return addressArr.join(", ");
1083
- };
1267
+ if (!(map !== null && map !== void 0 && (_map$getSource = map.getSource) !== null && _map$getSource !== void 0 && _map$getSource.call(map, layerId))) {
1268
+ return;
1269
+ }
1084
1270
 
1085
- var toPixels = function toPixels(length) {
1086
- var conversionFactor = 96;
1087
- conversionFactor /= 25.4;
1088
- return conversionFactor * length + "px";
1089
- };
1271
+ map.getSource(layerId).setData(newData);
1090
1272
 
1091
- var createPdf = function createPdf(map, locationValue, setLoading) {
1092
- setLoading(true);
1093
- var width = 210;
1094
- var height = 297; // Calculate pixel ratio
1273
+ if (typeof props.onTransitionFrame === "function") {
1274
+ props.onTransitionFrame(newData);
1275
+ }
1095
1276
 
1096
- var actualPixelRatio = window.devicePixelRatio; // Create map container
1097
-
1098
- var hidden = document.createElement("div");
1099
- hidden.className = "hidden-map";
1100
- document.body.appendChild(hidden);
1101
- var container = document.createElement("div");
1102
- container.style.width = toPixels(width);
1103
- container.style.height = toPixels(height);
1104
- hidden.appendChild(container); //Render map
1105
-
1106
- var renderMap = new maplibregl$1.Map({
1107
- container: container,
1108
- center: map.getCenter(),
1109
- zoom: map.getZoom(),
1110
- bearing: map.getBearing(),
1111
- pitch: map.getPitch(),
1112
- interactive: false,
1113
- preserveDrawingBuffer: true,
1114
- fadeDuration: 0,
1115
- attributionControl: false
1116
- });
1117
- var style = map.getStyle();
1118
-
1119
- var _loop = function _loop(name) {
1120
- var src = style.sources[name];
1121
- Object.keys(src).forEach(function (key) {
1122
- //delete properties if value is undefined.
1123
- // for instance, raster-dem might has undefined value in "url" and "bounds"
1124
- if (!src[key]) {
1125
- delete src[key];
1126
- }
1127
- });
1128
- };
1129
-
1130
- for (var name in style.sources) {
1131
- _loop(name);
1132
- }
1133
-
1134
- renderMap.setStyle(style);
1135
- renderMap.once("idle", function () {
1136
- var _hidden$parentNode;
1137
-
1138
- // TO DO: It is still under development
1139
- var pdf = new jsPDF({
1140
- orientation: "p",
1141
- unit: "mm",
1142
- compress: true
1143
- });
1144
- Object.defineProperty(window, "devicePixelRatio", {
1145
- get: function get() {
1146
- return 300 / 96;
1147
- }
1148
- });
1149
- var offsetX = 2.5;
1150
- var offsetY = 2.5;
1151
- var marginTop = 3;
1152
- var marginBottom = 3;
1153
- var innerMargin = 2;
1154
- var logo = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKgAAACxCAMAAABnTAbVAAAC8VBMVEUAAAD/AACAAACqAFW/AECZMzOqK1W2JEm/IECqHDmzGk25F0aqFUCxJzu2JEmqIkSvIEC0HjyqHEeuG0OzGkC2GD2uI0axIUO1IECtHz2xHUWzHEKtG0CwGj6zIkS1IUKyHz60HkSvHUKxHECzHD6uG0OxIUGzIECuHz6wHkOyHkG0HUCwHD6xHEOzIUGvIECxHz6zH0KvHkGxHUCyHT+vHEKwHEGyIECzHz+wH0KxHkGzHkCwHT+xHUKyHEGvIECxHz+yH0KzHkGwHkCxHj+zHUKwHUGxHECyHz+wH0GxH0GyHkCwHj+xHUGyHUGzHUCwHz+xH0GyH0GwHkCxHj+yHkGwHUCxHUCyHT+wH0GxH0CxHkCyHj+wHkGxHkCyHUCwHT+xH0GyH0CwH0CxHj+yHkGwHkCxHUCxHT+yHUGwH0CxH0CyHj+wHkGxHkCyHkCwHT+xHUGxH0CyH0CxHz+xHkGyHkCwHkCxHj+yHUGwHUCxH0CwHkGxHkCxHkCyHj+xHUGxHUCyH0CwHz+xHkGyHkCwHkCxHj+xHkGwHUCxHUCxHz+yH0GxHkCyHj+wHkGxHUCxHUCwHz+xH0GxHkCyHkCxHj+xHkGyHkCxHUCxHT+yH0GwHkCxHkCxHj+wHkGxHkCxHkCyHT+xH0GxH0CyHkCxHj+xHkGxHkCwHkCxHT+xHUCwH0CxHkCxHj+yHkCxHkCxHkCyHj+xHUCxH0CxHkCwHj+xHkCxHkCwHkCxHj+xHkCyHUCxH0CxHj+xHkCxHkCxHkCxHj+wHkCxHUCxH0CyHj+xHkCxHkCyHkCxHj+xHkCxHUCxHz+xHkCwHkCxHkCxHj+yHkCxHkCxHkC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zHhq9AJs1Jl+arpBbhW1uRJ2KqXSMii0LqAWu2Crb6hQGgOlrr9Sgxmw1ftUSIe/MR42q7I9bPU05bZLUPEEm5UDe02jTGU3qJHWsjn3wl7jKbMA6iK+YjO6wF430te3IQgg9hCDOgCbJdNH+RUIqMtxBvMybDaAPiYhiH5lDOJW2Kwfm7yBoJIqGFhX2CyJXgURCG74OQZS4YDNxrJR6RVozohKBrAHdpvEBjUj0LyUCqpbDbvdzwaTocWQUqqaB7stYr1MaJNQRDV3wG7v8DdrJGjU7SBVXA+7fcELPgyFZh2+oL/+sJmjjOd9HAYdWuXQzxWwWS+e92EodJEWeagQA5tNJ7khFHrdUk65cNgsh8wOhX4991GmFewVVs7nHTAiYil9tYO9Uuruh1F3n2GTONjr6dEwrnMevfrBXrEwwzGvig3GomXrvoP1HkQLJ6WV8II30OJ1XO0huQu/AwN3k5Vh+B1wpP3EIfhdCE2fhv+X/wF/AO+L9vuzfwAAAABJRU5ErkJggg==";
1155
- var textBuffer = 1;
1156
- var lineHeight = 3.25;
1157
- var text = locationValue ? nmConverter(locationValue.address) : "";
1158
- var textChunksSeperator = text.split(",");
1159
- var textChunks = [];
1160
-
1161
- if (textChunks.length) {
1162
- textChunksSeperator.forEach(function (chunk) {
1163
- var limitChunks = chunk.match(/.{1,34}/g);
1164
- textChunks.push.apply(textChunks, _toConsumableArray(limitChunks));
1165
- });
1166
- } //Render map image
1167
-
1168
-
1169
- pdf.addImage(renderMap.getCanvas().toDataURL("image/png"), "png", 0, 0, 210, 297, null, "FAST"); //Render lower left Copyright box
1170
-
1171
- pdf.setFillColor("white");
1172
- pdf.rect(138, 287, 297, 10, "F");
1173
- pdf.setFontSize(10); // optional
1174
-
1175
- pdf.text("Datenquelle: © OpenStreetMap-Mitwirkende", 140, pdf.internal.pageSize.height - 3); //Render infobox
1176
-
1177
- pdf.setFillColor("white");
1178
- var infoBoxSize = textChunks.length * lineHeight + marginTop + marginBottom + lineHeight * 2 + innerMargin * 2 + textBuffer;
1179
- pdf.rect(offsetX, 2, 66.5, infoBoxSize, "F");
1180
- pdf.setFontSize(10);
1181
- pdf.text("Karten PDF:", 6, offsetY + marginTop); //Render inner infobox
1182
-
1183
- pdf.rect(6, 7, 60, textChunks.length * lineHeight + innerMargin * 2 + textBuffer);
1184
- pdf.setFontSize(10); //Write out address
1185
-
1186
- textChunks.forEach(function (text, i) {
1187
- pdf.text(text.trim(), 8, 10 + i * 3.5 + innerMargin);
1188
- }); //Add WG Logo
1189
-
1190
- pdf.addImage(logo, "png", 5, offsetY + marginTop + lineHeight * 2 + textChunks.length * 3 + innerMargin * 2, 3, 3, null, "FAST"); //Add WG Url
1191
-
1192
- pdf.setFontSize(10);
1193
- pdf.text("wheregroup.com", 40, offsetY + marginTop + lineHeight * 2 + textChunks.length * lineHeight + innerMargin * 2 + textBuffer); //Set pdfs props
1194
-
1195
- pdf.setProperties({
1196
- title: "Map export",
1197
- subject: "Map export",
1198
- creator: "WhereGroup GmbH",
1199
- author: "(c)WhereGroup GmbH, (c)OpenStreetMap"
1200
- });
1201
- pdf.save("Map.pdf");
1202
- renderMap.remove();
1203
- (_hidden$parentNode = hidden.parentNode) === null || _hidden$parentNode === void 0 ? void 0 : _hidden$parentNode.removeChild(hidden);
1204
- Object.defineProperty(window, "devicePixelRatio", {
1205
- get: function get() {
1206
- return actualPixelRatio;
1207
- }
1208
- });
1209
- setLoading(false);
1210
- });
1211
- };
1212
-
1213
- /**
1214
- * Renders a button that will create a PDF version of the current map view (dimensions adjusted to fit Din A4 Paper).
1215
- *
1216
- * @component
1217
- */
1218
-
1219
- var MlCreatePdfButton = function MlCreatePdfButton(props) {
1220
- var mapContext = useContext(MapContext);
1221
- var initializedRef = useRef(false);
1222
- var mapRef = useRef(undefined);
1223
- useEffect(function () {
1224
- if (!mapContext.mapExists(props.mapId) || initializedRef.current) return;
1225
- initializedRef.current = true;
1226
- mapRef.current = mapContext.getMap(props.mapId);
1227
- }, [mapContext.mapIds, mapContext, props.mapId]);
1228
- return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Button, {
1229
- color: "primary",
1230
- variant: "contained",
1231
- onClick: function onClick() {
1232
- createPdf(mapRef.current, null, function () {});
1233
- }
1234
- }, /*#__PURE__*/React__default.createElement(PrinterIcon, null)));
1235
- };
1236
-
1237
- MlCreatePdfButton.defaultProps = {
1238
- mapId: undefined
1239
- };
1240
- MlCreatePdfButton.propTypes = {
1241
- /**
1242
- * Id of the target MapLibre instance in mapContext
1243
- */
1244
- mapId: PropTypes.string
1245
- };
1246
-
1247
- var _showNextTransitionSegment = function _showNextTransitionSegment(props, layerId, map, transitionInProgressRef, transitionGeojsonDataRef, transitionGeojsonCommonDataRef, currentTransitionStepRef, msPerStep, transitionTimeoutRef) {
1248
- var _arguments = arguments;
1249
-
1250
- if (typeof map.getSource(layerId) === "undefined" || !transitionInProgressRef.current) {
1251
- transitionTimeoutRef.current = setTimeout(function () {
1252
- return _showNextTransitionSegment.apply(void 0, _toConsumableArray(_arguments));
1253
- }, msPerStep);
1254
- return;
1255
- }
1256
-
1257
- if (typeof transitionGeojsonDataRef.current[currentTransitionStepRef.current] !== "undefined") {
1258
- var _map$getSource;
1259
-
1260
- var newData = currentTransitionStepRef.current + 1 === transitionGeojsonDataRef.current.length ? props.geojson : lineString([].concat(_toConsumableArray(transitionGeojsonCommonDataRef.current), _toConsumableArray(transitionGeojsonDataRef.current[currentTransitionStepRef.current].geometry.coordinates)));
1261
-
1262
- if (!(map !== null && map !== void 0 && (_map$getSource = map.getSource) !== null && _map$getSource !== void 0 && _map$getSource.call(map, layerId))) {
1263
- return;
1264
- }
1265
-
1266
- map.getSource(layerId).setData(newData);
1267
-
1268
- if (typeof props.onTransitionFrame === "function") {
1269
- props.onTransitionFrame(newData);
1270
- }
1271
-
1272
- currentTransitionStepRef.current++;
1277
+ currentTransitionStepRef.current++;
1273
1278
 
1274
1279
  if (transitionInProgressRef.current && currentTransitionStepRef.current < transitionGeojsonDataRef.current.length) {
1275
1280
  transitionTimeoutRef.current = setTimeout(function () {
@@ -1417,6 +1422,14 @@ var msPerStep = 50;
1417
1422
  var MlGeoJsonLayer = function MlGeoJsonLayer(props) {
1418
1423
  // Use a useRef hook to reference the layer object to be able to access it later inside useEffect hooks
1419
1424
  var mapContext = useContext(MapContext);
1425
+ var mapState = useMapState({
1426
+ mapId: props.mapId,
1427
+ watch: {
1428
+ viewport: false,
1429
+ layers: true,
1430
+ sources: false
1431
+ }
1432
+ });
1420
1433
  var oldGeojsonRef = useRef(null);
1421
1434
  var mapRef = useRef(null);
1422
1435
  var initializedRef = useRef(false);
@@ -1442,11 +1455,17 @@ var MlGeoJsonLayer = function MlGeoJsonLayer(props) {
1442
1455
  };
1443
1456
  }, []);
1444
1457
  useEffect(function () {
1445
- if (!mapRef.current || !initializedRef.current) return; // the MapLibre-gl instance (mapContext.map) is accessible here
1446
- // initialize the layer and add it to the MapLibre-gl instance or do something else with it
1458
+ if (!mapRef.current || !initializedRef.current) return;
1459
+
1460
+ for (var key in props.layout) {
1461
+ mapContext.getMap(props.mapId).setLayoutProperty(layerId.current, key, props.layout[key]);
1462
+ }
1463
+ }, [props.layout, mapContext, props.mapId]);
1464
+ useEffect(function () {
1465
+ if (!mapRef.current || !initializedRef.current) return;
1447
1466
 
1448
1467
  for (var key in props.paint) {
1449
- mapContext.getMap(props.mapId).setPaintProperty(componentId.current, key, props.paint[key]);
1468
+ mapContext.getMap(props.mapId).setPaintProperty(layerId.current, key, props.paint[key]);
1450
1469
  }
1451
1470
  }, [props.paint, mapContext, props.mapId]);
1452
1471
  var transitionToGeojson = useCallback(function (newGeojson) {
@@ -1475,6 +1494,22 @@ var MlGeoJsonLayer = function MlGeoJsonLayer(props) {
1475
1494
  // initialize the layer and add it to the MapLibre-gl instance or do something else with it
1476
1495
 
1477
1496
  if (props.geojson) {
1497
+ //check if insertBeforeLayer exists
1498
+ if (props.insertBeforeLayer) {
1499
+ var _mapState$layers;
1500
+
1501
+ var layerFound = false;
1502
+ mapState === null || mapState === void 0 ? void 0 : (_mapState$layers = mapState.layers) === null || _mapState$layers === void 0 ? void 0 : _mapState$layers.forEach(function (layer) {
1503
+ if (layer.id === props.insertBeforeLayer) {
1504
+ layerFound = true;
1505
+ }
1506
+ });
1507
+
1508
+ if (!layerFound) {
1509
+ return;
1510
+ }
1511
+ }
1512
+
1478
1513
  initializedRef.current = true;
1479
1514
  var geojson = props.geojson;
1480
1515
 
@@ -1494,7 +1529,8 @@ var MlGeoJsonLayer = function MlGeoJsonLayer(props) {
1494
1529
  paint: props.paint || {
1495
1530
  "line-color": "rgb(100,200,100)",
1496
1531
  "line-width": 10
1497
- }
1532
+ },
1533
+ layout: props.layout || {}
1498
1534
  }, props.insertBeforeLayer, componentId.current);
1499
1535
 
1500
1536
  if (typeof props.onHover !== "undefined") {
@@ -1514,7 +1550,7 @@ var MlGeoJsonLayer = function MlGeoJsonLayer(props) {
1514
1550
  oldGeojsonRef.current = props.geojson;
1515
1551
  }
1516
1552
  }
1517
- }, [mapContext.mapIds, mapContext, props, transitionToGeojson]);
1553
+ }, [mapContext.mapIds, mapContext, props, transitionToGeojson, mapState.layers]);
1518
1554
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null);
1519
1555
  };
1520
1556
 
@@ -1531,8 +1567,17 @@ MlGeoJsonLayer.propTypes = {
1531
1567
  type: PropTypes.string,
1532
1568
 
1533
1569
  /**
1534
- * Paint object, that is passed to the addLayer call.
1535
- * Possible propsdepend on the layer type.
1570
+ * Layout property object, that is passed to the addLayer call.
1571
+ * Possible props depend on the layer type.
1572
+ * https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#line
1573
+ * https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#circle
1574
+ * https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#fill
1575
+ */
1576
+ layout: PropTypes.object,
1577
+
1578
+ /**
1579
+ * Paint property object, that is passed to the addLayer call.
1580
+ * Possible props depend on the layer type.
1536
1581
  * https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#line
1537
1582
  * https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#circle
1538
1583
  * https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#fill
@@ -1585,42 +1630,31 @@ MlGeoJsonLayer.propTypes = {
1585
1630
  };
1586
1631
 
1587
1632
  var MlImageMarkerLayer = function MlImageMarkerLayer(props) {
1588
- // Use a useRef hook to reference the layer object to be able to access it later inside useEffect hooks
1589
- var mapRef = useRef(null);
1590
- var componentId = useRef((props.idPrefix ? props.idPrefix : "MlOsmLayer-") + v4());
1591
- var mapContext = useContext(MapContext);
1633
+ var mapHook = useMap({
1634
+ mapId: props.mapId,
1635
+ waitForLayer: props.insertBeforeLayer
1636
+ });
1592
1637
  var layerInitializedRef = useRef(false);
1593
- var idSuffixRef = useRef(props.idSuffix || new Date().getTime());
1594
1638
  var imageIdRef = useRef(props.imageId || "img_" + new Date().getTime());
1595
- var layerId = useRef((props.layerId || "MlImageMarkerLayer-") + idSuffixRef.current);
1596
- useEffect(function () {
1597
- var _componentId = componentId.current;
1598
- return function () {
1599
- // This is the cleanup function, it is called when this react component is removed from react-dom
1600
- if (mapRef.current) {
1601
- mapRef.current.cleanup(_componentId);
1602
- mapRef.current = null;
1603
- }
1604
- };
1605
- }, []);
1639
+ var layerId = useRef(props.layerId || "MlImageMarkerLayer-" + mapHook.componentId);
1606
1640
  useEffect(function () {
1607
- if (!mapRef.current || mapRef.current && !mapContext.getMap(props.mapId).getLayer(layerId.current) || !props.options) return; // the MapLibre-gl instance (mapContext.map) is accessible here
1641
+ if (!mapHook.mapIsReady || mapHook.map && !mapHook.map.getLayer(layerId.current) || !props.options) return; // the MapLibre-gl instance (mapContext.map) is accessible here
1608
1642
  // initialize the layer and add it to the MapLibre-gl instance or do something else with it
1609
1643
 
1610
1644
  var key;
1611
1645
 
1612
1646
  if (props.options.layout) {
1613
1647
  for (key in props.options.layout) {
1614
- mapContext.getMap(props.mapId).setLayoutProperty(layerId.current, key, props.options.layout[key]);
1648
+ mapHook.map.setLayoutProperty(layerId.current, key, props.options.layout[key]);
1615
1649
  }
1616
1650
  }
1617
1651
 
1618
1652
  if (props.options.paint) {
1619
1653
  for (key in props.options.paint) {
1620
- mapContext.getMap(props.mapId).setPaintProperty(layerId.current, key, props.options.paint[key]);
1654
+ mapHook.map.setPaintProperty(layerId.current, key, props.options.paint[key]);
1621
1655
  }
1622
1656
  }
1623
- }, [props.options, layerId.current, mapContext, props.mapId]);
1657
+ }, [props.options, layerId.current, props.mapId]);
1624
1658
  var addLayer = useCallback(function () {
1625
1659
  var tmpOptions = _objectSpread2({
1626
1660
  id: layerId.current,
@@ -1628,66 +1662,416 @@ var MlImageMarkerLayer = function MlImageMarkerLayer(props) {
1628
1662
  }, props.options);
1629
1663
 
1630
1664
  tmpOptions.layout["icon-image"] = imageIdRef.current;
1631
- mapRef.current.addLayer(tmpOptions, props.insertBeforeLayer, componentId.current);
1632
- }, [props]);
1665
+ mapHook.map.addLayer(tmpOptions, props.insertBeforeLayer, mapHook.componentId);
1666
+ }, [props, mapHook.mapIsReady, mapHook.map]);
1633
1667
  useEffect(function () {
1634
- if (!props.options || !mapContext.mapExists(props.mapId) || layerInitializedRef.current) return; // the MapLibre-gl instance (mapContext.map) is accessible here
1635
- // initialize the layer and add it to the MapLibre-gl instance or do something else with it
1636
-
1637
- mapRef.current = mapContext.getMap(props.mapId);
1668
+ if (!props.options || !mapHook.mapIsReady || layerInitializedRef.current) return;
1638
1669
  layerInitializedRef.current = true;
1639
1670
 
1640
1671
  if (props.imgSrc) {
1641
- mapRef.current.loadImage(props.imgSrc, function (error, image) {
1672
+ mapHook.map.loadImage(props.imgSrc, function (error, image) {
1642
1673
  if (error) throw error;
1643
- mapRef.current.addImage(imageIdRef.current, image, componentId.current);
1674
+ mapHook.map.addImage(imageIdRef.current, image, mapHook.componentId);
1644
1675
  });
1645
1676
  }
1646
1677
 
1647
1678
  addLayer();
1648
- }, [mapContext.mapIds, mapContext, props, addLayer]);
1679
+ }, [mapHook.mapIsReady, mapHook.map, addLayer, props]);
1649
1680
  useEffect(function () {
1650
- if (!mapRef.current || mapRef.current && !mapContext.getMap(props.mapId).getLayer(layerId.current) || !props.options) {
1681
+ if (!mapHook.mapIsReady || mapHook.map && !mapHook.map.getLayer(layerId.current) || !props.options) {
1651
1682
  return;
1652
- } // the MapLibre-gl instance (mapContext.map) is accessible here
1653
- // initialize the layer and add it to the MapLibre-gl instance or do something else with it
1654
-
1683
+ }
1655
1684
 
1656
- mapRef.current.getSource(layerId.current).setData(props.options.source.data);
1657
- }, [props.options.source.data, mapContext, props]);
1685
+ mapHook.map.getSource(layerId.current).setData(props.options.source.data);
1686
+ }, [props.options.source.data, props]);
1658
1687
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null);
1659
1688
  };
1660
1689
 
1661
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
1690
+ var marker = "b556faa3bc6829d2.png";
1662
1691
 
1663
- function SvgRotateRight(props) {
1664
- return /*#__PURE__*/createElement("svg", _extends({
1665
- width: "39.675098mm",
1666
- height: "104.27064mm",
1667
- viewBox: "0 0 39.675098 104.27064"
1668
- }, props), /*#__PURE__*/createElement("g", {
1669
- transform: "translate(-86.019554,-58.032633)"
1670
- }, /*#__PURE__*/createElement("path", {
1671
- style: {
1672
- strokeWidth: 0.744756
1673
- },
1674
- d: "m 442.74023,219.33594 -117.62695,32.32422 54.71094,31.12304 c -21.99397,41.5931 -32.8507,84.88283 -38.33008,127.89649 -6.86182,50.94051 -5.95715,103.99765 20.23828,155.46484 5.97246,11.72776 13.65817,23.59773 24.38867,35.06641 2.6597,2.84073 5.65602,5.75455 9.12891,8.68164 0.87557,0.7378 1.85363,1.52609 2.95117,2.35547 0.29669,0.22563 0.63616,0.47742 1.02149,0.75586 l 0.58203,0.42578 34.57812,-15.12305 -0.33789,-0.2207 c -0.0265,-0.0151 -0.0842,-0.0587 -0.18359,-0.13086 -0.46723,-0.34885 -0.9819,-0.76796 -1.56055,-1.25 -2.29757,-1.91343 -4.46539,-4.04643 -6.64062,-6.33985 -8.80052,-9.27114 -15.30333,-19.4993 -20.83985,-30.13867 -24.42289,-46.90715 -24.77465,-97.03535 -18.58008,-146.68164 4.94388,-37.37493 13.65299,-74.4847 30.20508,-109.92969 l 58.6211,33.34766 z",
1675
- transform: "scale(0.26458333)"
1676
- })));
1677
- }
1692
+ /**
1693
+ * Adds a button that makes the map follow the users GPS position using
1694
+ * navigator.geolocation.watchPosition if activated
1695
+ *
1696
+ * @param {object} props
1697
+ * @param {string} props.mapId Id of the target MapLibre instance in mapContext
1698
+ *
1699
+ * @component
1700
+ */
1678
1701
 
1679
- var _g;
1702
+ var MlFollowGps = function MlFollowGps(props) {
1703
+ var mapHook = useMap({
1704
+ mapId: props.mapId,
1705
+ waitForLayer: props.insertBeforeLayer
1706
+ });
1680
1707
 
1681
- function _extends$1() { _extends$1 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$1.apply(this, arguments); }
1708
+ var _useState = useState(false),
1709
+ _useState2 = _slicedToArray(_useState, 2),
1710
+ isFollowed = _useState2[0],
1711
+ setIsFollowed = _useState2[1];
1682
1712
 
1683
- function SvgRotateLeft(props) {
1684
- return /*#__PURE__*/createElement("svg", _extends$1({
1685
- width: "39.675098mm",
1686
- height: "104.27064mm",
1687
- viewBox: "0 0 39.675098 104.27064"
1688
- }, props), _g || (_g = /*#__PURE__*/createElement("g", {
1689
- transform: "translate(-86.019554,-58.032633)"
1690
- }, /*#__PURE__*/createElement("path", {
1713
+ var _useState3 = useState(undefined),
1714
+ _useState4 = _slicedToArray(_useState3, 2),
1715
+ geoJson = _useState4[0],
1716
+ setGeoJson = _useState4[1];
1717
+
1718
+ var watchIdRef = useRef(undefined);
1719
+
1720
+ var _useState5 = useState(false),
1721
+ _useState6 = _slicedToArray(_useState5, 2),
1722
+ locationAccessDenied = _useState6[0],
1723
+ setLocationAccessDenied = _useState6[1];
1724
+
1725
+ var _useState7 = useState(),
1726
+ _useState8 = _slicedToArray(_useState7, 2),
1727
+ accuracyGeoJson = _useState8[0],
1728
+ setAccuracyGeoJson = _useState8[1];
1729
+
1730
+ useEffect(function () {
1731
+ return function () {
1732
+ if (watchIdRef.current) {
1733
+ navigator.geolocation.clearWatch(watchIdRef.current);
1734
+ watchIdRef.current = undefined;
1735
+ }
1736
+ };
1737
+ }, []);
1738
+ var getLocationSuccess = useCallback(function (pos) {
1739
+ if (!mapHook.map) return;
1740
+ mapHook.map.setCenter([pos.coords.longitude, pos.coords.latitude]);
1741
+ var geoJsonPoint = point([pos.coords.longitude, pos.coords.latitude]);
1742
+ setGeoJson(geoJsonPoint);
1743
+ setAccuracyGeoJson(circle(geoJsonPoint, pos.coords.accuracy / 1000));
1744
+ }, [mapHook.map]);
1745
+
1746
+ var getLocationError = function getLocationError(err) {
1747
+ console.log("Access of user location denied");
1748
+ setLocationAccessDenied(true);
1749
+ };
1750
+
1751
+ useEffect(function () {
1752
+ if (!mapHook.map) return;
1753
+
1754
+ if (isFollowed) {
1755
+ watchIdRef.current = navigator.geolocation.watchPosition(getLocationSuccess, getLocationError);
1756
+ } else {
1757
+ navigator.geolocation.clearWatch(watchIdRef.current);
1758
+ }
1759
+ }, [isFollowed, getLocationSuccess]);
1760
+ return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, isFollowed && geoJson && /*#__PURE__*/React__default.createElement(MlGeoJsonLayer, {
1761
+ geojson: accuracyGeoJson,
1762
+ type: "fill",
1763
+ paint: _objectSpread2({
1764
+ "fill-color": "#ee7700",
1765
+ "fill-opacity": 0.5
1766
+ }, props.accuracyPaint),
1767
+ insertBeforeLayer: "MlFollowGpsMarker"
1768
+ }), isFollowed && geoJson && /*#__PURE__*/React__default.createElement(MlImageMarkerLayer, {
1769
+ layerId: "MlFollowGpsMarker",
1770
+ options: {
1771
+ type: "symbol",
1772
+ source: {
1773
+ type: "geojson",
1774
+ data: geoJson
1775
+ },
1776
+ layout: _objectSpread2({
1777
+ "icon-size": 0.1,
1778
+ "icon-offset": [0, -340]
1779
+ }, props.markerLayout)
1780
+ },
1781
+ imgSrc: props.markerImage || marker
1782
+ }), /*#__PURE__*/React__default.createElement(Button, {
1783
+ sx: _objectSpread2({
1784
+ zIndex: 1002,
1785
+ color: isFollowed ? props.onColor : props.offColor
1786
+ }, props.style),
1787
+ disabled: locationAccessDenied,
1788
+ onClick: function onClick() {
1789
+ setIsFollowed(!isFollowed);
1790
+ }
1791
+ }, " ", /*#__PURE__*/React__default.createElement(RoomIcon, {
1792
+ sx: {
1793
+ fontSize: props.style.fontSize
1794
+ }
1795
+ }), " "));
1796
+ };
1797
+
1798
+ MlFollowGps.defaultProps = {
1799
+ mapId: undefined,
1800
+ style: {
1801
+ minWidth: "30px",
1802
+ minHeight: "30px",
1803
+ width: "30px",
1804
+ height: "30px",
1805
+ backgroundColor: "#414141",
1806
+ borderRadius: "23%",
1807
+ margin: 0.15,
1808
+ fontSize: "1.3em",
1809
+ ":hover": {
1810
+ backgroundColor: "#515151",
1811
+ color: "#ececec"
1812
+ }
1813
+ },
1814
+ onColor: "#ececec",
1815
+ offColor: "#666"
1816
+ };
1817
+ MlFollowGps.propTypes = {
1818
+ /**
1819
+ * Id of the target MapLibre instance in mapContext
1820
+ */
1821
+ mapId: PropTypes.string,
1822
+
1823
+ /**
1824
+ * CSS style object that is applied to the button component
1825
+ */
1826
+ style: PropTypes.object,
1827
+
1828
+ /**
1829
+ * Active button font color
1830
+ */
1831
+ onColor: PropTypes.string,
1832
+
1833
+ /**
1834
+ * Inactive button font color
1835
+ */
1836
+ offColor: PropTypes.string,
1837
+
1838
+ /**
1839
+ * Accuracy paint property object, that is passed to the MlGeoJsonLayer responsible for drawing the accuracy circle.
1840
+ * Use any available paint prop from layer type "fill".
1841
+ * https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#fill
1842
+ */
1843
+ accuracyPaint: PropTypes.object,
1844
+
1845
+ /**
1846
+ * Marker layout property object, that is passed to the MlImageMarkerLayer responsible for drawing the position marker.
1847
+ * Use any available layout property from layer type "symbol".
1848
+ * https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#symbol
1849
+ */
1850
+ markerLayout: PropTypes.object,
1851
+
1852
+ /**
1853
+ * Replace the default marker image with a custom one.
1854
+ */
1855
+ markerImage: PropTypes.string
1856
+ };
1857
+
1858
+ var nmMap = {
1859
+ street: ["footway", "street", "road", "street_name", "residential", "path", "pedestrian", "road_reference", "road_reference_intl", "square", "place"],
1860
+ number: ["house_number", "street_number"],
1861
+ place: ["city", "village", "hamlet", "locality", "croft", "neighbourhood", "suburb", "city_district", "district", "quarter", "borough", "city_block", "residential", "commercial", "industrial", "houses", "subdivision", "allotments", "postal_city", "town", "municipality", "local_administrative_area"],
1862
+ zip: ["postcode", "partial_postcode"],
1863
+ state: ["state", "province", "state_code"]
1864
+ };
1865
+
1866
+ var nmConverter = function nmConverter(nmAddress) {
1867
+ var addressArr = [];
1868
+
1869
+ for (var key in nmMap) {
1870
+ nmMap[key].some(function (element) {
1871
+ if (nmAddress.hasOwnProperty(element)) {
1872
+ addressArr.push(nmAddress[element]);
1873
+ return true;
1874
+ }
1875
+
1876
+ return false;
1877
+ });
1878
+ }
1879
+
1880
+ return addressArr.join(", ");
1881
+ };
1882
+
1883
+ var toPixels = function toPixels(length) {
1884
+ var conversionFactor = 96;
1885
+ conversionFactor /= 25.4;
1886
+ return conversionFactor * length + "px";
1887
+ };
1888
+
1889
+ var createPdf = function createPdf(map, locationValue, setLoading) {
1890
+ setLoading(true);
1891
+ var width = 210;
1892
+ var height = 297; // Calculate pixel ratio
1893
+
1894
+ var actualPixelRatio = window.devicePixelRatio; // Create map container
1895
+
1896
+ var hidden = document.createElement("div");
1897
+ hidden.className = "hidden-map";
1898
+ document.body.appendChild(hidden);
1899
+ var container = document.createElement("div");
1900
+ container.style.width = toPixels(width);
1901
+ container.style.height = toPixels(height);
1902
+ hidden.appendChild(container); //Render map
1903
+
1904
+ var renderMap = new maplibregl$1.Map({
1905
+ container: container,
1906
+ center: map.getCenter(),
1907
+ zoom: map.getZoom(),
1908
+ bearing: map.getBearing(),
1909
+ pitch: map.getPitch(),
1910
+ interactive: false,
1911
+ preserveDrawingBuffer: true,
1912
+ fadeDuration: 0,
1913
+ attributionControl: false
1914
+ });
1915
+ var style = map.getStyle();
1916
+
1917
+ var _loop = function _loop(name) {
1918
+ var src = style.sources[name];
1919
+ Object.keys(src).forEach(function (key) {
1920
+ //delete properties if value is undefined.
1921
+ // for instance, raster-dem might has undefined value in "url" and "bounds"
1922
+ if (!src[key]) {
1923
+ delete src[key];
1924
+ }
1925
+ });
1926
+ };
1927
+
1928
+ for (var name in style.sources) {
1929
+ _loop(name);
1930
+ }
1931
+
1932
+ renderMap.setStyle(style);
1933
+ renderMap.once("idle", function () {
1934
+ var _hidden$parentNode;
1935
+
1936
+ // TO DO: It is still under development
1937
+ var pdf = new jsPDF({
1938
+ orientation: "p",
1939
+ unit: "mm",
1940
+ compress: true
1941
+ });
1942
+ Object.defineProperty(window, "devicePixelRatio", {
1943
+ get: function get() {
1944
+ return 300 / 96;
1945
+ }
1946
+ });
1947
+ var offsetX = 2.5;
1948
+ var offsetY = 2.5;
1949
+ var marginTop = 3;
1950
+ var marginBottom = 3;
1951
+ var innerMargin = 2;
1952
+ var logo = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKgAAACxCAMAAABnTAbVAAAC8VBMVEUAAAD/AACAAACqAFW/AECZMzOqK1W2JEm/IECqHDmzGk25F0aqFUCxJzu2JEmqIkSvIEC0HjyqHEeuG0OzGkC2GD2uI0axIUO1IECtHz2xHUWzHEKtG0CwGj6zIkS1IUKyHz60HkSvHUKxHECzHD6uG0OxIUGzIECuH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HrdUk65cNgsh8wOhX4991GmFewVVs7nHTAiYil9tYO9Uuruh1F3n2GTONjr6dEwrnMevfrBXrEwwzGvig3GomXrvoP1HkQLJ6WV8II30OJ1XO0huQu/AwN3k5Vh+B1wpP3EIfhdCE2fhv+X/wF/AO+L9vuzfwAAAABJRU5ErkJggg==";
1953
+ var textBuffer = 1;
1954
+ var lineHeight = 3.25;
1955
+ var text = locationValue ? nmConverter(locationValue.address) : "";
1956
+ var textChunksSeperator = text.split(",");
1957
+ var textChunks = [];
1958
+
1959
+ if (textChunks.length) {
1960
+ textChunksSeperator.forEach(function (chunk) {
1961
+ var limitChunks = chunk.match(/.{1,34}/g);
1962
+ textChunks.push.apply(textChunks, _toConsumableArray(limitChunks));
1963
+ });
1964
+ } //Render map image
1965
+
1966
+
1967
+ pdf.addImage(renderMap.getCanvas().toDataURL("image/png"), "png", 0, 0, 210, 297, null, "FAST"); //Render lower left Copyright box
1968
+
1969
+ pdf.setFillColor("white");
1970
+ pdf.rect(138, 287, 297, 10, "F");
1971
+ pdf.setFontSize(10); // optional
1972
+
1973
+ pdf.text("Datenquelle: © OpenStreetMap-Mitwirkende", 140, pdf.internal.pageSize.height - 3); //Render infobox
1974
+
1975
+ pdf.setFillColor("white");
1976
+ var infoBoxSize = textChunks.length * lineHeight + marginTop + marginBottom + lineHeight * 2 + innerMargin * 2 + textBuffer;
1977
+ pdf.rect(offsetX, 2, 66.5, infoBoxSize, "F");
1978
+ pdf.setFontSize(10);
1979
+ pdf.text("Karten PDF:", 6, offsetY + marginTop); //Render inner infobox
1980
+
1981
+ pdf.rect(6, 7, 60, textChunks.length * lineHeight + innerMargin * 2 + textBuffer);
1982
+ pdf.setFontSize(10); //Write out address
1983
+
1984
+ textChunks.forEach(function (text, i) {
1985
+ pdf.text(text.trim(), 8, 10 + i * 3.5 + innerMargin);
1986
+ }); //Add WG Logo
1987
+
1988
+ pdf.addImage(logo, "png", 5, offsetY + marginTop + lineHeight * 2 + textChunks.length * 3 + innerMargin * 2, 3, 3, null, "FAST"); //Add WG Url
1989
+
1990
+ pdf.setFontSize(10);
1991
+ pdf.text("wheregroup.com", 40, offsetY + marginTop + lineHeight * 2 + textChunks.length * lineHeight + innerMargin * 2 + textBuffer); //Set pdfs props
1992
+
1993
+ pdf.setProperties({
1994
+ title: "Map export",
1995
+ subject: "Map export",
1996
+ creator: "WhereGroup GmbH",
1997
+ author: "(c)WhereGroup GmbH, (c)OpenStreetMap"
1998
+ });
1999
+ pdf.save("Map.pdf");
2000
+ renderMap.remove();
2001
+ (_hidden$parentNode = hidden.parentNode) === null || _hidden$parentNode === void 0 ? void 0 : _hidden$parentNode.removeChild(hidden);
2002
+ Object.defineProperty(window, "devicePixelRatio", {
2003
+ get: function get() {
2004
+ return actualPixelRatio;
2005
+ }
2006
+ });
2007
+ setLoading(false);
2008
+ });
2009
+ };
2010
+
2011
+ /**
2012
+ * Renders a button that will create a PDF version of the current map view (dimensions adjusted to fit Din A4 Paper).
2013
+ *
2014
+ * @component
2015
+ */
2016
+
2017
+ var MlCreatePdfButton = function MlCreatePdfButton(props) {
2018
+ var mapContext = useContext(MapContext);
2019
+ var initializedRef = useRef(false);
2020
+ var mapRef = useRef(undefined);
2021
+ useEffect(function () {
2022
+ if (!mapContext.mapExists(props.mapId) || initializedRef.current) return;
2023
+ initializedRef.current = true;
2024
+ mapRef.current = mapContext.getMap(props.mapId);
2025
+ }, [mapContext.mapIds, mapContext, props.mapId]);
2026
+ return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Button, {
2027
+ color: "primary",
2028
+ variant: "contained",
2029
+ onClick: function onClick() {
2030
+ createPdf(mapRef.current, null, function () {});
2031
+ }
2032
+ }, /*#__PURE__*/React__default.createElement(PrinterIcon, null)));
2033
+ };
2034
+
2035
+ MlCreatePdfButton.defaultProps = {
2036
+ mapId: undefined
2037
+ };
2038
+ MlCreatePdfButton.propTypes = {
2039
+ /**
2040
+ * Id of the target MapLibre instance in mapContext
2041
+ */
2042
+ mapId: PropTypes.string
2043
+ };
2044
+
2045
+ function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2046
+
2047
+ function SvgRotateRight(props) {
2048
+ return /*#__PURE__*/createElement("svg", _extends({
2049
+ width: "39.675098mm",
2050
+ height: "104.27064mm",
2051
+ viewBox: "0 0 39.675098 104.27064"
2052
+ }, props), /*#__PURE__*/createElement("g", {
2053
+ transform: "translate(-86.019554,-58.032633)"
2054
+ }, /*#__PURE__*/createElement("path", {
2055
+ style: {
2056
+ strokeWidth: 0.744756
2057
+ },
2058
+ d: "m 442.74023,219.33594 -117.62695,32.32422 54.71094,31.12304 c -21.99397,41.5931 -32.8507,84.88283 -38.33008,127.89649 -6.86182,50.94051 -5.95715,103.99765 20.23828,155.46484 5.97246,11.72776 13.65817,23.59773 24.38867,35.06641 2.6597,2.84073 5.65602,5.75455 9.12891,8.68164 0.87557,0.7378 1.85363,1.52609 2.95117,2.35547 0.29669,0.22563 0.63616,0.47742 1.02149,0.75586 l 0.58203,0.42578 34.57812,-15.12305 -0.33789,-0.2207 c -0.0265,-0.0151 -0.0842,-0.0587 -0.18359,-0.13086 -0.46723,-0.34885 -0.9819,-0.76796 -1.56055,-1.25 -2.29757,-1.91343 -4.46539,-4.04643 -6.64062,-6.33985 -8.80052,-9.27114 -15.30333,-19.4993 -20.83985,-30.13867 -24.42289,-46.90715 -24.77465,-97.03535 -18.58008,-146.68164 4.94388,-37.37493 13.65299,-74.4847 30.20508,-109.92969 l 58.6211,33.34766 z",
2059
+ transform: "scale(0.26458333)"
2060
+ })));
2061
+ }
2062
+
2063
+ var _g;
2064
+
2065
+ function _extends$1() { _extends$1 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$1.apply(this, arguments); }
2066
+
2067
+ function SvgRotateLeft(props) {
2068
+ return /*#__PURE__*/createElement("svg", _extends$1({
2069
+ width: "39.675098mm",
2070
+ height: "104.27064mm",
2071
+ viewBox: "0 0 39.675098 104.27064"
2072
+ }, props), _g || (_g = /*#__PURE__*/createElement("g", {
2073
+ transform: "translate(-86.019554,-58.032633)"
2074
+ }, /*#__PURE__*/createElement("path", {
1691
2075
  d: "m 94.572523,58.032633 31.122127,8.55245 -14.4756,8.234638 c 5.81924,11.004841 8.69175,22.458582 10.1415,33.839279 1.81552,13.47801 1.57616,27.51604 -5.35471,41.13341 -1.58021,3.10296 -3.61373,6.24356 -6.45284,9.27798 -0.70371,0.75161 -1.49649,1.52256 -2.41535,2.29702 -0.23167,0.19521 -0.49044,0.40378 -0.78083,0.62322 -0.0785,0.0597 -0.16832,0.12632 -0.27027,0.19999 l -0.154,0.11265 -9.148793,-4.00131 0.0894,-0.0584 c 0.007,-0.004 0.02228,-0.0155 0.04857,-0.0346 0.123621,-0.0923 0.259794,-0.20319 0.412895,-0.33073 0.607899,-0.50626 1.181468,-1.07062 1.756997,-1.67742 2.328481,-2.45299 4.049011,-5.15919 5.513881,-7.97419 6.46189,-12.41085 6.55496,-25.67394 4.91598,-38.80952 -1.30807,-9.888781 -3.61235,-19.707408 -7.99176,-29.085561 l -15.510171,8.823235 z"
1692
2076
  }))));
1693
2077
  }
@@ -1860,200 +2244,49 @@ var MlNavigationCompass = function MlNavigationCompass(props) {
1860
2244
  rest = 90 + rest;
1861
2245
  }
1862
2246
 
1863
- if (rest === 0) {
1864
- rest = 90;
1865
- }
1866
-
1867
- (_mapRef$current5 = mapRef.current) === null || _mapRef$current5 === void 0 ? void 0 : _mapRef$current5.setBearing(Math.round(bearing - Math.abs(rest)));
1868
- }
1869
- })))));
1870
- };
1871
-
1872
- MlNavigationCompass.propTypes = {
1873
- /**
1874
- * Component id prefix
1875
- */
1876
- idPrefix: PropTypes.string,
1877
-
1878
- /**
1879
- * Style object to adjust css definitions of the component.
1880
- */
1881
- style: PropTypes.object,
1882
-
1883
- /**
1884
- * Style object to adjust css definitions of the background.
1885
- */
1886
- backgroundStyle: PropTypes.object,
1887
-
1888
- /**
1889
- * Style object to adjust css definitions of the compass needle.
1890
- */
1891
- needleStyle: PropTypes.object,
1892
-
1893
- /**
1894
- * Style object to adjust css definitions of the rotate right button.
1895
- */
1896
- rotateRightStyle: PropTypes.object,
1897
-
1898
- /**
1899
- * Style object to adjust css definitions of the rotate left button.
1900
- */
1901
- rotateLeftStyle: PropTypes.object
1902
- };
1903
-
1904
- /**
1905
- * Adds a button that makes the map follow the users GPS position using
1906
- * navigator.geolocation.watchPosition if activated
1907
- *
1908
- * @param {object} props
1909
- * @param {string} props.mapId Id of the target MapLibre instance in mapContext
1910
- *
1911
- * @component
1912
- */
1913
-
1914
- var MlFollowGps = function MlFollowGps(props) {
1915
- // Use a useRef hook to reference the layer object to be able to access it later inside useEffect hooks
1916
- var mapContext = useContext(MapContext);
1917
-
1918
- var _useState = useState(false),
1919
- _useState2 = _slicedToArray(_useState, 2),
1920
- isFollowed = _useState2[0],
1921
- setIsFollowed = _useState2[1];
1922
-
1923
- var _useState3 = useState(undefined),
1924
- _useState4 = _slicedToArray(_useState3, 2),
1925
- geoJson = _useState4[0],
1926
- setGeoJson = _useState4[1];
1927
-
1928
- var watchIdRef = useRef(undefined);
1929
-
1930
- var _useState5 = useState(false),
1931
- _useState6 = _slicedToArray(_useState5, 2),
1932
- locationAccessDenied = _useState6[0],
1933
- setLocationAccessDenied = _useState6[1];
1934
-
1935
- var initializedRef = useRef(false);
1936
- var mapRef = useRef(undefined);
1937
- var componentId = useRef((props.idPrefix ? props.idPrefix : "MlFollowGps-") + v4());
1938
-
1939
- var _useState7 = useState(30),
1940
- _useState8 = _slicedToArray(_useState7, 2),
1941
- accuracyRadius = _useState8[0],
1942
- setAccuracyRadius = _useState8[1];
1943
-
1944
- useEffect(function () {
1945
- var _componentId = componentId.current;
1946
- return function () {
1947
- // This is the cleanup function, it is called when this react component is removed from react-dom
1948
- // try to remove anything this component has added to the MapLibre-gl instance
1949
- // e.g.: remove the layer
1950
- // mapContext.getMap(props.mapId).removeLayer(layerRef.current);
1951
- // check for the existence of map.style before calling getLayer or getSource
1952
- if (mapRef.current) {
1953
- mapRef.current.cleanup(_componentId);
1954
- mapRef.current = undefined;
1955
- }
1956
-
1957
- if (watchIdRef.current) {
1958
- initializedRef.current = false;
1959
- navigator.geolocation.clearWatch(watchIdRef.current);
1960
- watchIdRef.current = undefined;
1961
- }
1962
- };
1963
- }, []);
1964
- useEffect(function () {
1965
- if (!mapContext.mapExists(props.mapId) || initializedRef.current) return; // the MapLibre-gl instance (mapContext.getMap(props.mapId)) is accessible here
1966
- // initialize the layer and add it to the MapLibre-gl instance or do something else with it
1967
-
1968
- initializedRef.current = true;
1969
- mapRef.current = mapContext.getMap(props.mapId);
1970
- mapRef.current.setCenter([7.132122000552613, 50.716405378037706]);
1971
- }, [mapContext.mapIds, mapContext, props.mapId]);
1972
-
1973
- var getLocationSuccess = function getLocationSuccess(pos) {
1974
- if (!mapRef.current) return;
1975
- mapRef.current.setCenter([pos.coords.longitude, pos.coords.latitude]);
1976
- setAccuracyRadius(pos.coords.accuracy);
1977
- setGeoJson(point([pos.coords.longitude, pos.coords.latitude]));
1978
- };
1979
-
1980
- var getLocationError = function getLocationError(err) {
1981
- console.log("Access of user location denied");
1982
- setLocationAccessDenied(true);
1983
- };
1984
-
1985
- return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, isFollowed && geoJson && /*#__PURE__*/React__default.createElement(MlGeoJsonLayer, {
1986
- geojson: geoJson,
1987
- type: "circle",
1988
- paint: {
1989
- "circle-radius": {
1990
- stops: [[0, 0], [20, accuracyRadius / 0.075 / Math.cos(geoJson.geometry.coordinates[1] * Math.PI / 180)]],
1991
- base: 2
1992
- },
1993
- "circle-color": "#ee7700",
1994
- "circle-opacity": 0.5
1995
- }
1996
- }), isFollowed && geoJson && /*#__PURE__*/React__default.createElement(MlImageMarkerLayer, {
1997
- options: {
1998
- type: "symbol",
1999
- source: {
2000
- type: "geojson",
2001
- data: geoJson
2002
- },
2003
- layout: {
2004
- "icon-size": 0.1,
2005
- "icon-offset": [0, -340]
2006
- }
2007
- },
2008
- imgSrc: "/assets/marker.png"
2009
- }), /*#__PURE__*/React__default.createElement(Button, {
2010
- sx: _objectSpread2({
2011
- zIndex: 1002,
2012
- color: isFollowed ? "#bbb" : "#666"
2013
- }, props.style),
2014
- disabled: locationAccessDenied,
2015
- onClick: function onClick() {
2016
- if (isFollowed) {
2017
- navigator.geolocation.clearWatch(watchIdRef.current);
2018
- } else {
2019
- watchIdRef.current = navigator.geolocation.watchPosition(getLocationSuccess, getLocationError);
2020
- }
2021
-
2022
- setIsFollowed(!isFollowed);
2023
- }
2024
- }, " ", /*#__PURE__*/React__default.createElement(RoomIcon, {
2025
- sx: {}
2026
- }), " "));
2027
- };
2247
+ if (rest === 0) {
2248
+ rest = 90;
2249
+ }
2028
2250
 
2029
- MlFollowGps.defaultProps = {
2030
- mapId: undefined,
2031
- style: {
2032
- minWidth: "30px",
2033
- minHeight: "30px",
2034
- width: "30px",
2035
- height: "30px",
2036
- backgroundColor: "#414141",
2037
- borderRadius: "23%",
2038
- margin: 0.15,
2039
- ":hover": {
2040
- backgroundColor: "#515151",
2041
- color: "#ececec"
2251
+ (_mapRef$current5 = mapRef.current) === null || _mapRef$current5 === void 0 ? void 0 : _mapRef$current5.setBearing(Math.round(bearing - Math.abs(rest)));
2042
2252
  }
2043
- }
2253
+ })))));
2044
2254
  };
2045
- MlFollowGps.propTypes = {
2255
+
2256
+ MlNavigationCompass.propTypes = {
2046
2257
  /**
2047
- * Id of the target MapLibre instance in mapContext
2258
+ * Component id prefix
2048
2259
  */
2049
- mapId: PropTypes.string,
2260
+ idPrefix: PropTypes.string,
2050
2261
 
2051
2262
  /**
2052
- * CSS style object that is applied to the button component
2263
+ * Style object to adjust css definitions of the component.
2264
+ */
2265
+ style: PropTypes.object,
2266
+
2267
+ /**
2268
+ * Style object to adjust css definitions of the background.
2269
+ */
2270
+ backgroundStyle: PropTypes.object,
2271
+
2272
+ /**
2273
+ * Style object to adjust css definitions of the compass needle.
2274
+ */
2275
+ needleStyle: PropTypes.object,
2276
+
2277
+ /**
2278
+ * Style object to adjust css definitions of the rotate right button.
2053
2279
  */
2054
- style: PropTypes.object
2280
+ rotateRightStyle: PropTypes.object,
2281
+
2282
+ /**
2283
+ * Style object to adjust css definitions of the rotate left button.
2284
+ */
2285
+ rotateLeftStyle: PropTypes.object
2055
2286
  };
2056
2287
 
2288
+ var _excluded$1 = ["color"];
2289
+
2057
2290
  var MlNavigationTools = function MlNavigationTools(props) {
2058
2291
  var mapContext = useContext(MapContext);
2059
2292
  var initializedRef = useRef(false);
@@ -2070,21 +2303,22 @@ var MlNavigationTools = function MlNavigationTools(props) {
2070
2303
  locationAccessDenied = _useState4[0],
2071
2304
  setLocationAccessDenied = _useState4[1];
2072
2305
 
2306
+ var mediaIsMobile = useMediaQuery("(max-width:900px)");
2073
2307
  var buttonStyle = {
2074
- minWidth: "30px",
2075
- minHeight: "30px",
2076
- width: "30px",
2077
- height: "30px",
2078
- color: "#bbb",
2308
+ minWidth: "20px",
2309
+ minHeight: "20px",
2310
+ width: mediaIsMobile ? "50px" : "30px",
2311
+ height: mediaIsMobile ? "50px" : "30px",
2079
2312
  backgroundColor: "#414141",
2080
2313
  borderRadius: "23%",
2081
2314
  //border: "1px solid #bbb",
2082
2315
  //boxShadow: "0px 0px 4px rgba(0,0,0,.5)",
2083
2316
  margin: 0.15,
2317
+ fontSize: mediaIsMobile ? "1.5em" : "1.2em",
2084
2318
  ":hover": {
2085
- backgroundColor: "#515151",
2086
- color: "#ececec"
2087
- }
2319
+ backgroundColor: "#515151"
2320
+ },
2321
+ color: "#ececec"
2088
2322
  };
2089
2323
  useEffect(function () {
2090
2324
  var _componentId = componentId.current;
@@ -2164,8 +2398,8 @@ var MlNavigationTools = function MlNavigationTools(props) {
2164
2398
  style: {
2165
2399
  zIndex: 501,
2166
2400
  position: "absolute",
2167
- right: "20px",
2168
- bottom: "20px",
2401
+ right: mediaIsMobile ? "15px" : "5px",
2402
+ bottom: mediaIsMobile ? "40px" : "20px",
2169
2403
  display: "flex",
2170
2404
  flexDirection: "column"
2171
2405
  }
@@ -2173,15 +2407,15 @@ var MlNavigationTools = function MlNavigationTools(props) {
2173
2407
  style: {
2174
2408
  width: "31px",
2175
2409
  position: "relative",
2176
- height: "50px",
2177
- marginLeft: "-5px"
2410
+ height: mediaIsMobile ? "55px" : "45px",
2411
+ marginLeft: mediaIsMobile ? "3px" : "-5px",
2412
+ transform: mediaIsMobile ? "scale(1.6)" : "scale(1)"
2178
2413
  },
2179
2414
  backgroundStyle: {
2180
2415
  boxShadow: "0px 0px 18px rgba(0,0,0,.5)"
2181
2416
  }
2182
2417
  }), /*#__PURE__*/React__default.createElement(Button, {
2183
2418
  sx: _objectSpread2(_objectSpread2({}, buttonStyle), {}, {
2184
- fontSize: ".9em",
2185
2419
  fontWeight: 600
2186
2420
  }),
2187
2421
  onClick: adjustPitch
@@ -2191,15 +2425,22 @@ var MlNavigationTools = function MlNavigationTools(props) {
2191
2425
  disabled: locationAccessDenied
2192
2426
  }, /*#__PURE__*/React__default.createElement(GpsFixedIcon, {
2193
2427
  sx: {
2194
- width: ".9em"
2428
+ fontSize: mediaIsMobile ? "1.5em" : "1.2em"
2195
2429
  }
2196
- })), /*#__PURE__*/React__default.createElement(MlFollowGps, null), /*#__PURE__*/React__default.createElement(ButtonGroup, {
2430
+ })), /*#__PURE__*/React__default.createElement(MlFollowGps, {
2431
+ style: _objectSpread2({}, function (_ref) {
2432
+ var color = _ref.color,
2433
+ rest = _objectWithoutProperties(_ref, _excluded$1);
2434
+
2435
+ return rest;
2436
+ }(buttonStyle))
2437
+ }), /*#__PURE__*/React__default.createElement(ButtonGroup, {
2197
2438
  orientation: "vertical",
2198
2439
  sx: {
2199
- width: "30px",
2440
+ width: "50px",
2200
2441
  border: "none",
2201
2442
  Button: {
2202
- minWidth: "30px !important",
2443
+ minWidth: "20px !important",
2203
2444
  border: "none",
2204
2445
  padding: 0
2205
2446
  },
@@ -2208,22 +2449,42 @@ var MlNavigationTools = function MlNavigationTools(props) {
2208
2449
  }
2209
2450
  }
2210
2451
  }, /*#__PURE__*/React__default.createElement(Button, {
2211
- sx: buttonStyle,
2452
+ sx: _objectSpread2(_objectSpread2({}, buttonStyle), {}, {
2453
+ color: "#ececec"
2454
+ }),
2212
2455
  onClick: zoomIn
2213
- }, /*#__PURE__*/React__default.createElement(ControlPointIcon, null)), /*#__PURE__*/React__default.createElement(Button, {
2214
- sx: buttonStyle,
2456
+ }, /*#__PURE__*/React__default.createElement(ControlPointIcon, {
2457
+ sx: {
2458
+ fontSize: mediaIsMobile ? "1.5em" : "1.2em"
2459
+ }
2460
+ })), /*#__PURE__*/React__default.createElement(Button, {
2461
+ sx: _objectSpread2(_objectSpread2({}, buttonStyle), {}, {
2462
+ color: "#ececec"
2463
+ }),
2215
2464
  onClick: zoomOut
2216
- }, /*#__PURE__*/React__default.createElement(RemoveCircleOutlineIcon, null))));
2465
+ }, /*#__PURE__*/React__default.createElement(RemoveCircleOutlineIcon, {
2466
+ sx: {
2467
+ fontSize: mediaIsMobile ? "1.5em" : "1.2em"
2468
+ }
2469
+ }))));
2217
2470
  };
2218
2471
 
2219
2472
  var MlLayer = function MlLayer(props) {
2220
2473
  // Use a useRef hook to reference the layer object to be able to access it later inside useEffect hooks
2221
2474
  var mapContext = useContext(MapContext);
2475
+ var mapState = useMapState({
2476
+ mapId: props.mapId,
2477
+ watch: {
2478
+ viewport: false,
2479
+ layers: true,
2480
+ sources: false
2481
+ }
2482
+ });
2222
2483
  var layerInitializedRef = useRef(false);
2223
2484
  var mapRef = useRef(null);
2224
2485
  var componentId = useRef((props.layerId ? props.layerId : "MlLayer-") + v4());
2225
2486
  var idSuffixRef = useRef(props.idSuffix || new Date().getTime());
2226
- var layerId = (props.layerId || "MlLayer-") + idSuffixRef.current;
2487
+ var layerId = useRef(props.layerId || componentId.current);
2227
2488
  var layerPaintConfRef = useRef(undefined);
2228
2489
  var layerLayoutConfRef = useRef(undefined);
2229
2490
  useEffect(function () {
@@ -2263,6 +2524,22 @@ var MlLayer = function MlLayer(props) {
2263
2524
  useEffect(function () {
2264
2525
  if (!mapContext.mapExists(props.mapId) || layerInitializedRef.current) return; // the MapLibre-gl instance (mapContext.map) is accessible here
2265
2526
  // initialize the layer and add it to the MapLibre-gl instance or do something else with it
2527
+ //check if insertBeforeLayer exists
2528
+
2529
+ if (props.insertBeforeLayer) {
2530
+ var _mapState$layers;
2531
+
2532
+ var layerFound = false;
2533
+ mapState === null || mapState === void 0 ? void 0 : (_mapState$layers = mapState.layers) === null || _mapState$layers === void 0 ? void 0 : _mapState$layers.forEach(function (layer) {
2534
+ if (layer.id === props.insertBeforeLayer) {
2535
+ layerFound = true;
2536
+ }
2537
+ });
2538
+
2539
+ if (!layerFound) {
2540
+ return;
2541
+ }
2542
+ }
2266
2543
 
2267
2544
  mapRef.current = mapContext.getMap(props.mapId);
2268
2545
 
@@ -2271,7 +2548,7 @@ var MlLayer = function MlLayer(props) {
2271
2548
 
2272
2549
  layerInitializedRef.current = true;
2273
2550
  mapRef.current.addLayer(_objectSpread2({
2274
- id: layerId,
2551
+ id: layerId.current,
2275
2552
  type: "background",
2276
2553
  paint: {
2277
2554
  "background-color": "rgba(0,0,0,0)"
@@ -2280,7 +2557,7 @@ var MlLayer = function MlLayer(props) {
2280
2557
  layerPaintConfRef.current = JSON.stringify((_props$options = props.options) === null || _props$options === void 0 ? void 0 : _props$options.paint);
2281
2558
  layerLayoutConfRef.current = JSON.stringify((_props$options2 = props.options) === null || _props$options2 === void 0 ? void 0 : _props$options2.layout);
2282
2559
  }
2283
- }, [mapContext.mapIds, mapContext, props, layerId]);
2560
+ }, [mapContext.mapIds, mapContext, props, mapState.layers]);
2284
2561
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null);
2285
2562
  };
2286
2563
 
@@ -2537,7 +2814,7 @@ var defaultProps = {
2537
2814
 
2538
2815
  var MlWmsLayer = function MlWmsLayer(props) {
2539
2816
  var mapContext = useContext(MapContext);
2540
- var componentId = useRef((props.idPrefix ? props.idPrefix : "MlWmsLayer-") + v4());
2817
+ var componentId = useRef(props.layerId || "MlWmsLayer-" + v4());
2541
2818
  var mapRef = useRef(null);
2542
2819
  var initializedRef = useRef(false);
2543
2820
  var layerId = useRef(props.layerId || componentId.current);
@@ -4143,7 +4420,7 @@ var MlLayerMagnify = function MlLayerMagnify(props) {
4143
4420
  return false;
4144
4421
  }
4145
4422
 
4146
- if (!mapContext.mapExists(props.map1Id) || !mapContext.mapExists(props.map2Id)) {
4423
+ if (!mapContext.getMap(props.map1Id) || !mapContext.getMap(props.map2Id)) {
4147
4424
  return false;
4148
4425
  }
4149
4426
 
@@ -4188,7 +4465,7 @@ var MlLayerMagnify = function MlLayerMagnify(props) {
4188
4465
  useEffect(function () {
4189
4466
  if (!mapExists() || syncMoveInitializedRef.current) return;
4190
4467
  syncMoveInitializedRef.current = true;
4191
- syncCleanupFunctionRef.current = syncMove(mapContext.getMap(props.map1Id), mapContext.getMap(props.map2Id));
4468
+ syncCleanupFunctionRef.current = syncMove(mapContext.getMap(props.map1Id).map, mapContext.getMap(props.map2Id).map);
4192
4469
 
4193
4470
  if (mapContext.maps[props.map1Id].getCanvas().clientWidth > mapContext.maps[props.map1Id].getCanvas().clientHeight && magnifierRadiusRef.current * 2 > mapContext.maps[props.map1Id].getCanvas().clientHeight) {
4194
4471
  magnifierRadiusRef.current = Math.floor(mapContext.maps[props.map1Id].getCanvas().clientHeight / 2);
@@ -4300,7 +4577,7 @@ var MlLayerSwipe = function MlLayerSwipe(props) {
4300
4577
  return false;
4301
4578
  }
4302
4579
 
4303
- if (!mapContext.mapExists(props.map1Id) || !mapContext.mapExists(props.map2Id)) {
4580
+ if (!mapContext.getMap(props.map1Id) || !mapContext.getMap(props.map2Id)) {
4304
4581
  return false;
4305
4582
  }
4306
4583
 
@@ -4333,7 +4610,7 @@ var MlLayerSwipe = function MlLayerSwipe(props) {
4333
4610
  useEffect(function () {
4334
4611
  if (!mapExists() || initializedRef.current) return;
4335
4612
  initializedRef.current = true;
4336
- syncCleanupFunctionRef.current = syncMove(mapContext.getMap(props.map1Id), mapContext.getMap(props.map2Id));
4613
+ syncCleanupFunctionRef.current = syncMove(mapContext.getMap(props.map1Id).map, mapContext.getMap(props.map2Id).map);
4337
4614
  onMove({
4338
4615
  clientX: mapContext.maps[props.map1Id].getCanvas().clientWidth / 2
4339
4616
  });
@@ -4399,6 +4676,19 @@ MlLayerSwipe.propTypes = {
4399
4676
  var GeoJsonContext = /*#__PURE__*/React__default.createContext({});
4400
4677
  var GeoJsonContextProvider = GeoJsonContext.Provider;
4401
4678
 
4679
+ /**
4680
+ * https://github.com/mapbox/togeojson
4681
+ *
4682
+ * Copyright (c) 2016 Mapbox All rights reserved.
4683
+ *
4684
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4685
+ *
4686
+ * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
4687
+ *
4688
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
4689
+ *
4690
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4691
+ */
4402
4692
  var toGeoJSON = function () {
4403
4693
  var removeSpace = /\s*/g,
4404
4694
  trimSpace = /^\s*|\s*$/g,
@@ -5039,6 +5329,7 @@ var MlGPXViewer = function MlGPXViewer(props) {
5039
5329
  setMetaData = _useState6[1];
5040
5330
 
5041
5331
  var fileupload = useRef(null);
5332
+ var mediaIsMobile = useMediaQuery("(max-width:900px)");
5042
5333
  var popup = useRef(new Popup({
5043
5334
  closeButton: false,
5044
5335
  closeOnClick: true
@@ -5236,14 +5527,20 @@ var MlGPXViewer = function MlGPXViewer(props) {
5236
5527
  fileupload.current.click();
5237
5528
  };
5238
5529
 
5239
- return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(IconButton, {
5240
- onClick: manualUpload,
5530
+ return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("div", {
5241
5531
  style: {
5242
- position: "absolute",
5532
+ position: "fixed",
5243
5533
  right: "5px",
5244
- bottom: "75px",
5245
- backgroundColor: "rgba(255,255,255,1)",
5534
+ bottom: mediaIsMobile ? "40px" : "25px",
5535
+ display: "flex",
5536
+ flexDirection: "column",
5537
+ gap: "5px",
5246
5538
  zIndex: 1000
5539
+ }
5540
+ }, /*#__PURE__*/React__default.createElement(IconButton, {
5541
+ onClick: manualUpload,
5542
+ style: {
5543
+ backgroundColor: "rgba(255,255,255,1)"
5247
5544
  },
5248
5545
  size: "large"
5249
5546
  }, /*#__PURE__*/React__default.createElement("input", {
@@ -5258,14 +5555,10 @@ var MlGPXViewer = function MlGPXViewer(props) {
5258
5555
  }), /*#__PURE__*/React__default.createElement(FileCopy, null)), /*#__PURE__*/React__default.createElement(IconButton, {
5259
5556
  onClick: toogleDrawer,
5260
5557
  style: {
5261
- position: "absolute",
5262
- right: "5px",
5263
- bottom: "25px",
5264
- backgroundColor: "rgba(255,255,255,1)",
5265
- zIndex: 1000
5558
+ backgroundColor: "rgba(255,255,255,1)"
5266
5559
  },
5267
5560
  size: "large"
5268
- }, /*#__PURE__*/React__default.createElement(InfoIcon, null)), /*#__PURE__*/React__default.createElement(Drawer, {
5561
+ }, /*#__PURE__*/React__default.createElement(InfoIcon, null))), /*#__PURE__*/React__default.createElement(Drawer, {
5269
5562
  variant: "persistent",
5270
5563
  anchor: "left",
5271
5564
  open: open
@@ -5366,165 +5659,138 @@ GeoJsonProvider.propTypes = {
5366
5659
  };
5367
5660
 
5368
5661
  /**
5369
- * React hook that allows subscribing to map state changes
5662
+ * MlSpatialElevationProfile returns a Button that will add a standard OSM tile layer to the maplibre-gl instance.
5370
5663
  *
5371
5664
  * @component
5372
5665
  */
5373
5666
 
5374
- function useMapState(props) {
5375
- // Use a useRef hook to reference the layer object to be able to access it later inside useEffect hooks
5667
+ var MlSpatialElevationProfile = function MlSpatialElevationProfile(props) {
5376
5668
  var mapContext = useContext(MapContext);
5669
+ var componentId = useRef((props.idPrefix ? props.idPrefix : "MlSpatialElevationProfile-") + v4());
5670
+ var mapRef = useRef(null);
5377
5671
  var initializedRef = useRef(false);
5378
- var mapRef = useRef(undefined);
5379
-
5380
- var _useState = useState(undefined),
5381
- _useState2 = _slicedToArray(_useState, 2),
5382
- center = _useState2[0],
5383
- setCenter = _useState2[1];
5384
-
5385
- var _useState3 = useState(undefined),
5386
- _useState4 = _slicedToArray(_useState3, 2),
5387
- viewport = _useState4[0],
5388
- setViewport = _useState4[1];
5389
-
5390
- var viewportRef = useRef(undefined);
5391
-
5392
- var _useState5 = useState(undefined),
5393
- _useState6 = _slicedToArray(_useState5, 2),
5394
- layers = _useState6[0],
5395
- setLayers = _useState6[1];
5396
-
5397
- var layersRef = useRef(undefined); //const mapRef = useRef(props.map);
5398
-
5399
- var componentId = useRef(v4());
5400
- /**
5401
- * returns the element if it matches the defined filter criteria
5402
- * to be used as filter function on the layers array
5403
- *
5404
- * @param {object} layer
5405
- */
5406
-
5407
- var layerIdFilter = useCallback(function (layer) {
5408
- if (!props.filter.includeBaseLayers && layer.baseLayer) {
5409
- return false;
5410
- }
5411
-
5412
- if (typeof props.filter.matchLayerIds !== "undefined") {
5413
- if (props.filter.matchLayerIds instanceof RegExp) {
5414
- return props.filter.matchLayerIds.test(layer.id);
5415
- } else {
5416
- return layer.id.includes(props.filter.matchLayerIds);
5417
- }
5418
- }
5419
-
5420
- return true;
5421
- }, [props.filter]);
5422
- var refreshLayerState = useCallback(function () {
5423
- var _layerState = mapRef.current.wrapper.layerState.filter(layerIdFilter);
5424
-
5425
- var _layerStateString = JSON.stringify(_layerState);
5426
-
5427
- if (layersRef.current !== _layerStateString) {
5428
- layersRef.current = _layerStateString;
5429
- setLayers(_layerState);
5430
- }
5431
- }, [layerIdFilter]);
5672
+ var dataSource = useContext(GeoJsonContext);
5673
+ var sourceName = useRef("elevationprofile-" + v4());
5674
+ var layerName = useRef("elevationprofile-layer-" + v4());
5675
+ var createStep = useCallback(function (x, y, z, x2, y2) {
5676
+ //const summand = 0.0002;
5677
+ var line = lineString$1([[x, y], [x2, y2]]);
5678
+ var offsetLine = lineOffset(line, 5, {
5679
+ units: "meters"
5680
+ });
5681
+ var x3 = offsetLine.geometry.coordinates[0][0];
5682
+ var y3 = offsetLine.geometry.coordinates[0][1];
5683
+ var x4 = offsetLine.geometry.coordinates[1][0];
5684
+ var y4 = offsetLine.geometry.coordinates[1][1];
5685
+ return polygon([[[x, y], [x2, y2], [x4, y4], [x3, y3], [x, y]]], {
5686
+ height: z * props.elevationFactor
5687
+ });
5688
+ }, [props.elevationFactor]);
5432
5689
  useEffect(function () {
5433
5690
  var _componentId = componentId.current;
5434
5691
  return function () {
5692
+ // This is the cleanup function, it is called when this react component is removed from react-dom
5435
5693
  if (mapRef.current) {
5436
5694
  mapRef.current.cleanup(_componentId);
5437
- mapRef.current = undefined;
5695
+ mapRef.current = null;
5438
5696
  }
5439
-
5440
- initializedRef.current = false;
5441
5697
  };
5442
5698
  }, []);
5443
5699
  useEffect(function () {
5444
- var _props$watch, _props$watch2;
5445
-
5446
- if (!mapContext.mapExists(props.mapId) || initializedRef.current) return; // the MapLibre-gl instance (mapContext.getMap(props.mapId)) is accessible here
5447
- // initialize the layer and add it to the MapLibre-gl instance or do something else with it
5448
-
5700
+ if (!mapContext.mapExists(props.mapId) || initializedRef.current) return;
5449
5701
  initializedRef.current = true;
5450
5702
  mapRef.current = mapContext.getMap(props.mapId);
5451
- /*
5452
- mapRef.current.on(
5453
- "move",
5454
- () => {
5455
- setCenter(mapRef.current.getCenter());
5456
- },
5457
- componentId.current
5458
- );
5459
- */
5703
+ mapRef.current.addSource(sourceName.current, {
5704
+ type: "geojson",
5705
+ data: dataSource.data
5706
+ }, componentId.current);
5707
+ mapRef.current.addLayer({
5708
+ id: layerName.current,
5709
+ source: sourceName.current,
5710
+ type: "fill-extrusion",
5711
+ paint: {
5712
+ "fill-extrusion-height": ["get", "height"],
5713
+ "fill-extrusion-opacity": 0.9,
5714
+ "fill-extrusion-color": ["interpolate", ["linear"], ["get", "height"], 0, "rgba(0, 0, 255, 0)", 0.1, "royalblue", 0.3, "cyan", 0.5, "lime", 0.7, "yellow", 1, "yellow"]
5715
+ }
5716
+ }, props.insertBeforeLayer, componentId.current);
5717
+ }, [mapContext.mapIds, props.insertBeforeLayer, props.mapId, dataSource, mapContext]);
5718
+ useEffect(function () {
5719
+ var _mapRef$current$getSo;
5460
5720
 
5461
- if (props !== null && props !== void 0 && (_props$watch = props.watch) !== null && _props$watch !== void 0 && _props$watch.viewport) {
5462
- setViewport(mapRef.current.wrapper.viewportState);
5463
- mapRef.current.wrapper.on("viewportchange", function () {
5464
- var _mapRef$current;
5721
+ if (!mapRef.current || !mapRef.current.getLayer(layerName.current)) return;
5722
+ var data = dataSource.data;
5723
+ if (!data || !data.features) return;
5724
+ var line = data.features.find(function (element) {
5725
+ return element.geometry.type === "LineString";
5726
+ });
5727
+ if (!line || !line.geometry) return;
5728
+ var heights = line.geometry.coordinates.map(function (coordinate, index) {
5729
+ return coordinate[2];
5730
+ });
5731
+ var min = Math.min.apply(Math, _toConsumableArray(heights));
5732
+ var max = Math.max.apply(Math, _toConsumableArray(heights)) - min;
5733
+ max = max === 0 ? 1 : max;
5734
+ mapRef.current.setPaintProperty(layerName.current, "fill-extrusion-color", ["interpolate", ["linear"], ["get", "height"], 0, "rgb(0,255,55)", max * props.elevationFactor, "rgb(255,0,0)"]);
5465
5735
 
5466
- if (viewportRef.current !== ((_mapRef$current = mapRef.current) === null || _mapRef$current === void 0 ? void 0 : _mapRef$current.wrapper.viewportStateString)) {
5467
- var _mapRef$current2, _mapRef$current3, _mapRef$current3$wrap;
5736
+ var lerp = function lerp(x, y, a) {
5737
+ return x * (1 - a) + y * a;
5738
+ };
5468
5739
 
5469
- setViewport((_mapRef$current2 = mapRef.current) === null || _mapRef$current2 === void 0 ? void 0 : _mapRef$current2.wrapper.viewportState);
5470
- setCenter((_mapRef$current3 = mapRef.current) === null || _mapRef$current3 === void 0 ? void 0 : (_mapRef$current3$wrap = _mapRef$current3.wrapper.viewportState) === null || _mapRef$current3$wrap === void 0 ? void 0 : _mapRef$current3$wrap.center);
5740
+ var points = [];
5741
+ line.geometry.coordinates.forEach(function (coordinate, index) {
5742
+ //const point = createPoint(coordinate[0],coordinate[1],coordinate[2]-min);
5743
+ //points.push(point);
5744
+ if (line.geometry.coordinates[index + 1]) {
5745
+ var wayLength = distance([coordinate[0], coordinate[1]], [line.geometry.coordinates[index + 1][0], line.geometry.coordinates[index + 1][1]], {
5746
+ units: "kilometers"
5747
+ });
5748
+ var listLength = ~~(wayLength * 1000 / 10);
5749
+ listLength = listLength < 1 ? 1 : listLength;
5750
+
5751
+ for (var i = 0; i < listLength; i++) {
5752
+ var x = lerp(line.geometry.coordinates[index][0], line.geometry.coordinates[index + 1][0], i / listLength);
5753
+ var y = lerp(line.geometry.coordinates[index][1], line.geometry.coordinates[index + 1][1], i / listLength);
5754
+ var z = lerp(line.geometry.coordinates[index][2] - min, line.geometry.coordinates[index + 1][2] - min, i / listLength);
5755
+ var x2 = lerp(line.geometry.coordinates[index][0], line.geometry.coordinates[index + 1][0], (i + 1) / listLength);
5756
+ var y2 = lerp(line.geometry.coordinates[index][1], line.geometry.coordinates[index + 1][1], (i + 1) / listLength);
5757
+ var point = createStep(x, y, z, x2, y2);
5758
+ points.push(point);
5471
5759
  }
5472
- }, componentId.current);
5473
- }
5474
-
5475
- if (props !== null && props !== void 0 && (_props$watch2 = props.watch) !== null && _props$watch2 !== void 0 && _props$watch2.layers) {
5476
- var _props$filter, _props$filter2;
5477
-
5478
- refreshLayerState();
5479
- mapRef.current.wrapper.on("layerchange", refreshLayerState, {
5480
- includeBaseLayers: props === null || props === void 0 ? void 0 : (_props$filter = props.filter) === null || _props$filter === void 0 ? void 0 : _props$filter.includeBaseLayers,
5481
- matchLayerIds: props === null || props === void 0 ? void 0 : (_props$filter2 = props.filter) === null || _props$filter2 === void 0 ? void 0 : _props$filter2.matchLayerIds
5482
- }, componentId.current);
5483
- }
5484
- }, [mapContext.mapIds, mapContext, props.mapId, refreshLayerState]);
5485
- return {
5486
- layers: layers,
5487
- viewport: viewport
5488
- };
5489
- }
5760
+ }
5761
+ });
5762
+ var newData = dataSource.getEmptyFeatureCollection();
5763
+ newData.features = points;
5764
+ (_mapRef$current$getSo = mapRef.current.getSource(sourceName.current)) === null || _mapRef$current$getSo === void 0 ? void 0 : _mapRef$current$getSo.setData(newData);
5765
+ }, [dataSource.data, createStep, dataSource, props.elevationFactor, mapContext]);
5766
+ return /*#__PURE__*/React__default.createElement(React__default.Fragment, null);
5767
+ };
5490
5768
 
5491
- useMapState.defaultProps = {
5492
- mapId: undefined,
5493
- watch: {
5494
- layers: true,
5495
- sources: false,
5496
- viewport: false
5497
- },
5498
- filter: {
5499
- includeBaseLayers: false
5500
- }
5769
+ MlSpatialElevationProfile.defaultProps = {
5770
+ elevationFactor: 1
5501
5771
  };
5502
- useMapState.propTypes = {
5772
+ MlSpatialElevationProfile.propTypes = {
5503
5773
  /**
5504
5774
  * Id of the target MapLibre instance in mapContext
5505
5775
  */
5506
5776
  mapId: PropTypes.string,
5507
5777
 
5508
5778
  /**
5509
- * Defines map Resources to watch
5779
+ * Prefix of the component id this component uses when adding elements to the MapLibreGl-instance
5510
5780
  */
5511
- watch: PropTypes.shape({
5512
- layers: PropTypes.bool,
5513
- sources: PropTypes.bool,
5514
- viewport: PropTypes.bool
5515
- }),
5781
+ idPrefix: PropTypes.string,
5516
5782
 
5517
5783
  /**
5518
- * Filter string or RegExp to more explicitly define the elements watched and increase performance
5519
- * strings will be matched using layerId.includes(matchString)
5520
- * RegExps will be matched using matchRegExp.test(layerId)
5784
+ * Number describes the factor of the height of the elevation
5521
5785
  */
5522
- filter: PropTypes.shape({
5523
- includeBaseLayers: PropTypes.bool,
5524
- matchLayerIds: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(RegExp)]),
5525
- matchSourceIds: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(RegExp)])
5526
- })
5786
+ elevationFactor: PropTypes.number,
5787
+
5788
+ /**
5789
+ * The layerId of an existing layer this layer should be rendered visually beneath
5790
+ * https://maplibre.org/maplibre-gl-js-docs/api/map/#map#addlayer - see "beforeId" property
5791
+ */
5792
+ insertBeforeLayer: PropTypes.string
5527
5793
  };
5528
5794
 
5529
- export { GeoJsonContext, GeoJsonProvider, MapLibreMap, MlBasicComponent, MlComponentTemplate, MlCreatePdfButton, MlFeatureEditor, MlFillExtrusionLayer, MlGPXViewer, MlGeoJsonLayer, MlImageMarkerLayer, MlLayer, MlLayerMagnify, MlLayerSwipe, MlNavigationCompass, MlNavigationTools, MlOsmLayer, MlVectorTileLayer, MlWmsLayer, useMapState };
5795
+ export { GeoJsonContext, GeoJsonProvider, MapLibreMap, MlBasicComponent, MlComponentTemplate, MlCreatePdfButton, MlFeatureEditor, MlFillExtrusionLayer, MlFollowGps, MlGPXViewer, MlGeoJsonLayer, MlImageMarkerLayer, MlLayer, MlLayerMagnify, MlLayerSwipe, MlNavigationCompass, MlNavigationTools, MlOsmLayer, MlSpatialElevationProfile, MlVectorTileLayer, MlWmsLayer, useMap, useMapState };
5530
5796
  //# sourceMappingURL=index.esm.js.map