@mapcomponents/react-maplibre 0.1.61 → 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 (197) 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 +23 -0
  6. package/coverage/clover.xml +265 -89
  7. package/coverage/coverage-final.json +14 -6
  8. package/coverage/lcov-report/favicon.png +0 -0
  9. package/coverage/lcov-report/index.html +84 -39
  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 +2 -8
  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 +11 -11
  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 +14 -14
  94. package/coverage/lcov-report/src/hooks/useExportMap/index.ts.html +1 -1
  95. package/coverage/lcov-report/src/hooks/useExportMap/lib.ts.html +21 -108
  96. package/coverage/lcov-report/src/hooks/useLayer.ts.html +1 -1
  97. package/coverage/lcov-report/src/hooks/useLayerEvent.js.html +9 -9
  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 +5 -2
  104. package/coverage/lcov.info +564 -161
  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/MlCreatePdfForm.stories.d.ts +1 -0
  113. package/dist/components/MlCreatePdfForm/lib/PdfContext.d.ts +3 -16
  114. package/dist/components/MlCreatePdfForm/lib/PdfPreview.d.ts +19 -6
  115. package/dist/components/MlCreatePdfForm/lib/_PdfPreview.d.ts +13 -0
  116. package/dist/components/MlFeatureEditor/MlFeatureEditor.d.ts +10 -4
  117. package/dist/components/MlFeatureEditor/lib/double_click_zoom.d.ts +0 -2
  118. package/dist/components/MlFeatureEditor/lib/theme.d.ts +1 -1
  119. package/dist/components/MlGPXViewer/util/GeoJsonContext.d.ts +1 -1
  120. package/dist/components/MlGPXViewer/util/MlGPXViewerInstructions.d.ts +1 -0
  121. package/dist/components/MlGPXViewer/util/SampleLayer.d.ts +0 -0
  122. package/dist/components/MlGPXViewer/util/demoViewer.d.ts +5 -0
  123. package/dist/components/MlGeoJsonLayer/MlGeoJsonLayer.d.ts +4 -4
  124. package/dist/components/MlGeoJsonLayer/MlGeoJsonLayer.stories.d.ts +103 -11
  125. package/dist/components/MlGeoJsonLayer/story_utils/MlGeoJsonLayer.lineStyler.d.ts +2 -0
  126. package/dist/components/MlGeoJsonLayer/story_utils/MlGeoJsonLayer.polygonStyler.d.ts +2 -0
  127. package/dist/components/MlSketchTool/LayerList/ColorPicker.d.ts +9 -0
  128. package/dist/components/MlSketchTool/LayerList/LayerList.d.ts +5 -0
  129. package/dist/components/MlSketchTool/LayerList/LayerListItem.d.ts +11 -0
  130. package/dist/components/MlSketchTool/LayerList/LayerPropertyForm.d.ts +9 -0
  131. package/dist/components/MlSketchTool/MlSketchTool.d.ts +29 -0
  132. package/dist/components/MlSketchTool/MlSketchTool.stories.d.ts +10 -0
  133. package/dist/contexts/SimpleDataProvider.d.ts +1 -1
  134. package/dist/custom.d.d.ts +1 -1
  135. package/dist/hooks/useLayer.d.ts +1 -1
  136. package/dist/hooks/useMap.d.ts +1 -1
  137. package/dist/hooks/useMapState.d.ts +3 -3
  138. package/dist/hooks/useSource.d.ts +1 -1
  139. package/dist/index.d.ts +1 -0
  140. package/dist/index.esm.css +1 -1
  141. package/dist/index.esm.js +3473 -4386
  142. package/dist/index.esm.js.map +1 -1
  143. package/dist/ui_components/LoadingOverlayContext.d.ts +1 -1
  144. package/dist/ui_components/Sidebar.d.ts +9 -1
  145. package/dist/ui_components/TopToolbar.d.ts +6 -1
  146. package/package.json +22 -15
  147. package/public/assets/sample1.gpx +3003 -0
  148. package/public/assets/sample2.gpx +1264 -0
  149. package/public/assets/sample3.gpx +912 -0
  150. package/public/index.html +0 -4
  151. package/public/thumbnails/MlSketchTool.png +0 -0
  152. package/public/thumbnails/useCameraFollowPath.png +0 -0
  153. package/src/components/MlCreatePdfForm/MlCreatePdfForm.cy.tsx +21 -0
  154. package/src/components/MlCreatePdfForm/MlCreatePdfForm.stories.tsx +14 -1
  155. package/src/components/MlCreatePdfForm/MlCreatePdfForm.tsx +0 -2
  156. package/src/components/MlCreatePdfForm/lib/PdfContext.tsx +16 -18
  157. package/src/components/MlCreatePdfForm/lib/PdfForm.tsx +79 -6
  158. package/src/components/MlCreatePdfForm/lib/PdfPreview.tsx +285 -357
  159. package/src/components/MlCreatePdfForm/lib/_PdfPreview.tsx +399 -0
  160. package/src/components/MlCreatePdfForm/lib/pdfContext.d.ts +24 -0
  161. package/src/components/MlCreatePdfForm/lib/preview.css +114 -0
  162. package/src/components/MlFeatureEditor/MlFeatureEditor.meta.json +1 -1
  163. package/src/components/MlFeatureEditor/MlFeatureEditor.tsx +39 -28
  164. package/src/components/MlGPXViewer/MlGPXViewer.stories.js +75 -15
  165. package/src/components/MlGPXViewer/MlGPXViewer.tsx +3 -1
  166. package/src/components/MlGPXViewer/util/MlGPXViewerInstructions.js +145 -0
  167. package/src/components/MlGPXViewer/util/SampleLayer.js +2 -0
  168. package/src/components/MlGPXViewer/util/demoViewer.js +254 -0
  169. package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.stories.tsx +102 -0
  170. package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.tsx +33 -23
  171. package/src/components/MlGeoJsonLayer/assets/sample_1.json +138 -24
  172. package/src/components/MlGeoJsonLayer/assets/sample_2.json +140 -20
  173. package/src/components/MlGeoJsonLayer/story_utils/MlGeoJsonLayer.lineStyler.js +189 -0
  174. package/src/components/MlGeoJsonLayer/story_utils/MlGeoJsonLayer.polygonStyler.js +188 -0
  175. package/src/components/MlSketchTool/LayerList/ColorPicker.tsx +43 -0
  176. package/src/components/MlSketchTool/LayerList/LayerList.tsx +12 -0
  177. package/src/components/MlSketchTool/LayerList/LayerListItem.tsx +109 -0
  178. package/src/components/MlSketchTool/LayerList/LayerPropertyForm.tsx +126 -0
  179. package/src/components/MlSketchTool/MlSketchTool.doc.de.md +3 -0
  180. package/src/components/MlSketchTool/MlSketchTool.meta.json +15 -0
  181. package/src/components/MlSketchTool/MlSketchTool.stories.js +26 -0
  182. package/src/components/MlSketchTool/MlSketchTool.tsx +271 -0
  183. package/src/components/MlTransitionGeoJsonLayer/MlTransitionGeoJsonLayer.meta.json +2 -2
  184. package/src/hooks/useExportMap/lib.ts +14 -43
  185. package/src/index.ts +1 -0
  186. package/src/ui_components/Sidebar.tsx +80 -0
  187. package/src/ui_components/TopToolbar.tsx +24 -0
  188. package/tsconfig.json +39 -58
  189. package/config/getHttpsConfig.js +0 -66
  190. package/config/modules.js +0 -134
  191. package/config/pnpTs.js +0 -35
  192. package/config/webpack.config.js +0 -757
  193. package/config/webpackDevServer.config.js +0 -130
  194. package/scripts/start.js +0 -166
  195. package/src/components/MlGeoJsonLayer/MlGeoJsonLayer.stories.js +0 -66
  196. package/src/ui_components/Sidebar.js +0 -100
  197. package/src/ui_components/TopToolbar.js +0 -29
@@ -0,0 +1,188 @@
1
+ import React, { useState, useMemo } from 'react';
2
+ import Sidebar from '../../../ui_components/Sidebar';
3
+ import { Select, Typography, Slider, Stack, MenuItem, FormControl } from '@mui/material';
4
+ import { ColorPicker } from 'mui-color';
5
+ import MlGeoJsonLayer from '../MlGeoJsonLayer';
6
+
7
+ /*
8
+ const FeatureNames = () => {
9
+ const names = ['Show all', 'Hofgarten', 'Stadtgarten', 'Opernplatz', 'Keiserplatz'];
10
+ return names.map((item) => {
11
+ console.log(item);
12
+ return (
13
+ <>
14
+ <MenuItem key={item} value={`"${item}"`}>
15
+ {item}
16
+ </MenuItem>
17
+ </>
18
+ );
19
+ });
20
+ };
21
+ */
22
+
23
+ const marks = [
24
+ {
25
+ value: 0,
26
+ label: '0%',
27
+ },
28
+ {
29
+ value: 0.25,
30
+ label: '25%',
31
+ },
32
+ {
33
+ value: 0.5,
34
+ label: '50%',
35
+ },
36
+ {
37
+ value: 0.75,
38
+ label: '75%',
39
+ },
40
+ {
41
+ value: 1,
42
+ label: '100%',
43
+ },
44
+ ];
45
+
46
+ const widthMarks = [
47
+ {
48
+ value: 0,
49
+ label: '0',
50
+ },
51
+ {
52
+ value: 5,
53
+ label: '5',
54
+ },
55
+ {
56
+ value: 10,
57
+ label: '10',
58
+ },
59
+ ];
60
+
61
+ const PolygonStyler = (props) => {
62
+ const [color, setColor] = useState('#2485C1');
63
+ const [opacity, setOpacity] = useState(0.8);
64
+ const [featureToShow, setFeatureToShow] = useState('Show all');
65
+ const [geomType, setGeomType] = useState('fill');
66
+ const [lineWidth, setLineWidth] = useState(6);
67
+
68
+ const storyGeoJson = useMemo(() => {
69
+ if (featureToShow === 'Show all') {
70
+ return props.geojson;
71
+ }
72
+ return {
73
+ type: 'FeatureCollection',
74
+ features: props.geojson.features.filter((item) => item.properties.name === featureToShow),
75
+ };
76
+ }, [featureToShow, props.geojson]);
77
+
78
+ const handleColorChange = (e) => {
79
+ setColor(`#${e.hex}`);
80
+ };
81
+
82
+ return (
83
+ <>
84
+ <Sidebar>
85
+ <Stack paddingTop={5} spacing={3} direction="column" sx={{ mb: 1 }} alignItems="left">
86
+ <FormControl>
87
+ <Typography>Geometry type:</Typography>
88
+ <Select
89
+ value={geomType}
90
+ onChange={(e) => {
91
+ setGeomType(e.target.value);
92
+ console.log(e.target.value);
93
+ }}
94
+ >
95
+ <MenuItem value={'fill'} key={1}>
96
+ fill
97
+ </MenuItem>
98
+ <MenuItem value={'circle'} key={2}>
99
+ circle
100
+ </MenuItem>
101
+ <MenuItem value={'line'} key={3}>
102
+ line
103
+ </MenuItem>
104
+ </Select>
105
+ </FormControl>
106
+ <Typography>Feature to show:</Typography>
107
+ <FormControl>
108
+ <Select
109
+ value={featureToShow}
110
+ onChange={(e) => {
111
+ setFeatureToShow(e.target.value);
112
+ console.log(e.target.value);
113
+ }}
114
+ >
115
+ <MenuItem value={'Show all'} key={1}>
116
+ Show all
117
+ </MenuItem>
118
+ <MenuItem value={'Hofgarten'} key={2}>
119
+ Hofgarten
120
+ </MenuItem>
121
+ <MenuItem value={'Stadtgarten'} key={3}>
122
+ Stadtgarten
123
+ </MenuItem>
124
+ <MenuItem value={'Opernplatz'} key={4}>
125
+ Opernplatz
126
+ </MenuItem>
127
+ <MenuItem value={'Keiserplatz'} key={5}>
128
+ Keiserplatz
129
+ </MenuItem>
130
+ </Select>
131
+ </FormControl>
132
+ <Typography>Display color:</Typography>
133
+ <ColorPicker value={color} onChange={handleColorChange} />
134
+
135
+ <Typography>Opacity:</Typography>
136
+ <Slider
137
+ defaultValue={1}
138
+ aria-label="Default"
139
+ value={opacity}
140
+ max={1}
141
+ min={0}
142
+ step={0.01}
143
+ marks={marks}
144
+ onChange={(e) => {
145
+ setOpacity(e.target.value);
146
+ console.log(e);
147
+ }}
148
+ />
149
+ <Typography paddingTop={4}>Stroke:</Typography>
150
+ <Slider
151
+ value={lineWidth}
152
+ aria-label="Default"
153
+ max={10}
154
+ min={0}
155
+ step={1}
156
+ marks={widthMarks}
157
+ onChange={(e) => {
158
+ setLineWidth(e.target.value);
159
+ }}
160
+ disabled={geomType !== 'line'}
161
+ />
162
+ </Stack>
163
+ </Sidebar>
164
+
165
+ <MlGeoJsonLayer
166
+ geojson={storyGeoJson}
167
+ defaultPaintOverrides={{
168
+ fill: {
169
+ 'fill-color': color,
170
+ 'fill-opacity': opacity,
171
+ },
172
+ circle: {
173
+ 'circle-color': color,
174
+ 'circle-opacity': opacity,
175
+ },
176
+ line: {
177
+ 'line-color': color,
178
+ 'line-opacity': opacity,
179
+ 'line-width': lineWidth,
180
+ },
181
+ }}
182
+ type={geomType}
183
+ />
184
+ </>
185
+ );
186
+ };
187
+
188
+ export default PolygonStyler;
@@ -0,0 +1,43 @@
1
+ import { ColorPicker } from 'mui-color';
2
+ import React from 'react';
3
+ import { paintPropsType } from './LayerPropertyForm';
4
+
5
+ type Props = {
6
+ key: string;
7
+ value: string;
8
+ propKey: string;
9
+ setPaintProps: (
10
+ paintProps: paintPropsType | ((current: paintPropsType) => paintPropsType)
11
+ ) => void;
12
+ };
13
+
14
+ export default function PaintPropsColorPicker({ propKey, value, setPaintProps }: Props) {
15
+ return (
16
+ <ColorPicker
17
+ value={value}
18
+ onChange={(value: any) => {
19
+ setPaintProps((current: paintPropsType): paintPropsType => {
20
+ if (!value?.rgb?.[0]) {
21
+ return current;
22
+ }
23
+
24
+ const newProps = {
25
+ ...current,
26
+ [propKey]:
27
+ 'rgba(' +
28
+ value.rgb[0] +
29
+ ',' +
30
+ value.rgb[1] +
31
+ ',' +
32
+ value.rgb[2] +
33
+ ',' +
34
+ value.alpha +
35
+ ')',
36
+ };
37
+
38
+ return newProps;
39
+ });
40
+ }}
41
+ />
42
+ );
43
+ }
@@ -0,0 +1,12 @@
1
+ import { List } from '@mui/material';
2
+ import React from 'react';
3
+
4
+ type Props = {
5
+ children: JSX.Element;
6
+ };
7
+
8
+ function LayerList({ children }: Props) {
9
+ return <List>{children}</List>;
10
+ }
11
+
12
+ export default LayerList;
@@ -0,0 +1,109 @@
1
+ import { Checkbox, IconButton, ListItem, ListItemIcon, ListItemText } from '@mui/material';
2
+ import TuneIcon from '@mui/icons-material/Tune';
3
+ import React, { useMemo, useState } from 'react';
4
+ import getDefaulLayerTypeByGeometry from '../../../components/MlGeoJsonLayer/util/getDefaultLayerTypeByGeometry';
5
+ import getDefaultPaintPropsByType from '../../../components/MlGeoJsonLayer/util/getDefaultPaintPropsByType';
6
+ import LayerPropertyForm from './LayerPropertyForm';
7
+
8
+ type Props = {
9
+ layerComponent: JSX.Element;
10
+ visible: boolean;
11
+ configurable: boolean;
12
+ type?: 'background' | 'background-labels' | 'layer' | 'wms-layer' | 'vector-tile-layer';
13
+ name: string;
14
+ description?: string;
15
+ additionalButtons?: JSX.Element;
16
+ };
17
+
18
+ function LayerListItem({
19
+ layerComponent,
20
+ visible = true,
21
+ type = 'layer',
22
+ name,
23
+ description,
24
+ configurable,
25
+ }: Props) {
26
+ const [localVisible, setLocalVisible] = useState(true);
27
+ const [paintPropsFormVisible, setPaintPropsFormVisible] = useState(false);
28
+ const [paintProps, setPaintProps] = useState(
29
+ layerComponent?.props?.paint ||
30
+ getDefaultPaintPropsByType(
31
+ layerComponent?.props?.type || getDefaulLayerTypeByGeometry(layerComponent.props.geojson)
32
+ )
33
+ );
34
+
35
+ const _visible = useMemo(() => {
36
+ if (!visible) {
37
+ return false;
38
+ }
39
+ return localVisible;
40
+ }, [visible, localVisible]);
41
+
42
+ const _layerComponent = useMemo(() => {
43
+ if (type === 'layer') {
44
+ return React.cloneElement(layerComponent, {
45
+ layout: {
46
+ visibility: _visible ? 'visible' : 'none',
47
+ },
48
+ paint: paintProps,
49
+ });
50
+ }
51
+ return <></>;
52
+ }, [type, layerComponent, paintProps, _visible]);
53
+
54
+ const layerType = useMemo(() => {
55
+ if (type === 'layer') {
56
+ if (layerComponent.props.type) {
57
+ return layerComponent.props.type;
58
+ }
59
+ if (layerComponent.props.geojson) {
60
+ return getDefaulLayerTypeByGeometry(layerComponent.props.geojson);
61
+ }
62
+ }
63
+
64
+ return undefined;
65
+ }, [layerComponent]);
66
+
67
+ return (
68
+ <>
69
+ <ListItem
70
+ secondaryAction={
71
+ configurable ? (
72
+ <IconButton
73
+ edge="end"
74
+ aria-label="comments"
75
+ onClick={() => {
76
+ setPaintPropsFormVisible((current) => {
77
+ return !current;
78
+ });
79
+ }}
80
+ >
81
+ <TuneIcon />
82
+ </IconButton>
83
+ ) : undefined
84
+ }
85
+ >
86
+ <ListItemIcon>
87
+ <Checkbox
88
+ disabled={!visible}
89
+ checked={localVisible}
90
+ onClick={() => {
91
+ setLocalVisible((val) => !val);
92
+ }}
93
+ />
94
+ </ListItemIcon>
95
+ <ListItemText primary={name} secondary={description} />
96
+ {_layerComponent}
97
+ </ListItem>
98
+ {configurable && paintPropsFormVisible && (
99
+ <LayerPropertyForm
100
+ paintProps={paintProps}
101
+ setPaintProps={setPaintProps}
102
+ layerType={layerType}
103
+ />
104
+ )}
105
+ </>
106
+ );
107
+ }
108
+
109
+ export default LayerListItem;
@@ -0,0 +1,126 @@
1
+ import {
2
+ CircleLayerSpecification,
3
+ FillLayerSpecification,
4
+ LineLayerSpecification,
5
+ } from 'maplibre-gl';
6
+ import React, { useRef } from 'react';
7
+ import ColorPicker from './ColorPicker';
8
+ import { ListItem, Slider, TextField, Typography } from '@mui/material';
9
+ import { Box } from '@mui/system';
10
+
11
+ export type paintPropsType =
12
+ | CircleLayerSpecification['paint']
13
+ | FillLayerSpecification['paint']
14
+ | LineLayerSpecification['paint'];
15
+
16
+ type Props = {
17
+ paintProps: paintPropsType;
18
+ setPaintProps: (
19
+ paintProps: paintPropsType | ((current: paintPropsType) => paintPropsType)
20
+ ) => void;
21
+ layerType: string;
22
+ };
23
+
24
+ const mapLayerTypeToPaintProps = {
25
+ circle: ['circle-color'],
26
+ line: ['line-color', 'line-width', 'line-blur'],
27
+ fill: ['fill-color'],
28
+ };
29
+ const mapPropKeyToFormInputType = {
30
+ 'line-color': 'colorpicker',
31
+ 'line-width': 'slider',
32
+ 'line-blur': 'slider',
33
+ 'fill-color': 'colorpicker',
34
+ 'circle-color': 'colorpicker',
35
+ };
36
+ const mapPropKeyToFormInputTypeKeys = Object.keys(mapPropKeyToFormInputType);
37
+
38
+ const inputPropsByPropKey = {
39
+ 'line-blur': {
40
+ step: 1,
41
+ min: 1,
42
+ max: 100,
43
+ },
44
+ 'line-width': {
45
+ step: 1,
46
+ min: 1,
47
+ max: 100,
48
+ },
49
+ };
50
+
51
+ export default function LayerPropertyForm({ paintProps = {}, setPaintProps }: Props) {
52
+ const key = useRef(Math.round(Math.random() * 10000000000));
53
+ //const onChange = (event) => {};
54
+
55
+ const getFormInputByType = (key: string, value: any) => {
56
+ if (mapPropKeyToFormInputTypeKeys.indexOf(key) !== -1) {
57
+ const label = (
58
+ <Typography id={key + '_label'} gutterBottom>
59
+ {key}
60
+ </Typography>
61
+ );
62
+ switch (mapPropKeyToFormInputType[key]) {
63
+ case 'slider':
64
+ return (
65
+ <>
66
+ {label}
67
+ <Slider
68
+ {...inputPropsByPropKey[key]}
69
+ inputProps={{ inputMode: 'decimal', pattern: '[0-9]*' }}
70
+ value={paintProps[key]}
71
+ onChange={(ev: Event, value: number, activeThumb) => {
72
+ if (value) {
73
+ setPaintProps((current) => ({ ...current, [key]: value }));
74
+ }
75
+ }}
76
+ />
77
+ </>
78
+ );
79
+ break;
80
+ case 'numberfield':
81
+ return (
82
+ <>
83
+ {label}
84
+ <TextField
85
+ inputProps={{ inputMode: 'decimal', pattern: '[0-9]*' }}
86
+ value={paintProps[key]}
87
+ onChange={(ev: React.ChangeEvent) => {
88
+ if (ev?.target?.value) {
89
+ setPaintProps((current) => ({ ...current, [key]: parseInt(ev.target.value) }));
90
+ }
91
+ }}
92
+ />
93
+ </>
94
+ );
95
+ break;
96
+ case 'colorpicker':
97
+ return (
98
+ <>
99
+ {label}
100
+ <ColorPicker
101
+ key={key}
102
+ value={paintProps[key]}
103
+ propKey={key}
104
+ setPaintProps={setPaintProps}
105
+ />
106
+ </>
107
+ );
108
+ break;
109
+ }
110
+ }
111
+ return null;
112
+ };
113
+
114
+ return (
115
+ <>
116
+ <ListItem
117
+ sx={{ boxShadow: 'inset 0px 0px 10px rgb(50 50 50 / 10%)', borderRadius: '5px' }}
118
+ key={key + '_paintPropForm'}
119
+ >
120
+ <Box>
121
+ {Object.keys(paintProps).map((el: string) => getFormInputByType(el, paintProps[el]))}
122
+ </Box>
123
+ </ListItem>
124
+ </>
125
+ );
126
+ }
@@ -0,0 +1,3 @@
1
+ # Component Beschreibung
2
+
3
+ Beschreibungstext
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "MlSketchTool",
3
+ "title": "Sketch Tool",
4
+ "description": "Enables creation and editing of Points LineStrings and Polygons.",
5
+ "i18n": {
6
+ "de": {
7
+ "title": "Zeichenwerkzeug",
8
+ "description": "Erzeugen und bearbeiten von Geometrien."
9
+ }
10
+ },
11
+ "tags": [],
12
+ "category": "",
13
+ "type": "component",
14
+ "price": 0
15
+ }
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+
3
+ import MlSketchTool from './MlSketchTool';
4
+
5
+ import mapContextDecorator from '../../decorators/MapContextDecorator';
6
+ import Sidebar from '../../ui_components/Sidebar';
7
+
8
+ const storyoptions = {
9
+ title: 'MapComponents/MlSketchTool',
10
+ component: MlSketchTool,
11
+ argTypes: {},
12
+ decorators: mapContextDecorator,
13
+ };
14
+ export default storyoptions;
15
+
16
+ const Template = (args) => (
17
+ <>
18
+ <Sidebar sx={{ maxWidth: '25vw' }}>
19
+ <MlSketchTool />
20
+ </Sidebar>
21
+ </>
22
+ );
23
+
24
+ export const ExampleConfig = Template.bind({});
25
+ ExampleConfig.parameters = {};
26
+ ExampleConfig.args = {};