@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
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
 
3
- import { MapContext } from "@mapcomponents/react-core";
4
- import { useEffect, useRef, useContext, useState } from "react";
3
+ import {MapContext} from "@mapcomponents/react-core";
4
+ import {useEffect, useRef, useContext, useState} from "react";
5
5
  import Button from "@mui/material/Button";
6
6
  import ButtonGroup from "@mui/material/ButtonGroup";
7
7
  import ControlPointIcon from "@mui/icons-material/ControlPoint";
@@ -9,10 +9,11 @@ import RemoveCircleOutlineIcon from "@mui/icons-material/RemoveCircleOutline";
9
9
  //import ZoomOutIcon from "@mui/icons-material/ZoomOut";
10
10
  //import ZoomInIcon from "@mui/icons-material/ZoomIn";
11
11
  import GpsFixedIcon from "@mui/icons-material/GpsFixed";
12
- import { v4 as uuidv4 } from "uuid";
12
+ import {v4 as uuidv4} from "uuid";
13
13
 
14
14
  import MlNavigationCompass from "../MlNavigationCompass/MlNavigationCompass";
15
15
  import MlFollowGps from "../MlFollowGps/MlFollowGps";
16
+ import useMediaQuery from "@mui/material/useMediaQuery";
16
17
 
17
18
  const MlNavigationTools = (props) => {
18
19
  const mapContext = useContext(MapContext);
@@ -22,21 +23,22 @@ const MlNavigationTools = (props) => {
22
23
 
23
24
  const [pitch, setPitch] = useState(0);
24
25
  const [locationAccessDenied, setLocationAccessDenied] = useState(false);
26
+ const mediaIsMobile = useMediaQuery("(max-width:900px)");
25
27
  const buttonStyle = {
26
- minWidth: "30px",
27
- minHeight: "30px",
28
- width: "30px",
29
- height: "30px",
30
- color: "#bbb",
28
+ minWidth: "20px",
29
+ minHeight: "20px",
30
+ width: mediaIsMobile ? "50px" : "30px",
31
+ height: mediaIsMobile ? "50px" : "30px",
31
32
  backgroundColor: "#414141",
32
33
  borderRadius: "23%",
33
34
  //border: "1px solid #bbb",
34
35
  //boxShadow: "0px 0px 4px rgba(0,0,0,.5)",
35
36
  margin: 0.15,
37
+ fontSize: mediaIsMobile ? "1.5em" : "1.2em",
36
38
  ":hover": {
37
39
  backgroundColor: "#515151",
38
- color: "#ececec",
39
40
  },
41
+ color: "#ececec"
40
42
  };
41
43
 
42
44
  useEffect(() => {
@@ -77,7 +79,7 @@ const MlNavigationTools = (props) => {
77
79
  if (!mapRef.current) return;
78
80
 
79
81
  if (mapRef.current.transform._zoom + 0.5 <= mapRef.current.transform._maxZoom) {
80
- mapRef.current.easeTo({ zoom: mapRef.current.transform._zoom + 0.5 });
82
+ mapRef.current.easeTo({zoom: mapRef.current.transform._zoom + 0.5});
81
83
  }
82
84
  };
83
85
 
@@ -85,7 +87,7 @@ const MlNavigationTools = (props) => {
85
87
  if (!mapRef.current) return;
86
88
 
87
89
  if (mapRef.current.transform._zoom - 0.5 >= mapRef.current.transform._minZoom) {
88
- mapRef.current.easeTo({ zoom: mapRef.current.transform._zoom - 0.5 });
90
+ mapRef.current.easeTo({zoom: mapRef.current.transform._zoom - 0.5});
89
91
  }
90
92
  };
91
93
 
@@ -96,7 +98,7 @@ const MlNavigationTools = (props) => {
96
98
  if (mapRef.current.getPitch() !== 0) {
97
99
  targetPitch = 0;
98
100
  }
99
- mapRef.current.easeTo({ pitch: targetPitch });
101
+ mapRef.current.easeTo({pitch: targetPitch});
100
102
  };
101
103
 
102
104
  const moveToCurrentLocation = () => {
@@ -117,8 +119,8 @@ const MlNavigationTools = (props) => {
117
119
  style={{
118
120
  zIndex: 501,
119
121
  position: "absolute",
120
- right: "20px",
121
- bottom: "20px",
122
+ right: mediaIsMobile ? "15px" : "5px",
123
+ bottom: mediaIsMobile ? "40px" : "20px",
122
124
  display: "flex",
123
125
  flexDirection: "column",
124
126
  }}
@@ -127,34 +129,35 @@ const MlNavigationTools = (props) => {
127
129
  style={{
128
130
  width: "31px",
129
131
  position: "relative",
130
- height: "50px",
131
- marginLeft: "-5px",
132
+ height: mediaIsMobile ? "55px" : "45px",
133
+ marginLeft: mediaIsMobile ? "3px" : "-5px",
134
+ transform: mediaIsMobile ? "scale(1.6)" : "scale(1)"
132
135
  }}
133
136
  backgroundStyle={{
134
137
  boxShadow: "0px 0px 18px rgba(0,0,0,.5)",
135
138
  }}
136
139
  />
137
- <Button sx={{ ...buttonStyle, fontSize: ".9em", fontWeight: 600 }} onClick={adjustPitch}>
140
+ <Button sx={{...buttonStyle, fontWeight: 600}} onClick={adjustPitch}>
138
141
  {pitch ? "2D" : "3D"}
139
142
  </Button>
140
143
  <Button sx={buttonStyle} onClick={moveToCurrentLocation} disabled={locationAccessDenied}>
141
- <GpsFixedIcon sx={{ width: ".9em" }} />
144
+ <GpsFixedIcon sx={{fontSize: mediaIsMobile ? "1.5em" : "1.2em"}}/>
142
145
  </Button>
143
- <MlFollowGps />
146
+ <MlFollowGps style={{...(({color, ...rest}) => rest)(buttonStyle)}} />
144
147
  <ButtonGroup
145
148
  orientation="vertical"
146
149
  sx={{
147
- width: "30px",
150
+ width: "50px",
148
151
  border: "none",
149
- Button: { minWidth: "30px !important", border: "none", padding: 0 },
150
- "Button:hover": { border: "none" },
152
+ Button: {minWidth: "20px !important", border: "none", padding: 0},
153
+ "Button:hover": {border: "none"},
151
154
  }}
152
155
  >
153
- <Button sx={buttonStyle} onClick={zoomIn}>
154
- <ControlPointIcon />
156
+ <Button sx={{...buttonStyle, color: "#ececec",}} onClick={zoomIn}>
157
+ <ControlPointIcon sx={{fontSize: mediaIsMobile ? "1.5em" : "1.2em"}}/>
155
158
  </Button>
156
- <Button sx={buttonStyle} onClick={zoomOut}>
157
- <RemoveCircleOutlineIcon />
159
+ <Button sx={{...buttonStyle, color: "#ececec",}} onClick={zoomOut}>
160
+ <RemoveCircleOutlineIcon sx={{fontSize: mediaIsMobile ? "1.5em" : "1.2em"}}/>
158
161
  </Button>
159
162
  </ButtonGroup>
160
163
  </div>
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "MlScaleReference",
3
- "title": "Referencescale",
3
+ "title": "Reference scale",
4
4
  "description": "",
5
5
  "i18n": {
6
6
  "de": {
@@ -4,6 +4,7 @@ import MlScaleReference from "./MlScaleReference";
4
4
 
5
5
  import TopToolbar from "../../ui_components/TopToolbar";
6
6
  import mapContextDecorator from "../../decorators/MapContextDecorator";
7
+ import useMediaQuery from "@mui/material/useMediaQuery";
7
8
 
8
9
  const storyoptions = {
9
10
  title: "MapComponents/MlScaleReference",
@@ -16,27 +17,30 @@ const storyoptions = {
16
17
  };
17
18
  export default storyoptions;
18
19
 
19
- const Template = (props) => (
20
- <>
21
- {props.show === "toolbar" && (
22
- <TopToolbar>
23
- <MlScaleReference {...props} />
24
- </TopToolbar>
25
- )}
26
- {props.show === "overlay" && (
27
- <div
28
- style={{
29
- position: "absolute",
30
- zIndex: 100000,
31
- bottom: "20px",
32
- right: "20px",
33
- }}
34
- >
35
- <MlScaleReference {...props} />
36
- </div>
37
- )}
38
- </>
39
- );
20
+ const Template = (props) => {
21
+ const mediaIsMobile = useMediaQuery("(max-width:900px)");
22
+ return(
23
+ <>
24
+ {props.show === "toolbar" && (
25
+ <TopToolbar>
26
+ <MlScaleReference {...props} />
27
+ </TopToolbar>
28
+ )}
29
+ {props.show === "overlay" && (
30
+ <div
31
+ style={{
32
+ position: "absolute",
33
+ zIndex: 100000,
34
+ bottom: mediaIsMobile ? "40px" : "20px",
35
+ right: "20px",
36
+ }}
37
+ >
38
+ <MlScaleReference {...props} />
39
+ </div>
40
+ )}
41
+ </>
42
+ );
43
+ }
40
44
 
41
45
  export const Toolbar = Template.bind({});
42
46
  Toolbar.args = {
@@ -1,8 +1,9 @@
1
- import React, { useRef, useEffect, useContext, useState } from "react";
1
+ import React, {useRef, useEffect, useContext, useState} from "react";
2
2
  import PropTypes from "prop-types";
3
3
 
4
- import { MapContext } from "@mapcomponents/react-core";
5
- import { v4 as uuidv4 } from "uuid";
4
+ import {MapContext} from "@mapcomponents/react-core";
5
+ import {v4 as uuidv4} from "uuid";
6
+ import useMapState from "../../hooks/useMapState";
6
7
 
7
8
  /**
8
9
  * TODO: Add short & useful description
@@ -15,11 +16,21 @@ import { v4 as uuidv4 } from "uuid";
15
16
  const MlShareMapState = (props) => {
16
17
  // Use a useRef hook to reference the layer object to be able to access it later inside useEffect hooks
17
18
  const mapContext = useContext(MapContext);
18
-
19
19
  const initializedRef = useRef(false);
20
20
  const mapRef = useRef(undefined);
21
21
  const [map, setMap] = useState(undefined);
22
22
  const componentId = useRef((props.idPrefix ? props.idPrefix : "MlShareMapState-") + uuidv4());
23
+ const [isInitialState, setIsInitialState] = useState(true);
24
+ const mapState = useMapState({
25
+ watch: {
26
+ viewport: false,
27
+ layers: true,
28
+ sources: false
29
+ },
30
+ filter: {
31
+ includeBaseLayers: false
32
+ }
33
+ })
23
34
 
24
35
  const mapStateRef = useRef({});
25
36
 
@@ -49,32 +60,59 @@ const MlShareMapState = (props) => {
49
60
  mapRef.current = mapContext.getMap(props.mapId);
50
61
  setMap(mapRef.current);
51
62
 
52
- let currentUrlParams = getCurrentUrlParameters();
63
+ const currentUrlParams = getCurrentUrlParameters();
53
64
  if (currentUrlParams.lat && currentUrlParams.lng) {
54
65
  mapStateRef.current.lat = currentUrlParams.lat;
55
66
  mapStateRef.current.lng = currentUrlParams.lng;
56
67
  mapStateRef.current.zoom = currentUrlParams.zoom;
57
- mapRef.current.setCenter([mapStateRef.current.lng, mapStateRef.current.lat]);
58
68
  mapRef.current.setZoom(mapStateRef.current.zoom);
59
69
  }
60
70
  }, [mapContext.mapIds, mapContext, props.mapId, props.active]);
61
71
 
62
72
  useEffect(() => {
63
73
  if (!map) return;
74
+ if(!mapState.layers) return;
75
+ if(!isInitialState) return;
76
+
77
+ const currentUrlParams = getCurrentUrlParameters()
78
+
79
+ if(currentUrlParams.layers) {
80
+ for (let x in currentUrlParams.layers) {
81
+ mapRef.current.getLayer(currentUrlParams.layers[x].id).visibility = currentUrlParams.layers[x].visible ? "visible" : "none"
82
+ mapRef.current.getLayer(currentUrlParams.layers[x].id).type = currentUrlParams.layers[x].type
83
+ }
84
+ }
85
+
86
+ }, [mapState.layers, props.mapId, props.active])
87
+
88
+ useEffect(() => {
89
+ if (!map) return;
90
+ if (!mapState.layers) return;
64
91
 
65
92
  if (props.active) {
93
+ setIsInitialState(false)
66
94
  map.on(
67
95
  "moveend",
68
96
  () => {
97
+ let mapLayers = []
98
+ for (let x in mapState.layers) {
99
+ mapLayers.push(new URLSearchParams({
100
+ id: mapState.layers[x].id,
101
+ type: mapState.layers[x].type,
102
+ visible: mapState.layers[x].visible
103
+ }))
104
+ }
69
105
  refreshMapState();
70
106
  let urlParams = new URLSearchParams({
71
107
  ...getCurrentUrlParameters(),
72
108
  ...mapStateRef.current,
109
+ layers : mapLayers
73
110
  });
111
+
74
112
  let currentParams = new URLSearchParams(window.location.search);
75
113
  if (urlParams.toString() !== currentParams.toString()) {
76
114
  window.history.pushState(
77
- { ...mapStateRef.current },
115
+ {...mapStateRef.current},
78
116
  document.title,
79
117
  "?" + urlParams.toString()
80
118
  );
@@ -88,7 +126,33 @@ const MlShareMapState = (props) => {
88
126
  }, [props.active, map]);
89
127
 
90
128
  const getCurrentUrlParameters = () => {
91
- return Object.fromEntries(new URLSearchParams(window.location.search));
129
+ let parameterObject = Object.fromEntries(new URLSearchParams(window.location.search))
130
+
131
+ if(window.location.search.indexOf("layers")!==-1) {
132
+ let layerParamString = window.location.search.substring(window.location.search.indexOf("layers"))
133
+ layerParamString = layerParamString.substring(0, (layerParamString.indexOf("&")!==-1) ? layerParamString.indexOf("&") : layerParamString.length)
134
+ parameterObject = Object.fromEntries(new URLSearchParams(window.location.search.replace(layerParamString, "")))
135
+ let layerParams = layerParamString.substring(7)
136
+ layerParams = layerParams.replaceAll("%3D", "=")
137
+ layerParams = layerParams.replaceAll("%26", "&")
138
+ layerParams = layerParams.replaceAll("%2C", ",")
139
+
140
+ if (layerParams.indexOf(",")) {
141
+ layerParams = layerParams.split(",")
142
+ } else {
143
+ layerParams = [layerParams]
144
+ }
145
+
146
+ for (let x in layerParams) {
147
+ let layerState = layerParams[x].split("&")
148
+ layerParams[x] = {}
149
+ for (let y in layerState) {
150
+ layerParams[x][layerState[y].split("=")[0]] = layerState[y].split("=")[1]
151
+ }
152
+ }
153
+ parameterObject["layers"] = layerParams
154
+ }
155
+ return parameterObject
92
156
  };
93
157
 
94
158
  const refreshMapState = () => {
@@ -99,7 +163,7 @@ const MlShareMapState = (props) => {
99
163
 
100
164
  window.onpopstate = (event) => {
101
165
  if (event.state && event.state.lng && event.state.lat && event.state.zoom) {
102
- mapRef.current.easeTo({ zoom: event.state.zoom, center: [event.state.lng, event.state.lat] });
166
+ mapRef.current.easeTo({zoom: event.state.zoom, center: [event.state.lng, event.state.lat]});
103
167
  }
104
168
  };
105
169
 
@@ -2,6 +2,8 @@ import React, { useState} from "react";
2
2
 
3
3
  import MlShareMapState from "./MlShareMapState";
4
4
  import mapContextDecorator from "../../decorators/MapContextDecorator";
5
+ import useMapState from "../../hooks/useMapState";
6
+ import MlLayer from "../MlLayer/MlLayer";
5
7
 
6
8
  const storyoptions = {
7
9
  title: "MapComponents/MlShareMapState",
@@ -12,7 +14,19 @@ const storyoptions = {
12
14
  export default storyoptions;
13
15
 
14
16
  const Template = (args) => {
15
- const [watchState, setWatchState] = useState(true);
17
+ const [watchState, setWatchState] = useState(false);
18
+ const [testLayerVisible, setTestLayerVisible] = useState(true);
19
+ const mapState = useMapState({
20
+ watch : {
21
+ viewport : false,
22
+ layers : true,
23
+ sources : false
24
+ },
25
+ filter : {
26
+ includeBaseLayers : false
27
+ }
28
+ }
29
+ )
16
30
 
17
31
  return (
18
32
  <>
@@ -22,7 +36,16 @@ const Template = (args) => {
22
36
  >
23
37
  watch map state {watchState?1:0}
24
38
  </button>
39
+ <button
40
+ style={{ zIndex: "1000", position: "absolute" }}
41
+ onClick={() => setTestLayerVisible(!testLayerVisible)}
42
+ >
43
+ visibility {testLayerVisible?1:0}
44
+ </button>
25
45
  <MlShareMapState active={watchState} />
46
+ <MlLayer layerId={"MlLayer-testLayer"} options={{layout: {visibility: (testLayerVisible ? "visible":"none")}}} />
47
+ <MlLayer layerId={"MlLayer-testLayer2"} options={{layout: {visibility: (testLayerVisible ? "visible":"none")}}} />
48
+ <MlLayer layerId={"MlLayer-testLayer3"} options={{layout: {visibility: (testLayerVisible ? "visible":"none")}}} />
26
49
  </>
27
50
  );
28
51
  };
@@ -9,6 +9,7 @@ import Button from "@mui/material/Button";
9
9
  import FileDownloadIcon from '@mui/icons-material/FileDownload';
10
10
  import InfoIcon from "@mui/icons-material/Info";
11
11
  import IconButton from "@mui/material/IconButton";
12
+ import useMediaQuery from "@mui/material/useMediaQuery";
12
13
 
13
14
  const storyoptions = {
14
15
  title: "MapComponents/MlSpatialElevationProfile",
@@ -24,30 +25,35 @@ const storyoptions = {
24
25
  };
25
26
  export default storyoptions;
26
27
 
27
- const Template = (args) => (
28
+ const Template = (args) => {
29
+
30
+ const mediaIsMobile = useMediaQuery("(max-width:900px)");
31
+
32
+ return(
28
33
  <>
29
34
  <IconButton
30
35
  style={{
31
36
  position: "absolute",
32
37
  right: "5px",
33
- bottom: "125px",
38
+ bottom: mediaIsMobile ? "145px" : "125px",
34
39
  backgroundColor: "rgba(255,255,255,1)",
35
40
 
36
41
  zIndex: 1000,
37
42
  }}
38
43
  title="Download sample-data"
39
44
  size="large"
40
- href="/assets/sample.gpx"
45
+ href="assets/sample.gpx"
41
46
  target="blank"
42
47
  >
43
- <FileDownloadIcon/>
48
+ <FileDownloadIcon />
44
49
  </IconButton>
45
50
  <GeoJsonProvider>
46
- <MlGPXViewer/>
47
- <MlSpatialElevationProfile/>
51
+ <MlGPXViewer />
52
+ <MlSpatialElevationProfile />
48
53
  </GeoJsonProvider>
49
54
  </>
50
55
  );
56
+ }
51
57
 
52
58
  export const ExampleConfig = Template.bind({});
53
59
  ExampleConfig.parameters = {};
@@ -45,8 +45,13 @@ const MlThreeJsLayer = (props) => {
45
45
  initializedRef.current = true;
46
46
  mapRef.current = mapContext.getMap(props.mapId);
47
47
 
48
+ mapRef.current.setCenter([7.099771581806502, 50.73395746209983]);
49
+ mapRef.current.setZoom(15);
50
+ mapRef.current.setPitch(45);
51
+
48
52
  // parameters to ensure the model is georeferenced correctly on the map
49
- var modelOrigin = [7.1300753566457304, 50.71596191210998];
53
+ var modelOrigin = [7.099771581806502, 50.73395746209983];
54
+ // 50.73395746209983, 7.099771581806502
50
55
  var modelAltitude = 0;
51
56
  var modelRotate = [Math.PI / 2, 90, 0];
52
57
 
@@ -92,8 +97,7 @@ const MlThreeJsLayer = (props) => {
92
97
  // use the three.js GLTF loader to add the 3D model to the three.js scene
93
98
  var loader = new GLTFLoader();
94
99
  loader.load(
95
- //"/assets/3D/posttower_simple.gltf",
96
- "/assets/3D/godzilla_simple.glb",
100
+ "assets/3D/godzilla_simple.glb",
97
101
  //"https://docs.mapbox.com/mapbox-gl-js/assets/34M_17/34M_17.gltf",
98
102
  function (gltf) {
99
103
  this.scene.add(gltf.scene);
@@ -102,14 +106,6 @@ const MlThreeJsLayer = (props) => {
102
106
  }
103
107
  }.bind(this)
104
108
  );
105
- loader.load(
106
- "/assets/3D/posttower.gltf",
107
- //"/assets/3D/posttower_wh.gltf.glb",
108
- //"https://docs.mapbox.com/mapbox-gl-js/assets/34M_17/34M_17.gltf",
109
- function (gltf) {
110
- this.scene.add(gltf.scene);
111
- }.bind(this)
112
- );
113
109
  this.map = map;
114
110
 
115
111
  // use the Mapbox GL JS map canvas for three.js
@@ -161,9 +157,6 @@ const MlThreeJsLayer = (props) => {
161
157
  if (mapRef.current.getLayer(layerName)) {
162
158
  mapRef.current.setLayoutProperty(layerName, "visibility", "visible");
163
159
  }
164
- mapRef.current.setCenter([7.130255969902919, 50.7143656091998]);
165
- mapRef.current.setZoom(15);
166
- mapRef.current.setPitch(45);
167
160
  }, [mapContext.mapIds, mapContext, props]);
168
161
 
169
162
  useEffect(() => {
@@ -211,4 +204,4 @@ MlThreeJsLayer.propTypes = {
211
204
  onDone: PropTypes.func,
212
205
  };
213
206
 
214
- export default MlThreeJsLayer;
207
+ export default MlThreeJsLayer;
@@ -47,7 +47,7 @@ const defaultProps = {
47
47
  const MlWmsLayer = (props) => {
48
48
  const mapContext = useContext(MapContext);
49
49
 
50
- const componentId = useRef((props.idPrefix ? props.idPrefix : "MlWmsLayer-") + uuidv4());
50
+ const componentId = useRef(props.layerId || ("MlWmsLayer-" + uuidv4()));
51
51
  const mapRef = useRef(null);
52
52
  const initializedRef = useRef(false);
53
53
  const layerId = useRef(props.layerId || componentId.current);
@@ -41,7 +41,7 @@ const MlWmsLoader = (props) => {
41
41
  // Use a useRef hook to reference the layer object to be able to access it later inside useEffect hooks
42
42
  const mapContext = useContext(MapContext);
43
43
  const { capabilities, error, setUrl, getFeatureInfoUrl, wmsUrl } = useWms({
44
- url: props.url,
44
+ url: undefined,
45
45
  urlParameters: props.urlParameters,
46
46
  });
47
47
 
@@ -72,6 +72,8 @@ const MlWmsLoader = (props) => {
72
72
  }, []);
73
73
 
74
74
  useEffect(() => {
75
+ if (!initializedRef.current) return;
76
+
75
77
  setUrl(props.url);
76
78
  }, [props.url]);
77
79
 
@@ -199,17 +201,19 @@ const MlWmsLoader = (props) => {
199
201
  // initialize the layer and add it to the MapLibre-gl instance or do something else with it
200
202
  initializedRef.current = true;
201
203
  mapRef.current = mapContext.getMap(props.mapId);
202
- }, [mapContext.mapIds, mapContext, props.mapId]);
204
+ console.log("set url " + props.url);
205
+ setUrl(props.url);
206
+ }, [mapContext.mapIds, mapContext, props.mapId, props.url]);
203
207
 
204
208
  return (
205
209
  <>
206
210
  {error && <p>{error}</p>}
207
211
  <h3 key="title">{capabilities?.Service?.Title}</h3>
212
+ {console.log(componentId.current)}
208
213
  {capabilities?.Capability?.Layer?.Layer.map((layer, idx) => (
209
214
  <MlLayer
210
- layerId="Order-"
215
+ layerId={"Order-" + componentId.current + "-" + idx}
211
216
  key={componentId.current + "-" + idx}
212
- idSuffix={componentId.current + "-" + idx}
213
217
  {...(idx > 0
214
218
  ? {
215
219
  insertBeforeLayer: "Order-" + componentId.current + "-" + (idx - 1),
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "MlWmsLoader",
3
- "title": "WMS Info",
3
+ "title": "WMS loader",
4
4
  "description": "",
5
5
  "i18n": {
6
6
  "de": {
@@ -18,11 +18,11 @@ const storyoptions = {
18
18
  export default storyoptions;
19
19
 
20
20
  const Template = (props) => {
21
- const [url, setUrl] = useState("");
21
+ const [url, setUrl] = useState(props.url);
22
22
 
23
23
  return (
24
24
  <>
25
- <Sidebar sx={{ width: "500px", wordBreak: "break-word" }}>
25
+ <Sidebar sx={{ wordBreak: "break-word" }}>
26
26
  <TextField
27
27
  label="WMS Url"
28
28
  variant="standard"
@@ -40,7 +40,8 @@ ExampleConfig.parameters = {};
40
40
  ExampleConfig.args = {
41
41
  /**
42
42
  * try https://maps.heigit.org/histosm/wms or https://magosm.magellium.com/geoserver/wms
43
- *
43
+ * https://www.wms.nrw.de/wms/kitas
44
+ * https://www.wms.nrw.de/geobasis/wms_nw_vdop
44
45
  */
45
- url: "https://www.wms.nrw.de/geobasis/wms_nw_vdop",
46
+ url: "https://www.wms.nrw.de/wms/kitas",
46
47
  };
@@ -4,16 +4,21 @@ import { MapComponentsProvider } from "@mapcomponents/react-core";
4
4
  import { LoadingOverlayProvider } from "../ui_components/LoadingOverlayContext";
5
5
  import LoadingOverlay from "../ui_components/LoadingOverlay";
6
6
  import "./style.css";
7
+ import { createTheme, ThemeProvider } from "@mui/material/styles";
8
+
9
+ const theme = createTheme({});
7
10
 
8
11
  const decorators = [
9
12
  (Story) => (
10
- <MapComponentsProvider>
11
- <LoadingOverlayProvider>
12
- <LoadingOverlay></LoadingOverlay>
13
+ <ThemeProvider theme={theme}>
14
+ <MapComponentsProvider>
15
+ <LoadingOverlayProvider>
16
+ <LoadingOverlay></LoadingOverlay>
13
17
 
14
- <Story />
15
- </LoadingOverlayProvider>
16
- </MapComponentsProvider>
18
+ <Story />
19
+ </LoadingOverlayProvider>
20
+ </MapComponentsProvider>
21
+ </ThemeProvider>
17
22
  ),
18
23
  ];
19
24