@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,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 = {};
@@ -0,0 +1,271 @@
1
+ import React, { useState, useCallback } from 'react';
2
+ import PanoramaFishEyeIcon from '@mui/icons-material/PanoramaFishEye';
3
+ import ShowChartIcon from '@mui/icons-material/ShowChart';
4
+ import PentagonIcon from '@mui/icons-material/Pentagon';
5
+ import { Box } from '@mui/system';
6
+ //import useMediaQuery from '@mui/material/useMediaQuery';
7
+ import MlFeatureEditor from '../MlFeatureEditor/MlFeatureEditor';
8
+ import List from '@mui/material/List';
9
+ import EditIcon from '@mui/icons-material/Edit';
10
+ import SettingsIcon from '@mui/icons-material/Settings';
11
+ import MlGeoJsonLayer from '../MlGeoJsonLayer/MlGeoJsonLayer';
12
+ import useMap from '../../hooks/useMap';
13
+ import DeleteIcon from '@mui/icons-material/Delete';
14
+ import * as turf from '@turf/turf';
15
+ import ButtonGroup from '@mui/material/ButtonGroup';
16
+ import IconButton from '@mui/material/IconButton';
17
+ import Tooltip from '@mui/material/Tooltip';
18
+ import LayerListItem from './LayerList/LayerListItem';
19
+ import GpsFixedIcon from '@mui/icons-material/GpsFixed';
20
+ import { Feature } from '@turf/turf';
21
+ import { LngLatLike } from '!maplibre-gl';
22
+ import { SxProps } from '@mui/system/styleFunctionSx/styleFunctionSx';
23
+
24
+ interface MlSketchToolProps {
25
+ /**
26
+ * Id of the target MapLibre instance in mapContext
27
+ */
28
+ mapId?: string;
29
+ /**
30
+ * Id of an existing layer in the mapLibre instance to help specify the layer order
31
+ * This layer will be visually beneath the layer with the "insertBeforeLayer" id.
32
+ */
33
+ insertBeforeLayer?: string;
34
+ /**
35
+ * Style attribute for the button-style
36
+ * https://mui.com/system/getting-started/the-sx-prop/
37
+ */
38
+ buttonStyleOverride?: SxProps;
39
+ }
40
+
41
+ /**
42
+ * Component template
43
+ *
44
+ */
45
+
46
+ const MlSketchTool = (props: MlSketchToolProps) => {
47
+ type SketchStateType = {
48
+ selectedGeoJson: Feature | undefined;
49
+ activeGeometryIndex: number;
50
+ geometries: Feature[];
51
+ drawMode: string;
52
+ };
53
+ const mapHook = useMap({
54
+ mapId: props.mapId,
55
+ waitForLayer: props.insertBeforeLayer,
56
+ });
57
+ //const mediaIsMobile = useMediaQuery('(max-width:900px)');
58
+ const [hoveredGeometry, setHoveredGeometry] = useState<Feature>();
59
+ const [sketchState, setSketchState] = useState<SketchStateType>({
60
+ activeGeometryIndex: 0,
61
+ selectedGeoJson: undefined,
62
+ geometries: [],
63
+ drawMode: '',
64
+ });
65
+
66
+ const buttonStyle = {
67
+ ...props.buttonStyleOverride,
68
+ };
69
+
70
+ const buttonClickHandler = useCallback(
71
+ (buttonDrawMode: string) => {
72
+ console.log(buttonDrawMode);
73
+ sketchState.drawMode !== buttonDrawMode
74
+ ? setSketchState((_sketchTool) => ({
75
+ drawMode: buttonDrawMode,
76
+ geometries: _sketchTool.geometries,
77
+ activeGeometryIndex: 0,
78
+ selectedGeoJson: undefined,
79
+ }))
80
+ : setSketchState((_sketchTool) => ({
81
+ drawMode: '',
82
+ geometries: _sketchTool.geometries,
83
+ activeGeometryIndex: 0,
84
+ selectedGeoJson: undefined,
85
+ }));
86
+ },
87
+ [sketchState]
88
+ );
89
+
90
+ const removeGeoJson = (geoJson: Feature): void => {
91
+ setSketchState((_sketchState) => {
92
+ const tempGeometries = [..._sketchState.geometries];
93
+ tempGeometries.splice(tempGeometries.indexOf(geoJson), 1);
94
+
95
+ return {
96
+ ..._sketchState,
97
+ geometries: tempGeometries,
98
+ activeGeometryIndex: _sketchState.activeGeometryIndex - 1,
99
+ };
100
+ });
101
+ };
102
+
103
+ return (
104
+ <>
105
+ <Box
106
+ sx={{
107
+ zIndex: 104,
108
+ }}
109
+ >
110
+ <ButtonGroup>
111
+ <Tooltip title={'point'}>
112
+ <IconButton sx={buttonStyle} onClick={() => buttonClickHandler('draw_point')}>
113
+ <PanoramaFishEyeIcon />
114
+ </IconButton>
115
+ </Tooltip>
116
+ <Tooltip title={'Line'}>
117
+ <IconButton sx={buttonStyle} onClick={() => buttonClickHandler('draw_line_string')}>
118
+ <ShowChartIcon />
119
+ </IconButton>
120
+ </Tooltip>
121
+ <Tooltip title={'Polygon'}>
122
+ <IconButton sx={buttonStyle} onClick={() => buttonClickHandler('custom_polygon')}>
123
+ <PentagonIcon />
124
+ </IconButton>
125
+ </Tooltip>
126
+ </ButtonGroup>
127
+ </Box>
128
+
129
+ {sketchState.drawMode && (
130
+ <MlFeatureEditor
131
+ mode={
132
+ sketchState.drawMode === 'edit'
133
+ ? sketchState.selectedGeoJson?.geometry?.type === 'LineString'
134
+ ? 'simple_select'
135
+ : 'custom_select'
136
+ : sketchState.drawMode
137
+ }
138
+ geojson={sketchState.drawMode === 'edit' ? sketchState.selectedGeoJson : undefined}
139
+ onChange={(feature: object) => {
140
+ setSketchState((_sketchState) => {
141
+ const _geometries = [...sketchState.geometries];
142
+ if (sketchState.drawMode === 'edit' && sketchState.selectedGeoJson) {
143
+ _geometries[_geometries.indexOf(sketchState.selectedGeoJson)] = feature[0];
144
+ } else {
145
+ if (!sketchState.activeGeometryIndex) {
146
+ const tempFeature = feature[0];
147
+ tempFeature.properties.id = tempFeature.id;
148
+
149
+ _geometries.push(tempFeature);
150
+ } else {
151
+ _geometries[sketchState.activeGeometryIndex] = feature[0];
152
+ }
153
+ }
154
+ return {
155
+ ..._sketchState,
156
+ activeGeometryIndex:
157
+ _sketchState.drawMode !== 'edit' && feature[0].geometry.type !== 'Point'
158
+ ? _geometries.length - 1
159
+ : _sketchState.activeGeometryIndex,
160
+ geometries: _geometries,
161
+ };
162
+ });
163
+ }}
164
+ onFinish={() => {
165
+ setSketchState((_sketchState) => ({
166
+ ..._sketchState,
167
+ drawMode: '',
168
+ activeGeometryIndex:
169
+ _sketchState.drawMode !== 'draw_point' ? 0 : _sketchState.activeGeometryIndex,
170
+ selectedGeoJson:
171
+ _sketchState.drawMode !== 'draw_point' ? undefined : _sketchState.selectedGeoJson,
172
+ }));
173
+ }}
174
+ />
175
+ )}
176
+
177
+ <List sx={{ zIndex: 105 }}>
178
+ {sketchState.geometries.map((el) => (
179
+ <>
180
+ <Box key={el.id} sx={{ display: 'flex', flexDirection: 'column' }}>
181
+ <br />
182
+ <Box
183
+ flexDirection={'row'}
184
+ sx={{
185
+ '&:hover': {
186
+ backgroundColor: 'rgb(177, 177, 177, 0.2)',
187
+ },
188
+ }}
189
+ onMouseOver={() => {
190
+ setHoveredGeometry(el);
191
+ }}
192
+ onMouseLeave={() => {
193
+ setHoveredGeometry(undefined);
194
+ }}
195
+ >
196
+ {/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */}
197
+ {/* @ts-ignore-next-line */}
198
+ <LayerListItem
199
+ sx={buttonStyle}
200
+ visible={true}
201
+ configurable={true}
202
+ layerComponent={
203
+ <MlGeoJsonLayer mapId={props.mapId} geojson={el} layerId={String(el.id)} />
204
+ }
205
+ type={'layer'}
206
+ name={String(el.id)}
207
+ description={el.geometry.type}
208
+ >
209
+ <SettingsIcon />
210
+ </LayerListItem>
211
+ <IconButton
212
+ onClick={() => {
213
+ mapHook?.map?.map.setCenter(
214
+ el.geometry.type === 'Point'
215
+ ? (el.geometry.coordinates as LngLatLike)
216
+ : (turf.centerOfMass(el).geometry.coordinates as LngLatLike)
217
+ );
218
+ }}
219
+ >
220
+ <GpsFixedIcon />
221
+ </IconButton>
222
+ <IconButton
223
+ sx={buttonStyle}
224
+ onClick={() => {
225
+ setSketchState((_sketchState) => ({
226
+ ..._sketchState,
227
+ selectedGeoJson: el,
228
+ drawMode: 'edit',
229
+ }));
230
+ }}
231
+ >
232
+ <EditIcon />
233
+ </IconButton>
234
+ <IconButton
235
+ sx={buttonStyle}
236
+ onClick={() => {
237
+ removeGeoJson(el);
238
+ }}
239
+ >
240
+ <DeleteIcon />
241
+ </IconButton>
242
+ </Box>
243
+ </Box>
244
+ </>
245
+ ))}
246
+ {hoveredGeometry && (
247
+ <MlGeoJsonLayer
248
+ mapId={props.mapId}
249
+ geojson={{ type: 'FeatureCollection', features: [hoveredGeometry] }}
250
+ type={'line'}
251
+ layerId={'highlightBorder'}
252
+ paint={{
253
+ 'line-color': '#dd9900',
254
+ 'line-opacity': 0.4,
255
+ 'line-width': 10,
256
+ }}
257
+ />
258
+ )}
259
+ </List>
260
+ {sketchState.drawMode === 'edit' && (
261
+ <Box>Edit {sketchState.selectedGeoJson?.geometry?.type}</Box>
262
+ )}
263
+ </>
264
+ );
265
+ };
266
+
267
+ MlSketchTool.defaultProps = {
268
+ mapId: undefined,
269
+ buttonStyleOverride: {},
270
+ };
271
+ export default MlSketchTool;
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "MlTransitionGeoJsonLayer",
3
- "title": "GeoJSON layer",
3
+ "title": "Transition GeoJSON layer",
4
4
  "description": "",
5
5
  "i18n": {
6
6
  "de": {
7
- "title": "GeoJSON Ebene",
7
+ "title": "Animierte GeoJSON Ebene",
8
8
  "description": ""
9
9
  }
10
10
  },
@@ -0,0 +1,80 @@
1
+ import React, { useState } from 'react';
2
+ import { styled } from '@mui/material/styles';
3
+ import Drawer from '@mui/material/Drawer';
4
+ import ChevronLeftIcon from '@mui/icons-material/ChevronLeft';
5
+ import MenuIcon from '@mui/icons-material/Menu';
6
+ import { IconButton, PaperProps } from '@mui/material';
7
+ import useMediaQuery from '@mui/material/useMediaQuery';
8
+ import Box from '@mui/material/Box';
9
+ import { JsxChildren } from 'typedoc/dist/lib/utils/jsx.elements';
10
+
11
+ const DrawerHeader = styled('div')(() => ({
12
+ display: 'flex',
13
+ alignItems: 'center',
14
+ }));
15
+
16
+ interface SidebarProps {
17
+ drawerPaperProps: PaperProps;
18
+ drawerHeaderProps: Headers;
19
+ children: JsxChildren;
20
+ }
21
+
22
+ export default function Sidebar({ drawerPaperProps, drawerHeaderProps, ...props }: SidebarProps) {
23
+ const mediaIsMobile = useMediaQuery('(max-width:900px)');
24
+
25
+ const [drawerOpen, setDrawerOpen] = useState(true);
26
+
27
+ const handleDrawerOpen = () => {
28
+ setDrawerOpen(true);
29
+ };
30
+ const handleDrawerClose = () => {
31
+ setDrawerOpen(false);
32
+ };
33
+
34
+ return (
35
+ <>
36
+ <IconButton
37
+ onClick={handleDrawerOpen}
38
+ style={{
39
+ zIndex: 101,
40
+ position: 'relative',
41
+ padding: '20px',
42
+ }}
43
+ >
44
+ <MenuIcon />
45
+ </IconButton>
46
+ <Drawer
47
+ transitionDuration={0}
48
+ variant="persistent"
49
+ anchor="left"
50
+ open={drawerOpen}
51
+ PaperProps={{
52
+ sx: {
53
+ maxWidth: '20%',
54
+ padding: '40px',
55
+ },
56
+ ...drawerPaperProps,
57
+ }}
58
+ sx={{
59
+ flexGrow: 1,
60
+ zIndex: 105,
61
+ position: 'absolute',
62
+ top: 0,
63
+ backgroundColor: '#fafafa',
64
+ display: 'flex',
65
+ flexDirection: 'column',
66
+ maxWidth: mediaIsMobile ? '90vw' : '20vw',
67
+ ...(drawerOpen ? {} : { left: mediaIsMobile ? '-90vw' : '-20vw' }),
68
+ }}
69
+ {...props}
70
+ >
71
+ <DrawerHeader {...drawerHeaderProps}>
72
+ <IconButton onClick={handleDrawerClose}>
73
+ <ChevronLeftIcon />
74
+ </IconButton>
75
+ </DrawerHeader>
76
+ <Box>{props.children}</Box>
77
+ </Drawer>
78
+ </>
79
+ );
80
+ }
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import AppBar from '@mui/material/AppBar';
3
+ import { Toolbar, AppBarProps, ToolbarProps } from '@mui/material';
4
+
5
+ interface TopToolbarProps extends AppBarProps {
6
+ toolbarProps: ToolbarProps;
7
+ }
8
+ export default function TopToolbar({ toolbarProps, ...props }: TopToolbarProps) {
9
+ return (
10
+ <AppBar
11
+ sx={{
12
+ minHeight: '62px',
13
+ backgroundColor: '#f1f1f1',
14
+ position: 'absolute',
15
+ zIndex: 120,
16
+ }}
17
+ color="primary"
18
+ position="static"
19
+ {...props}
20
+ >
21
+ <Toolbar {...toolbarProps}>{props.children}</Toolbar>
22
+ </AppBar>
23
+ );
24
+ }
package/tsconfig.json CHANGED
@@ -1,59 +1,40 @@
1
1
  {
2
- "compilerOptions": {
3
- "checkJs": false,
4
- "esModuleInterop": true,
5
- "importHelpers": false,
6
- "isolatedModules": true,
7
- "resolveJsonModule": true,
8
- "skipLibCheck": true,
9
- "sourceMap": true,
10
- "strict": false,
11
- "types": [
12
- "node",
13
- "jest",
14
- "geojson"
15
- ],
16
- "outDir": "build/esm",
17
- "module": "esnext",
18
- "target": "es5",
19
- "lib": [
20
- "es6",
21
- "dom",
22
- "es2016",
23
- "es2017"
24
- ],
25
- "jsx": "react",
26
- "declaration": true,
27
- "declarationDir": "./dist",
28
- "moduleResolution": "node",
29
- "noUnusedLocals": true,
30
- "noUnusedParameters": true,
31
- "noImplicitReturns": true,
32
- "noImplicitThis": true,
33
- "noImplicitAny": true,
34
- "strictNullChecks": true,
35
- "suppressImplicitAnyIndexErrors": true,
36
- "allowSyntheticDefaultImports": true,
37
- "allowJs": true,
38
- "baseUrl": ".",
39
- "paths": {
40
- "!maplibre-gl": [
41
- "node_modules/maplibre-gl"
42
- ] // This mapping is relative to "baseUrl"
43
- }
44
- },
45
- "include": [
46
- "src",
47
- "src/custom.d.tsx"
48
- ],
49
- "exclude": [
50
- "node_modules",
51
- "lib"
52
- ],
53
- "typedocOptions": {
54
- "entryPoints": [
55
- "src/index.ts"
56
- ],
57
- "out": "docs",
58
- }
59
- }
2
+ "compilerOptions": {
3
+ "checkJs": false,
4
+ "esModuleInterop": true,
5
+ "importHelpers": false,
6
+ "isolatedModules": true,
7
+ "resolveJsonModule": true,
8
+ "skipLibCheck": true,
9
+ "sourceMap": true,
10
+ "strict": false,
11
+ "types": ["node", "jest", "geojson", "cypress", "./support"],
12
+ "outDir": "build/esm",
13
+ "module": "esnext",
14
+ "target": "es5",
15
+ "lib": ["es6", "dom", "es2016", "es2017"],
16
+ "jsx": "react",
17
+ "declaration": true,
18
+ "declarationDir": "./dist",
19
+ "moduleResolution": "node",
20
+ "noUnusedLocals": true,
21
+ "noUnusedParameters": true,
22
+ "noImplicitReturns": true,
23
+ "noImplicitThis": true,
24
+ "noImplicitAny": true,
25
+ "strictNullChecks": true,
26
+ "suppressImplicitAnyIndexErrors": true,
27
+ "allowSyntheticDefaultImports": true,
28
+ "allowJs": true,
29
+ "baseUrl": ".",
30
+ "paths": {
31
+ "!maplibre-gl": ["node_modules/maplibre-gl"] // This mapping is relative to "baseUrl"
32
+ }
33
+ },
34
+ "include": ["src", "src/custom.d.tsx"],
35
+ "exclude": ["node_modules", "lib"],
36
+ "typedocOptions": {
37
+ "entryPoints": ["src/index.ts"],
38
+ "out": "docs"
39
+ }
40
+ }