@mapcomponents/react-maplibre 0.1.62 → 0.1.63

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 (185) hide show
  1. package/.babelrc +21 -2
  2. package/.eslintrc.js +8 -1
  3. package/.storybook/main.js +0 -1
  4. package/.storybook/preview.js +0 -2
  5. package/CHANGELOG.md +18 -0
  6. package/coverage/clover.xml +232 -44
  7. package/coverage/coverage-final.json +11 -3
  8. package/coverage/lcov-report/favicon.png +0 -0
  9. package/coverage/lcov-report/index.html +70 -25
  10. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  11. package/coverage/lcov-report/src/components/MapLibreMap/MapLibreMap.tsx.html +1 -1
  12. package/coverage/lcov-report/src/components/MapLibreMap/index.html +1 -1
  13. package/coverage/lcov-report/src/components/MlCenterPosition/MlCenterPosition.tsx.html +1 -1
  14. package/coverage/lcov-report/src/components/MlCenterPosition/index.html +1 -1
  15. package/coverage/lcov-report/src/components/MlCreatePdfButton/MlCreatePdfButton.tsx.html +1 -1
  16. package/coverage/lcov-report/src/components/MlCreatePdfButton/index.html +1 -1
  17. package/coverage/lcov-report/src/components/MlCreatePdfForm/MlCreatePdfForm.cy.tsx.html +148 -0
  18. package/coverage/lcov-report/src/components/MlCreatePdfForm/MlCreatePdfForm.tsx.html +1 -1
  19. package/coverage/lcov-report/src/components/MlCreatePdfForm/index.html +22 -7
  20. package/coverage/lcov-report/src/components/MlFeatureEditor/MlFeatureEditor.tsx.html +73 -40
  21. package/coverage/lcov-report/src/components/MlFeatureEditor/index.html +15 -15
  22. package/coverage/lcov-report/src/components/MlFillExtrusionLayer/MlFillExtrusionLayer.tsx.html +1 -1
  23. package/coverage/lcov-report/src/components/MlFillExtrusionLayer/index.html +1 -1
  24. package/coverage/lcov-report/src/components/MlFollowGps/MlFollowGps.tsx.html +1 -1
  25. package/coverage/lcov-report/src/components/MlFollowGps/index.html +1 -1
  26. package/coverage/lcov-report/src/components/MlGPXViewer/MlGPXViewer.tsx.html +9 -3
  27. package/coverage/lcov-report/src/components/MlGPXViewer/gpxConverter.js.html +1 -1
  28. package/coverage/lcov-report/src/components/MlGPXViewer/index.html +1 -1
  29. package/coverage/lcov-report/src/components/MlGeoJsonLayer/MlGeoJsonLayer.tsx.html +59 -29
  30. package/coverage/lcov-report/src/components/MlGeoJsonLayer/index.html +1 -1
  31. package/coverage/lcov-report/src/components/MlGeoJsonLayer/story_utils/MlGeoJsonLayer.lineStyler.js.html +652 -0
  32. package/coverage/lcov-report/src/components/MlGeoJsonLayer/story_utils/MlGeoJsonLayer.polygonStyler.js.html +649 -0
  33. package/coverage/lcov-report/src/components/MlGeoJsonLayer/story_utils/index.html +131 -0
  34. package/coverage/lcov-report/src/components/MlGeojsonLayerWithSource/MlGeojsonLayerWithSource.tsx.html +1 -1
  35. package/coverage/lcov-report/src/components/MlGeojsonLayerWithSource/index.html +1 -1
  36. package/coverage/lcov-report/src/components/MlImageMarkerLayer/MlImageMarkerLayer.tsx.html +1 -1
  37. package/coverage/lcov-report/src/components/MlImageMarkerLayer/index.html +1 -1
  38. package/coverage/lcov-report/src/components/MlLayer/MlLayer.tsx.html +1 -1
  39. package/coverage/lcov-report/src/components/MlLayer/index.html +1 -1
  40. package/coverage/lcov-report/src/components/MlLayerMagnify/MlLayerMagnify.tsx.html +1 -1
  41. package/coverage/lcov-report/src/components/MlLayerMagnify/index.html +1 -1
  42. package/coverage/lcov-report/src/components/MlLayerSwipe/MlLayerSwipe.tsx.html +1 -1
  43. package/coverage/lcov-report/src/components/MlLayerSwipe/index.html +1 -1
  44. package/coverage/lcov-report/src/components/MlLayerSwitcher/MlLayerSwitcher.js.html +1 -1
  45. package/coverage/lcov-report/src/components/MlLayerSwitcher/components/LayerBox.js.html +1 -1
  46. package/coverage/lcov-report/src/components/MlLayerSwitcher/components/index.html +1 -1
  47. package/coverage/lcov-report/src/components/MlLayerSwitcher/index.html +1 -1
  48. package/coverage/lcov-report/src/components/MlMarker/MlMarker.tsx.html +1 -1
  49. package/coverage/lcov-report/src/components/MlMarker/index.html +1 -1
  50. package/coverage/lcov-report/src/components/MlMeasureTool/MlMeasureTool.tsx.html +1 -1
  51. package/coverage/lcov-report/src/components/MlMeasureTool/index.html +1 -1
  52. package/coverage/lcov-report/src/components/MlNavigationCompass/MlNavigationCompass.tsx.html +1 -1
  53. package/coverage/lcov-report/src/components/MlNavigationCompass/index.html +1 -1
  54. package/coverage/lcov-report/src/components/MlNavigationTools/MlNavigationTools.tsx.html +1 -1
  55. package/coverage/lcov-report/src/components/MlNavigationTools/index.html +1 -1
  56. package/coverage/lcov-report/src/components/MlOsmLayer/MlOsmLayer.js.html +1 -1
  57. package/coverage/lcov-report/src/components/MlOsmLayer/MlOsmLayer.stories_.js.html +1 -1
  58. package/coverage/lcov-report/src/components/MlOsmLayer/index.html +1 -1
  59. package/coverage/lcov-report/src/components/MlScaleReference/MlScaleReference.js.html +1 -1
  60. package/coverage/lcov-report/src/components/MlScaleReference/index.html +1 -1
  61. package/coverage/lcov-report/src/components/MlShareMapState/MlShareMapState.js.html +1 -1
  62. package/coverage/lcov-report/src/components/MlShareMapState/index.html +1 -1
  63. package/coverage/lcov-report/src/components/MlSketchTool/LayerList/ColorPicker.tsx.html +214 -0
  64. package/coverage/lcov-report/src/components/MlSketchTool/LayerList/LayerList.tsx.html +121 -0
  65. package/coverage/lcov-report/src/components/MlSketchTool/LayerList/LayerListItem.tsx.html +412 -0
  66. package/coverage/lcov-report/src/components/MlSketchTool/LayerList/LayerPropertyForm.tsx.html +463 -0
  67. package/coverage/lcov-report/src/components/MlSketchTool/LayerList/index.html +161 -0
  68. package/coverage/lcov-report/src/components/MlSketchTool/MlSketchTool.tsx.html +898 -0
  69. package/coverage/lcov-report/src/components/MlSketchTool/index.html +116 -0
  70. package/coverage/lcov-report/src/components/MlSpatialElevationProfile/MlSpatialElevationProfile.js.html +1 -1
  71. package/coverage/lcov-report/src/components/MlSpatialElevationProfile/index.html +1 -1
  72. package/coverage/lcov-report/src/components/MlThreeJsLayer/MlThreeJsLayer.js.html +1 -1
  73. package/coverage/lcov-report/src/components/MlThreeJsLayer/index.html +1 -1
  74. package/coverage/lcov-report/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.tsx.html +1 -1
  75. package/coverage/lcov-report/src/components/MlTransitionGeoJsonLayer/index.html +1 -1
  76. package/coverage/lcov-report/src/components/MlUseMapDebugger/MlUseMapDebugger.js.html +1 -1
  77. package/coverage/lcov-report/src/components/MlUseMapDebugger/index.html +1 -1
  78. package/coverage/lcov-report/src/components/MlVectorTileLayer/MlVectorTileLayer.tsx.html +1 -1
  79. package/coverage/lcov-report/src/components/MlVectorTileLayer/index.html +1 -1
  80. package/coverage/lcov-report/src/components/MlWmsFeatureInfoPopup/MlWmsFeatureInfoPopup.js.html +1 -1
  81. package/coverage/lcov-report/src/components/MlWmsFeatureInfoPopup/index.html +1 -1
  82. package/coverage/lcov-report/src/components/MlWmsLayer/MlWmsLayer.tsx.html +1 -1
  83. package/coverage/lcov-report/src/components/MlWmsLayer/index.html +1 -1
  84. package/coverage/lcov-report/src/components/MlWmsLoader/MlWmsLoader.tsx.html +1 -1
  85. package/coverage/lcov-report/src/components/MlWmsLoader/index.html +1 -1
  86. package/coverage/lcov-report/src/contexts/MapContext.tsx.html +1 -1
  87. package/coverage/lcov-report/src/contexts/SimpleDataContext.js.html +1 -1
  88. package/coverage/lcov-report/src/contexts/SimpleDataProvider.js.html +1 -1
  89. package/coverage/lcov-report/src/contexts/index.html +1 -1
  90. package/coverage/lcov-report/src/hooks/index.html +1 -1
  91. package/coverage/lcov-report/src/hooks/useCameraFollowPath/index.html +1 -1
  92. package/coverage/lcov-report/src/hooks/useCameraFollowPath/useCameraFollowPath.tsx.html +1 -1
  93. package/coverage/lcov-report/src/hooks/useExportMap/index.html +1 -1
  94. package/coverage/lcov-report/src/hooks/useExportMap/index.ts.html +1 -1
  95. package/coverage/lcov-report/src/hooks/useExportMap/lib.ts.html +1 -1
  96. package/coverage/lcov-report/src/hooks/useLayer.ts.html +1 -1
  97. package/coverage/lcov-report/src/hooks/useLayerEvent.js.html +1 -1
  98. package/coverage/lcov-report/src/hooks/useMap.ts.html +1 -1
  99. package/coverage/lcov-report/src/hooks/useMapState.ts.html +1 -1
  100. package/coverage/lcov-report/src/hooks/useSource.ts.html +1 -1
  101. package/coverage/lcov-report/src/hooks/useWms.js.html +1 -1
  102. package/coverage/lcov-report/src/index.html +1 -1
  103. package/coverage/lcov-report/src/index.ts.html +1 -1
  104. package/coverage/lcov.info +514 -89
  105. package/cypress/support/commands.ts +37 -0
  106. package/cypress/support/component-index.html +12 -0
  107. package/cypress/support/component.ts +46 -0
  108. package/cypress.config.ts +101 -0
  109. package/dist/components/MapLibreMap/MapLibreMap.d.ts +1 -1
  110. package/dist/components/MapLibreMap/lib/MapLibreGlWrapper.d.ts +3 -3
  111. package/dist/components/MlCreatePdfForm/MlCreatePdfForm.cy.d.ts +1 -0
  112. package/dist/components/MlCreatePdfForm/lib/PdfPreview.d.ts +1 -1
  113. package/dist/components/MlFeatureEditor/MlFeatureEditor.d.ts +10 -4
  114. package/dist/components/MlFeatureEditor/lib/double_click_zoom.d.ts +0 -2
  115. package/dist/components/MlFeatureEditor/lib/theme.d.ts +1 -1
  116. package/dist/components/MlGPXViewer/util/GeoJsonContext.d.ts +1 -1
  117. package/dist/components/MlGPXViewer/util/MlGPXViewerInstructions.d.ts +1 -0
  118. package/dist/components/MlGPXViewer/util/SampleLayer.d.ts +0 -0
  119. package/dist/components/MlGPXViewer/util/demoViewer.d.ts +5 -0
  120. package/dist/components/MlGeoJsonLayer/MlGeoJsonLayer.d.ts +4 -4
  121. package/dist/components/MlGeoJsonLayer/MlGeoJsonLayer.stories.d.ts +103 -11
  122. package/dist/components/MlGeoJsonLayer/story_utils/MlGeoJsonLayer.lineStyler.d.ts +2 -0
  123. package/dist/components/MlGeoJsonLayer/story_utils/MlGeoJsonLayer.polygonStyler.d.ts +2 -0
  124. package/dist/components/MlSketchTool/LayerList/ColorPicker.d.ts +9 -0
  125. package/dist/components/MlSketchTool/LayerList/LayerList.d.ts +5 -0
  126. package/dist/components/MlSketchTool/LayerList/LayerListItem.d.ts +11 -0
  127. package/dist/components/MlSketchTool/LayerList/LayerPropertyForm.d.ts +9 -0
  128. package/dist/components/MlSketchTool/MlSketchTool.d.ts +29 -0
  129. package/dist/components/MlSketchTool/MlSketchTool.stories.d.ts +10 -0
  130. package/dist/contexts/SimpleDataProvider.d.ts +1 -1
  131. package/dist/custom.d.d.ts +1 -1
  132. package/dist/hooks/useLayer.d.ts +1 -1
  133. package/dist/hooks/useMap.d.ts +1 -1
  134. package/dist/hooks/useMapState.d.ts +3 -3
  135. package/dist/hooks/useSource.d.ts +1 -1
  136. package/dist/index.esm.css +1 -1
  137. package/dist/index.esm.js +2736 -3557
  138. package/dist/index.esm.js.map +1 -1
  139. package/dist/ui_components/LoadingOverlayContext.d.ts +1 -1
  140. package/dist/ui_components/Sidebar.d.ts +9 -1
  141. package/dist/ui_components/TopToolbar.d.ts +6 -1
  142. package/package.json +21 -15
  143. package/public/assets/sample1.gpx +3003 -0
  144. package/public/assets/sample2.gpx +1264 -0
  145. package/public/assets/sample3.gpx +912 -0
  146. package/public/index.html +0 -4
  147. package/public/thumbnails/MlSketchTool.png +0 -0
  148. package/public/thumbnails/useCameraFollowPath.png +0 -0
  149. package/src/components/MlCreatePdfForm/MlCreatePdfForm.cy.tsx +21 -0
  150. package/src/components/MlCreatePdfForm/MlCreatePdfForm.stories.tsx +1 -3
  151. package/src/components/MlCreatePdfForm/lib/PdfForm.tsx +1 -1
  152. package/src/components/MlFeatureEditor/MlFeatureEditor.meta.json +1 -1
  153. package/src/components/MlFeatureEditor/MlFeatureEditor.tsx +39 -28
  154. package/src/components/MlGPXViewer/MlGPXViewer.stories.js +75 -15
  155. package/src/components/MlGPXViewer/MlGPXViewer.tsx +3 -1
  156. package/src/components/MlGPXViewer/util/MlGPXViewerInstructions.js +145 -0
  157. package/src/components/MlGPXViewer/util/SampleLayer.js +2 -0
  158. package/src/components/MlGPXViewer/util/demoViewer.js +254 -0
  159. package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.stories.tsx +102 -0
  160. package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.tsx +33 -23
  161. package/src/components/MlGeoJsonLayer/assets/sample_1.json +138 -24
  162. package/src/components/MlGeoJsonLayer/assets/sample_2.json +140 -20
  163. package/src/components/MlGeoJsonLayer/story_utils/MlGeoJsonLayer.lineStyler.js +189 -0
  164. package/src/components/MlGeoJsonLayer/story_utils/MlGeoJsonLayer.polygonStyler.js +188 -0
  165. package/src/components/MlSketchTool/LayerList/ColorPicker.tsx +43 -0
  166. package/src/components/MlSketchTool/LayerList/LayerList.tsx +12 -0
  167. package/src/components/MlSketchTool/LayerList/LayerListItem.tsx +109 -0
  168. package/src/components/MlSketchTool/LayerList/LayerPropertyForm.tsx +126 -0
  169. package/src/components/MlSketchTool/MlSketchTool.doc.de.md +3 -0
  170. package/src/components/MlSketchTool/MlSketchTool.meta.json +15 -0
  171. package/src/components/MlSketchTool/MlSketchTool.stories.js +26 -0
  172. package/src/components/MlSketchTool/MlSketchTool.tsx +271 -0
  173. package/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.meta.json +2 -2
  174. package/src/ui_components/Sidebar.tsx +80 -0
  175. package/src/ui_components/TopToolbar.tsx +24 -0
  176. package/tsconfig.json +39 -58
  177. package/config/getHttpsConfig.js +0 -66
  178. package/config/modules.js +0 -134
  179. package/config/pnpTs.js +0 -35
  180. package/config/webpack.config.js +0 -757
  181. package/config/webpackDevServer.config.js +0 -130
  182. package/scripts/start.js +0 -166
  183. package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.stories.js +0 -66
  184. package/src/ui_components/Sidebar.js +0 -100
  185. package/src/ui_components/TopToolbar.js +0 -29
@@ -0,0 +1,254 @@
1
+ import React, { useContext, useRef, useEffect, useState, useCallback } from 'react';
2
+ import { bbox } from '@turf/turf';
3
+ import Divider from '@mui/material/Divider';
4
+ import Typography from '@mui/material/Typography';
5
+ import CloseIcon from '@mui/icons-material/Close';
6
+ import Drawer from '@mui/material/Drawer';
7
+ import IconButton from '@mui/material/IconButton';
8
+ import Box from '@mui/material/Box';
9
+ import Button from '@mui/material/Button';
10
+ import Modal from '@mui/material/Modal';
11
+ import InfoIcon from '@mui/icons-material/Info';
12
+ import FileCopy from '@mui/icons-material/FileCopy';
13
+ import List from '@mui/material/List';
14
+ import ListItem from '@mui/material/ListItem';
15
+ import ListItemText from '@mui/material/ListItemText';
16
+ import GeoJsonContext from './GeoJsonContext';
17
+ import toGeoJSON from '../gpxConverter';
18
+ import useMediaQuery from '@mui/material/useMediaQuery';
19
+ import useMap from '../../../hooks/useMap';
20
+ import Grid from '@mui/material/Grid';
21
+ import { ListItemButton } from '@mui/material';
22
+
23
+
24
+ const modalStyle = {
25
+ position: 'absolute',
26
+ top: '50%',
27
+ left: '60%',
28
+ width: 350,
29
+ height: 280,
30
+ bgcolor: 'background.paper',
31
+ boxShadow: 24,
32
+ p: 4,
33
+ };
34
+
35
+ const mobileStyle = {
36
+ position: 'absolute',
37
+ top: '30%',
38
+ left: '20%',
39
+ width: 200,
40
+ height: 300,
41
+ bgcolor: 'background.paper',
42
+ boxShadow: 24,
43
+ p: 4,
44
+ };
45
+
46
+ /**
47
+ * MlSpatialElevationProfileDemoViewer returns a button to load a Demo GPX Track into the map.
48
+ */
49
+ const MlGPXDemoLoader = (props) => {
50
+
51
+ const [openModal, setOpenModal] = useState(false);
52
+ const [infoOpen, setInfoOpen] = useState(false);
53
+ const [metaData, setMetaData] = useState([]);
54
+ const [selectedSample, setSelectedSample] = useState();
55
+ const mapHook = useMap({ mapId: 'map_1' });
56
+ const dataSource = useContext(GeoJsonContext);
57
+ const sourceName = 'import-source';
58
+ const [file, setFile] = useState();
59
+ const reader = useRef(new FileReader());
60
+ reader.current.onload = (payload) => {
61
+ if (!payload) return;
62
+ setFile(payload.currentTarget.result);
63
+ };
64
+
65
+ const mediaIsMobile = useMediaQuery('(max-width:900px)');
66
+
67
+ const toogleDrawer = () => {
68
+ setInfoOpen(!infoOpen);
69
+ };
70
+
71
+ const handleClick = () => {
72
+ setOpenModal(true);
73
+ };
74
+
75
+ const handleSelect = (e) => {
76
+
77
+ if (e.target.innerText === 'mountain_trail.gpx') {
78
+ setSelectedSample('assets/sample1.gpx');
79
+ } else if (e.target.innerText === 'bycycle_tour.gpx') {
80
+ setSelectedSample('assets/sample2.gpx');
81
+ } else {
82
+ setSelectedSample('assets/sample3.gpx');
83
+ }
84
+
85
+ e.target.style.backgroundColor = 'lightgray';
86
+ };
87
+
88
+ useEffect(() => {
89
+ if (!selectedSample) return;
90
+ fetch(selectedSample)
91
+ .then(function (response) {
92
+ return response.blob();
93
+ })
94
+ .then(function (gpx) {
95
+ reader.current.readAsText(gpx);
96
+ });
97
+ }, [selectedSample]);
98
+
99
+ const handleLoad = useCallback(() => {
100
+ addGPXToMap(file);
101
+ setOpenModal(false);
102
+ }, [file]);
103
+
104
+ const handleClose = () => {
105
+ setOpenModal(false);
106
+ };
107
+
108
+ const addGPXToMap = (gpxAsString) => {
109
+ if (!mapHook.map || !dataSource.setData) return;
110
+ try {
111
+ setMetaData([]);
112
+ const domParser = new DOMParser();
113
+ const gpxDoc = domParser.parseFromString(gpxAsString, 'application/xml');
114
+ const metadata = gpxDoc.querySelector('metadata');
115
+ metadata?.childNodes.forEach((node) => {
116
+ let value = node.textContent;
117
+ const title = node.nodeName;
118
+
119
+ if (node.nodeName === 'link') {
120
+ value = node.getAttribute('href');
121
+ }
122
+ if (value?.trim().length) {
123
+ const metaDatEntry = {
124
+ title: title,
125
+ value: value,
126
+ id: new Date().getTime(),
127
+ };
128
+ setMetaData((prevState) => [...prevState, metaDatEntry]);
129
+ }
130
+ });
131
+ const data = toGeoJSON.gpx(gpxDoc);
132
+ dataSource.setData(data);
133
+ mapHook.map.map.getSource(sourceName).setData(data);
134
+ const bounds = bbox(data);
135
+ mapHook.map.map.fitBounds(bounds);
136
+ } catch (e) {
137
+ console.log(e);
138
+ }
139
+ };
140
+
141
+ return (
142
+ <>
143
+ <Modal
144
+ open={openModal}
145
+ onClose={handleClose}
146
+ aria-labelledby="modal-modal-title"
147
+ aria-describedby="modal-modal-description"
148
+ >
149
+ <Box sx={mediaIsMobile ? mobileStyle : modalStyle}>
150
+ <Grid container>
151
+ <Grid xs={10}>
152
+ <Typography id="modal-modal-title" variant="h6">
153
+ GPX demo files
154
+ </Typography>
155
+ </Grid>
156
+ <Grid xs={2}>
157
+ <Button onClick={handleClose}>
158
+ <CloseIcon sx={{ color: 'black' }} />
159
+ </Button>
160
+ </Grid>
161
+ </Grid>
162
+ <Divider />
163
+
164
+ <List>
165
+ <ListItem>
166
+ <ListItemButton value="sample1" onClick={handleSelect}>
167
+ <ListItemText> mountain_trail.gpx </ListItemText>
168
+ </ListItemButton>
169
+ </ListItem>
170
+ <Divider variant="inset" component="li" />
171
+ <ListItem>
172
+ <ListItemButton value="sample2" onClick={handleSelect}>
173
+ <ListItemText> bycycle_tour.gpx </ListItemText>
174
+ </ListItemButton>
175
+ </ListItem>
176
+ <Divider variant="inset" component="li" />
177
+ <ListItem>
178
+ <ListItemButton value="sample3" onClick={handleSelect}>
179
+ <ListItemText>treckking.gpx </ListItemText>
180
+ </ListItemButton>
181
+ </ListItem>
182
+ <Divider variant="inset" component="li" />
183
+ </List>
184
+
185
+ <Grid>
186
+ <Button
187
+ variant="outlined"
188
+ onClick={handleLoad}
189
+ sx={{ display: 'block', marginLeft: 'auto' }}
190
+ >
191
+ Load
192
+ </Button>
193
+ </Grid>
194
+ </Box>
195
+ </Modal>
196
+
197
+ <Drawer variant="persistent" anchor="left" open={infoOpen}>
198
+ <Typography
199
+ variant="h6"
200
+ style={{
201
+ textAlign: "center",
202
+ padding: "1em",
203
+ }}
204
+ noWrap
205
+ >
206
+ Informationen zur Route
207
+ </Typography>
208
+ <Divider />
209
+ <List>
210
+ {metaData.map((item) => (
211
+ <ListItem key={`item--${item.id}`}>
212
+ <ListItemText primary={item.value} />
213
+ </ListItem>
214
+ ))}
215
+ </List>
216
+ </Drawer>
217
+
218
+ {props.enabled && (
219
+ <div
220
+ style={{
221
+ position: 'fixed',
222
+ right: '5px',
223
+ bottom: mediaIsMobile ? '40px' : '25px',
224
+ display: 'flex',
225
+ flexDirection: 'column',
226
+ gap: '5px',
227
+ zIndex: 3000,
228
+ }}
229
+ >
230
+ <IconButton
231
+ onClick={handleClick}
232
+ style={{
233
+ backgroundColor: '#cbd300',
234
+ }}
235
+ size="large"
236
+ >
237
+ <FileCopy />
238
+ </IconButton>
239
+ <IconButton
240
+ onClick={toogleDrawer}
241
+ style={{
242
+ backgroundColor: '#cbd300',
243
+ }}
244
+ size="large"
245
+ >
246
+ <InfoIcon />
247
+ </IconButton>
248
+ </div>
249
+ )}
250
+ </>
251
+ );
252
+ };
253
+
254
+ export default MlGPXDemoLoader;
@@ -0,0 +1,102 @@
1
+ import React, { useRef, useEffect } from 'react';
2
+ import MlGeoJsonLayer from './MlGeoJsonLayer';
3
+ import useMap from '../../hooks/useMap';
4
+ import mapContextDecorator from '../../decorators/MapContextDecorator';
5
+ import PolygonStyler from './story_utils/MlGeoJsonLayer.polygonStyler';
6
+ import LineStyler from './story_utils/MlGeoJsonLayer.lineStyler';
7
+ import sample_geojson_1 from './assets/sample_1.json';
8
+ import sample_geojson_2 from './assets/sample_2.json';
9
+ import { GeoJSONObject } from '@turf/turf';
10
+
11
+ const storyoptions = {
12
+ title: 'MapComponents/MlGeoJsonLayer',
13
+ component: MlGeoJsonLayer,
14
+
15
+ argTypes: {},
16
+
17
+ decorators: mapContextDecorator,
18
+ };
19
+ export default storyoptions;
20
+
21
+ interface TemplateProps {
22
+ geojson: GeoJSONObject;
23
+ mapId: string;
24
+ type: string;
25
+ }
26
+
27
+ const Template = (props: TemplateProps) => {
28
+ const mapHook = useMap({
29
+ mapId: undefined,
30
+ });
31
+
32
+ const initializedRef = useRef(false);
33
+
34
+ useEffect(() => {
35
+ if (!mapHook.map || initializedRef.current) return;
36
+
37
+ initializedRef.current = true;
38
+ mapHook.map.map.flyTo({ center: [7.100175528281227, 50.73487992742369], zoom: 15 });
39
+ }, [mapHook.map]);
40
+
41
+ return (
42
+ <>
43
+ <LineStyler {...props} />
44
+ </>
45
+ );
46
+ };
47
+ const PolygonTemplate = (props: TemplateProps) => {
48
+ const mapHook = useMap({
49
+ mapId: undefined,
50
+ });
51
+
52
+ const initializedRef = useRef(false);
53
+
54
+ useEffect(() => {
55
+ if (!mapHook.map || initializedRef.current) return;
56
+
57
+ initializedRef.current = true;
58
+ mapHook.map.map.flyTo({ center: [7.100175528281227, 50.73487992742369], zoom: 15 });
59
+ }, [mapHook.map]);
60
+
61
+ return (
62
+ <>
63
+ <PolygonStyler {...props} />
64
+ </>
65
+ );
66
+ };
67
+
68
+ export const Linestring = Template.bind({});
69
+ Linestring.parameters = {};
70
+ Linestring.args = {
71
+ geojson: sample_geojson_2,
72
+ mapId: 'Map_1',
73
+ /*paint:{
74
+ "stroke-color": 'rgba(123,20,80)',
75
+ "fill-opacity": 0
76
+ },*/
77
+ type: 'line',
78
+ };
79
+
80
+ export const Polygon = PolygonTemplate.bind({});
81
+
82
+ Polygon.args = {
83
+ geojson: sample_geojson_1,
84
+ };
85
+
86
+ export const DefaultPaintOverrides = Template.bind({});
87
+ DefaultPaintOverrides.parameters = {};
88
+ DefaultPaintOverrides.args = {
89
+ defaultPaintOverrides: {
90
+ fill: {
91
+ 'fill-color': 'blue',
92
+ },
93
+ circle: {
94
+ 'circle-color': 'red',
95
+ },
96
+ line: {
97
+ 'line-color': 'black',
98
+ },
99
+ },
100
+ geojson: sample_geojson_1,
101
+ type: '',
102
+ };
@@ -1,15 +1,20 @@
1
- import React from "react";
1
+ import React from 'react';
2
2
 
3
- import useLayer from "../../hooks/useLayer";
3
+ import useLayer from '../../hooks/useLayer';
4
4
 
5
- import { v4 as uuidv4 } from "uuid";
5
+ import { v4 as uuidv4 } from 'uuid';
6
6
 
7
- import getDefaultPaintPropsByType from "./util/getDefaultPaintPropsByType";
8
- import getDefaulLayerTypeByGeometry from "./util/getDefaultLayerTypeByGeometry";
9
- import { Feature, FeatureCollection } from "@turf/turf";
7
+ import getDefaultPaintPropsByType from './util/getDefaultPaintPropsByType';
8
+ import getDefaulLayerTypeByGeometry from './util/getDefaultLayerTypeByGeometry';
9
+ import { Feature, FeatureCollection } from '@turf/turf';
10
10
 
11
-
12
- import { LineLayerSpecification, CircleLayerSpecification, FillLayerSpecification,MapLayerMouseEvent, LayerSpecification } from "maplibre-gl";
11
+ import {
12
+ LineLayerSpecification,
13
+ CircleLayerSpecification,
14
+ FillLayerSpecification,
15
+ MapLayerMouseEvent,
16
+ LayerSpecification,
17
+ } from 'maplibre-gl';
13
18
 
14
19
  type MlGeoJsonLayerProps = {
15
20
  /**
@@ -19,7 +24,7 @@ type MlGeoJsonLayerProps = {
19
24
  /**
20
25
  * Id of an existing layer in the mapLibre instance to help specify the layer order
21
26
  * This layer will be visually beneath the layer with the "insertBeforeLayer" id.
22
- * This layer will not be added to the maplibre-gl instance until a layer with an
27
+ * This layer will not be added to the maplibre-gl instance until a layer with an
23
28
  * id that matches the value of insertBeforeLayer is created.
24
29
  */
25
30
  insertBeforeLayer?: string;
@@ -35,7 +40,7 @@ type MlGeoJsonLayerProps = {
35
40
  * Type of the layer that will be added to the MapLibre instance.
36
41
  * Possible values: "line", "circle", "fill"
37
42
  */
38
- type?: "fill" | "line" | "circle";
43
+ type?: 'fill' | 'line' | 'circle';
39
44
  /**
40
45
  * Paint property object, that is passed to the addLayer call.
41
46
  * Possible props depend on the layer type.
@@ -43,7 +48,10 @@ type MlGeoJsonLayerProps = {
43
48
  * https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#circle
44
49
  * https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#fill
45
50
  */
46
- paint?: CircleLayerSpecification['paint'] | FillLayerSpecification['paint'] | LineLayerSpecification['paint'];
51
+ paint?:
52
+ | CircleLayerSpecification['paint']
53
+ | FillLayerSpecification['paint']
54
+ | LineLayerSpecification['paint'];
47
55
  /**
48
56
  * Layout property object, that is passed to the addLayer call.
49
57
  * Possible props depend on the layer type.
@@ -51,7 +59,10 @@ type MlGeoJsonLayerProps = {
51
59
  * https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#circle
52
60
  * https://maplibre.org/maplibre-gl-js-docs/style-spec/layers/#fill
53
61
  */
54
- layout?: CircleLayerSpecification['layout'] | FillLayerSpecification['layout'] | LineLayerSpecification['layout'];
62
+ layout?:
63
+ | CircleLayerSpecification['layout']
64
+ | FillLayerSpecification['layout']
65
+ | LineLayerSpecification['layout'];
55
66
  /**
56
67
  * Javascript object that is spread into the addLayer commands first parameter.
57
68
  */
@@ -59,7 +70,11 @@ type MlGeoJsonLayerProps = {
59
70
  /**
60
71
  * Javascript object with optional properties "fill", "line", "circle" to override implicit layer type default paint properties.
61
72
  */
62
- defaultPaintOverrides?: { circle?: CircleLayerSpecification['paint'], fill?: FillLayerSpecification['paint'], line?: LineLayerSpecification['paint'] };
73
+ defaultPaintOverrides?: {
74
+ circle?: CircleLayerSpecification['paint'];
75
+ fill?: FillLayerSpecification['paint'];
76
+ line?: LineLayerSpecification['paint'];
77
+ };
63
78
  /**
64
79
  * Hover event handler that is executed whenever a geometry rendered by this component is hovered.
65
80
  */
@@ -73,27 +88,23 @@ type MlGeoJsonLayerProps = {
73
88
  * left/unhovered.
74
89
  */
75
90
  onLeave?: MapLayerMouseEvent;
76
- }
91
+ };
77
92
 
78
93
  /**
79
94
  * Adds source and layer of types "line", "fill" or "circle" to display GeoJSON data on the map.
80
95
  *
81
96
  * @component
82
97
  */
98
+
83
99
  const MlGeoJsonLayer = (props: MlGeoJsonLayerProps) => {
84
100
  const layerType = props.type || getDefaulLayerTypeByGeometry(props.geojson);
85
101
  // Use a useRef hook to reference the layer object to be able to access it later inside useEffect hooks
86
102
  useLayer({
87
103
  mapId: props.mapId,
88
- layerId: props.layerId || "MlGeoJsonLayer-" + uuidv4(),
104
+ layerId: props.layerId || 'MlGeoJsonLayer-' + uuidv4(),
89
105
  geojson: props.geojson,
90
106
  options: {
91
- paint:
92
- props.paint ||
93
- getDefaultPaintPropsByType(
94
- layerType,
95
- props.defaultPaintOverrides
96
- ),
107
+ paint: props.paint || getDefaultPaintPropsByType(layerType, props.defaultPaintOverrides),
97
108
  layout: props.layout || {},
98
109
  ...props.options,
99
110
  type: layerType as LayerSpecification['type'],
@@ -104,8 +115,7 @@ const MlGeoJsonLayer = (props: MlGeoJsonLayerProps) => {
104
115
  onLeave: props.onLeave,
105
116
  });
106
117
 
107
- return (<></>);
118
+ return <></>;
108
119
  };
109
120
 
110
-
111
121
  export default MlGeoJsonLayer;
@@ -1,26 +1,140 @@
1
1
  {
2
- "type": "Feature",
3
- "properties": {},
4
- "geometry": {
5
- "type": "LineString",
6
- "coordinates": [
7
- [7.1074676513671875, 50.74340774029213],
8
- [7.0992279052734375, 50.756441089372665],
9
- [7.079315185546874, 50.764693667025014],
10
- [7.045669555664062, 50.77945780529241],
11
- [7.030563354492187, 50.79161300845443],
12
- [7.0291900634765625, 50.80940599750376],
13
- [7.0236968994140625, 50.820685846099174],
14
- [7.0085906982421875, 50.825891011253546],
15
- [6.9879913330078125, 50.826758482363275],
16
- [6.97906494140625, 50.835432306955276],
17
- [6.9824981689453125, 50.84583876895451],
18
- [6.9962310791015625, 50.85147463352982],
19
- [7.012023925781249, 50.85710981721644],
20
- [7.021636962890625, 50.86664473085768],
21
- [7.0367431640625, 50.872278081520406],
22
- [7.0477294921875, 50.877044231111014],
23
- [7.052536010742187, 50.88397594225127]
24
- ]
25
- }
2
+ "type": "FeatureCollection",
3
+ "features": [
4
+ {
5
+ "id": "1",
6
+ "type": "Feature",
7
+ "properties": { "name": "Hofgarten" },
8
+ "geometry": {
9
+ "coordinates": [
10
+ [
11
+ [7.104246282215286, 50.734109601136055],
12
+ [7.10209443365315, 50.732370465826534],
13
+ [7.104720792410859, 50.73113417375197],
14
+ [7.1049635650692835, 50.73112718895845],
15
+ [7.105724988405626, 50.73137864087451],
16
+ [7.107071273146147, 50.73179073970729],
17
+ [7.107060238024758, 50.73190249469832],
18
+ [7.106629868312979, 50.732552065303736],
19
+ [7.104246282215286, 50.734109601136055]
20
+ ]
21
+ ],
22
+ "type": "Polygon"
23
+ }
24
+ },
25
+ {
26
+ "id": "2",
27
+ "type": "Feature",
28
+ "properties": { "name": "Stadtgarten" },
29
+ "geometry": {
30
+ "coordinates": [
31
+ [
32
+ [7.105893155288783, 50.73444907786518],
33
+ [7.106402034397206, 50.733582900352985],
34
+ [7.106897536862704, 50.73369549309848],
35
+ [7.107111352729277, 50.7336105803617],
36
+ [7.107157469878132, 50.733549549237495],
37
+ [7.108406816456494, 50.733927190803854],
38
+ [7.1084747528756225, 50.73402627417772],
39
+ [7.10853382802236, 50.734039360645426],
40
+ [7.1083093424639685, 50.73448242889327],
41
+ [7.108247313560071, 50.73447868993853],
42
+ [7.108226637258156, 50.734508601570155],
43
+ [7.107907631465423, 50.734559077405464],
44
+ [7.107694960936584, 50.73457777214577],
45
+ [7.107597486944087, 50.734575902671935],
46
+ [7.107576810643138, 50.73462077001935],
47
+ [7.108185284655264, 50.734633856320954],
48
+ [7.108087810663733, 50.73492362349066],
49
+ [7.107910600755304, 50.734888120981594],
50
+ [7.107875467179866, 50.734952050517165],
51
+ [7.107778849851883, 50.73496038914578],
52
+ [7.107682232521427, 50.734963168688125],
53
+ [7.10769979930771, 50.7350132004259],
54
+ [7.107339680163761, 50.73499652318577],
55
+ [7.107221104348952, 50.73497706639833],
56
+ [7.107278196408828, 50.73488534143442],
57
+ [7.107019086291899, 50.73484364820982],
58
+ [7.106988344414447, 50.734927034622416],
59
+ [7.106514041150831, 50.73484364820982],
60
+ [7.106606266786173, 50.734604606338195],
61
+ [7.105893155288783, 50.73444907786518]
62
+ ]
63
+ ],
64
+ "type": "Polygon"
65
+ }
66
+ },
67
+ {
68
+ "id": "3",
69
+ "type": "Feature",
70
+ "properties": { "name": "Opernplatz" },
71
+ "geometry": {
72
+ "coordinates": [
73
+ [
74
+ [7.104632320011916, 50.736606042555366],
75
+ [7.104779316251751, 50.736422797521044],
76
+ [7.104817178920001, 50.7363283555695],
77
+ [7.104868404882268, 50.736319898072],
78
+ [7.105434117684382, 50.73653415420432],
79
+ [7.105596704435243, 50.736569393605805],
80
+ [7.105797153853388, 50.73659758510803],
81
+ [7.105725882948974, 50.73684848872955],
82
+ [7.105338347406786, 50.736800563422435],
83
+ [7.1051824423039704, 50.73677237204271],
84
+ [7.104863950451204, 50.73668356908482],
85
+ [7.104632320011916, 50.736606042555366]
86
+ ]
87
+ ],
88
+ "type": "Polygon"
89
+ }
90
+ },
91
+ {
92
+ "id": "2c3972ac51f4350582ecc9de57d47c75",
93
+ "type": "Feature",
94
+ "properties": { "name": "Keiserplatz" },
95
+ "geometry": {
96
+ "coordinates": [
97
+ [
98
+ [7.100878520474112, 50.73167947463554],
99
+ [7.100876728417518, 50.731653654340704],
100
+ [7.100857282327439, 50.731633541894354],
101
+ [7.10079841102764, 50.73157086579248],
102
+ [7.100757419228046, 50.731538946883745],
103
+ [7.100606042670478, 50.73140800018959],
104
+ [7.100525308506718, 50.73136967425927],
105
+ [7.10037393194915, 50.731331348297005],
106
+ [7.100313381326117, 50.731308991470826],
107
+ [7.100267968358821, 50.73127226237719],
108
+ [7.100184711252609, 50.73119561026192],
109
+ [7.099690214497514, 50.73138724031432],
110
+ [7.099691475969678, 50.73140400766788],
111
+ [7.099861143861631, 50.73141398829278],
112
+ [7.0998571229209375, 50.73145675554436],
113
+ [7.099832918440285, 50.73150591044205],
114
+ [7.099780384599569, 50.73155556557083],
115
+ [7.099892082101547, 50.73155547486934],
116
+ [7.099882074627317, 50.73158758317477],
117
+ [7.0999202108099695, 50.73158998765363],
118
+ [7.099912858928455, 50.73159899760262],
119
+ [7.0999207681442975, 50.73160353227202],
120
+ [7.099921690047621, 50.7316057996082],
121
+ [7.099930036031913, 50.73160923675198],
122
+ [7.100091909667459, 50.731627463555895],
123
+ [7.100165737828326, 50.731649680201066],
124
+ [7.1003014331650665, 50.731709520224214],
125
+ [7.100316426855426, 50.73173557596814],
126
+ [7.100384577793838, 50.73178469147469],
127
+ [7.100415620558475, 50.731796580130755],
128
+ [7.100494222199336, 50.7318078992016],
129
+ [7.100585685541193, 50.731804728779615],
130
+ [7.100677188738862, 50.73177247244158],
131
+ [7.100842140282873, 50.73170978389162],
132
+ [7.100873170896176, 50.73169013008063],
133
+ [7.100878520474112, 50.73167947463554]
134
+ ]
135
+ ],
136
+ "type": "Polygon"
137
+ }
138
+ }
139
+ ]
26
140
  }