@mapcomponents/ra-geospatial 1.5.3 → 1.5.4-0

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 (96) hide show
  1. package/.babelrc +12 -0
  2. package/.storybook/main.ts +25 -0
  3. package/.storybook/manager.js +6 -0
  4. package/.storybook/mapcomponents_logo.png +0 -0
  5. package/.storybook/preview.ts +27 -0
  6. package/.storybook/style.css +20 -0
  7. package/.storybook/wheregroupTheme.js +9 -0
  8. package/README.md +1 -2
  9. package/assets/ra_geospatial_screenshots.png +0 -0
  10. package/dist/README.md +74 -0
  11. package/dist/components/GeospatialInput.d.ts +9 -0
  12. package/dist/components/GeospatialInput.d.ts.map +1 -0
  13. package/dist/components/GeospatialInputMap.d.ts +18 -0
  14. package/dist/components/GeospatialInputMap.d.ts.map +1 -0
  15. package/dist/components/GeospatialShow.d.ts +9 -0
  16. package/dist/components/GeospatialShow.d.ts.map +1 -0
  17. package/dist/components/GeospatialShowMap.d.ts +11 -0
  18. package/dist/components/GeospatialShowMap.d.ts.map +1 -0
  19. package/dist/contexts/DataContext.d.ts +4 -0
  20. package/dist/contexts/DataContext.d.ts.map +1 -0
  21. package/dist/contexts/dataProvider.d.ts +35 -0
  22. package/dist/contexts/dataProvider.d.ts.map +1 -0
  23. package/dist/contexts/lsDataProvider.d.ts +44 -0
  24. package/dist/contexts/lsDataProvider.d.ts.map +1 -0
  25. package/dist/decorators/ReactAdminDefaultDecorator.d.ts +3 -0
  26. package/dist/decorators/ReactAdminDefaultDecorator.d.ts.map +1 -0
  27. package/dist/favicon.ico +0 -0
  28. package/dist/html2canvas.esm-CUkZERmf.cjs +23 -0
  29. package/dist/html2canvas.esm-CUkZERmf.cjs.map +1 -0
  30. package/dist/html2canvas.esm-Dmi1NfiH.js +4872 -0
  31. package/dist/html2canvas.esm-Dmi1NfiH.js.map +1 -0
  32. package/dist/index-BYtSitNR.js +61509 -0
  33. package/dist/index-BYtSitNR.js.map +1 -0
  34. package/dist/index-DD78QbMh.cjs +1222 -0
  35. package/dist/index-DD78QbMh.cjs.map +1 -0
  36. package/dist/index.cjs +2 -0
  37. package/dist/index.cjs.map +1 -0
  38. package/dist/index.css +1 -0
  39. package/dist/index.d.ts +3 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.es-DBcuOIG0.js +6675 -0
  42. package/dist/index.es-DBcuOIG0.js.map +1 -0
  43. package/dist/index.es-YxBXdzDQ.cjs +19 -0
  44. package/dist/index.es-YxBXdzDQ.cjs.map +1 -0
  45. package/dist/index.js +6 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/layout/GisLayout.d.ts +6 -0
  48. package/dist/layout/GisLayout.d.ts.map +1 -0
  49. package/dist/logo.png +0 -0
  50. package/dist/manifest.json +25 -0
  51. package/dist/package.json +24 -0
  52. package/dist/purify.es-D1I7B1hP.cjs +3 -0
  53. package/dist/purify.es-D1I7B1hP.cjs.map +1 -0
  54. package/dist/purify.es-DHbHSKL1.js +529 -0
  55. package/dist/purify.es-DHbHSKL1.js.map +1 -0
  56. package/dist/ra_components/Poi.d.ts +5 -0
  57. package/dist/ra_components/Poi.d.ts.map +1 -0
  58. package/dist/ra_components/Property.d.ts +5 -0
  59. package/dist/ra_components/Property.d.ts.map +1 -0
  60. package/dist/ra_components/Route.d.ts +5 -0
  61. package/dist/ra_components/Route.d.ts.map +1 -0
  62. package/dist/ra_components/raGeospatialProps.d.ts +12 -0
  63. package/dist/ra_components/raGeospatialProps.d.ts.map +1 -0
  64. package/dist/ra_components/raGeospatialWebGisProps.d.ts +12 -0
  65. package/dist/ra_components/raGeospatialWebGisProps.d.ts.map +1 -0
  66. package/eslint.config.cjs +3 -0
  67. package/index.html +16 -0
  68. package/package.json +23 -42
  69. package/project.json +14 -0
  70. package/public/favicon.ico +0 -0
  71. package/public/logo.png +0 -0
  72. package/public/manifest.json +25 -0
  73. package/src/components/GeospatialInput.stories.tsx +83 -0
  74. package/src/components/GeospatialInput.tsx +14 -17
  75. package/src/components/GeospatialInputMap.tsx +172 -165
  76. package/src/components/GeospatialShow.stories.tsx +84 -0
  77. package/src/components/GeospatialShow.tsx +14 -17
  78. package/src/components/GeospatialShowMap.tsx +53 -58
  79. package/src/contexts/DataContext.jsx +66 -0
  80. package/src/contexts/dataProvider.tsx +30 -0
  81. package/src/contexts/lsDataProvider.js +138 -0
  82. package/src/decorators/ReactAdminDefaultDecorator.tsx +40 -0
  83. package/src/index.ts +2 -2
  84. package/src/layout/GisLayout.jsx +90 -0
  85. package/src/ra_components/Poi.tsx +42 -0
  86. package/src/ra_components/Property.tsx +42 -0
  87. package/src/ra_components/Route.tsx +42 -0
  88. package/src/ra_components/raGeospatialProps.ts +5 -0
  89. package/src/ra_components/raGeospatialWebGisProps.ts +5 -0
  90. package/src/types.d.ts +3 -2
  91. package/tsconfig.json +7 -101
  92. package/tsconfig.lib.json +29 -0
  93. package/vite.config.ts +58 -0
  94. package/dist/index.esm.js +0 -157
  95. package/dist/index.esm.js.map +0 -1
  96. package/rollup.config.js +0 -50
@@ -1,180 +1,187 @@
1
- import React, { useEffect, useState } from "react";
2
- import { InputProps, useInput, useRecordContext } from "react-admin";
3
- import {
4
- GeoJSONGeometry,
5
- parse as wellknownParse,
6
- stringify as wellknownStringify
7
- } from "wellknown";
1
+ import React, { useEffect, useState } from 'react';
2
+ import { InputProps, useInput, useRecordContext } from 'react-admin';
3
+ import { parse as wellknownParse, stringify as wellknownStringify } from 'wellknown';
4
+
8
5
  import {
9
6
  MapLibreMap,
10
7
  MlFeatureEditor,
11
8
  MlGeoJsonLayer,
12
- useMap
13
- } from "@mapcomponents/react-maplibre";
14
- import { LngLatLike } from "maplibre-gl";
15
- import { centroid, feature } from "@turf/turf";
16
- import { Feature } from "@turf/helpers";
9
+ useMap,
10
+ } from '@mapcomponents/react-maplibre';
11
+ import { LngLatLike } from 'maplibre-gl';
12
+ import { centroid, feature } from '@turf/turf';
13
+ import { Feature } from '@turf/helpers';
14
+ import { Geometry } from 'geojson';
17
15
 
18
16
  export interface GeospatialInputMapProps extends InputProps<any> {
19
- MapLibreMapProps?: React.ComponentProps<typeof MapLibreMap>;
20
- geometrytype?: "point" | "line" | "polygon";
21
- embeddedMap?: boolean;
22
- mapId?: string;
17
+ MapLibreMapProps?: React.ComponentProps<typeof MapLibreMap>;
18
+ geometrytype?: 'point' | 'line' | 'polygon';
19
+ embeddedMap?: boolean;
20
+ mapId?: string;
23
21
  }
24
22
 
25
23
  function GeospatialInputMap(props: GeospatialInputMapProps) {
26
- const source = props?.source;
27
- const record = useRecordContext();
28
- const mapHook = useMap({mapId:props?.mapId});
29
-
30
- const [geojson, setGeojson] = useState<typeof feature>();
31
- const [oldGeoJson, setOldGeoJson] = useState<typeof feature>();
32
- const {
33
- field: { name, onChange, ...rest },
34
- fieldState,
35
- formState,
36
- isRequired,
37
- } = useInput(props);
38
-
39
- useEffect(() => {
40
- if (typeof record === "undefined" || !record[source]) return;
41
-
42
- const _geoJson = {
43
- type: "Feature",
44
- properties: {},
45
- geometry: wellknownParse(record[source]),
46
- };
47
-
48
- setGeojson(_geoJson as unknown as typeof feature);
49
- setOldGeoJson(_geoJson as unknown as typeof feature);
50
- }, [record, props.source]);
51
-
52
- useEffect(() => {
53
- if (!mapHook.map) return;
54
-
55
- if (typeof record !== "undefined" && record[source]) {
56
- const _center = centroid(
57
- wellknownParse(record[source]) as typeof Feature
58
- );
59
-
60
- if (_center?.geometry?.coordinates) {
61
- mapHook.map.setCenter(_center.geometry.coordinates as LngLatLike);
62
- }
63
- }
64
- }, [mapHook.map]);
65
-
66
- return (
67
- <>
68
- {props.embeddedMap && (
69
- <MapLibreMap
70
- {...props?.MapLibreMapProps}
71
- options={{
72
- zoom: 14,
73
- style:
74
- "https://wms.wheregroup.com/tileserver/style/klokantech-basic.json",
75
- center: [0, 0],
76
- ...props?.MapLibreMapProps?.options,
77
- }}
78
- style={{
79
- width: "100%",
80
- height: "400px",
81
- ...props?.MapLibreMapProps?.style,
82
- }}
83
- />
84
- )}
85
-
86
- {props.type === "point" && (
87
- <>
88
- {oldGeoJson && (
89
- <MlGeoJsonLayer
90
- mapId={props?.mapId}
91
- geojson={oldGeoJson as typeof feature}
92
- paint={{
93
- "circle-radius": 8,
94
- "circle-color": "#6f6f96",
95
- "circle-stroke-color": "white",
96
- "circle-stroke-width": 3,
97
- "circle-opacity": 0.8,
98
- }}
99
- type="circle"
100
- insertBeforeLayer="gl-draw-polygon-fill-inactive.cold"
101
- />
102
- )}
103
-
104
- <MlFeatureEditor
105
- mapId={props?.mapId}
106
- geojson={geojson as typeof feature}
107
- mode={geojson ? "simple_select": "draw_point"}
108
- onChange={(_geojson) => {
109
- if (typeof _geojson[0] !== "undefined") {
110
- onChange(wellknownStringify(_geojson[0] as GeoJSONGeometry));
111
- }
112
- }}
113
- />
114
- </>
115
- )}
116
- {props.type === "polygon" && (
117
- <>
118
- {oldGeoJson && (
119
- <MlGeoJsonLayer
120
- mapId={props?.mapId}
121
- geojson={oldGeoJson as typeof feature}
122
- paint={{
123
- "fill-color": "#6f6f96",
124
- "fill-opacity": 0.6,
125
- }}
126
- type="fill"
127
- insertBeforeLayer="gl-draw-polygon-fill-inactive.cold"
128
- />
129
- )}
130
-
131
- <MlFeatureEditor
132
- mapId={props?.mapId}
133
- geojson={geojson as typeof feature}
134
- mode={geojson ? "simple_select": "draw_polygon"}
135
- onChange={(_geojson) => {
136
- if (typeof _geojson[0] !== "undefined") {
137
- onChange(wellknownStringify(_geojson[0] as GeoJSONGeometry));
138
- }
139
- }}
140
- />
141
- </>
142
- )}
143
- {props.type === "line" && (
144
- <>
145
- {oldGeoJson && (
146
- <MlGeoJsonLayer
147
- mapId={props?.mapId}
148
- geojson={oldGeoJson as typeof feature}
149
- paint={{
150
- "line-width": 6,
151
- "line-color": "#6f6f96",
152
- "line-opacity": 0.6,
153
- }}
154
- type="line"
155
- insertBeforeLayer="gl-draw-polygon-fill-inactive.cold"
156
- />
157
- )}
158
-
159
- <MlFeatureEditor
160
- mapId={props?.mapId}
161
- geojson={geojson as typeof feature}
162
- mode={geojson ? "simple_select": "draw_line_string"}
163
- onChange={(_geojson) => {
164
- if (typeof _geojson[0] !== "undefined") {
165
- onChange(wellknownStringify(_geojson[0] as GeoJSONGeometry));
166
- }
167
- }}
168
- />
169
- </>
170
- )}
171
- </>
172
- );
24
+ const source = props?.source;
25
+ const record = useRecordContext();
26
+ const mapHook = useMap({ mapId: props?.mapId });
27
+
28
+ const [geojson, setGeojson] = useState<typeof feature>();
29
+ const [oldGeoJson, setOldGeoJson] = useState<typeof feature>();
30
+ const input = useInput(props);
31
+
32
+ const {
33
+ field: { onChange },
34
+ } = input;
35
+
36
+ useEffect(() => {
37
+ if (typeof record === 'undefined' || !record[source]) return;
38
+
39
+ const _geoJson = {
40
+ type: 'Feature',
41
+ properties: {},
42
+ geometry: wellknownParse(record[source]),
43
+ };
44
+
45
+ setGeojson(_geoJson as unknown as typeof feature);
46
+ setOldGeoJson(_geoJson as unknown as typeof feature);
47
+ }, [record, props.source]);
48
+
49
+ useEffect(() => {
50
+ if (!mapHook.map) return;
51
+
52
+ if (typeof record !== 'undefined' && record[source]) {
53
+ const _center = centroid(wellknownParse(record[source]) as typeof Feature);
54
+
55
+ if (_center?.geometry?.coordinates) {
56
+ mapHook.map.setCenter(_center.geometry.coordinates as LngLatLike);
57
+ }
58
+ }
59
+ }, [mapHook.map]);
60
+
61
+ return (
62
+ <>
63
+ {props.embeddedMap && (
64
+ <MapLibreMap
65
+ {...props?.MapLibreMapProps}
66
+ options={{
67
+ zoom: 14,
68
+ style: 'https://wms.wheregroup.com/tileserver/style/klokantech-basic.json',
69
+ center:
70
+ Array.isArray(props?.MapLibreMapProps?.options?.center) &&
71
+ props.MapLibreMapProps.options.center.length === 2
72
+ ? [
73
+ props.MapLibreMapProps.options.center[0],
74
+ props.MapLibreMapProps.options.center[1],
75
+ ]
76
+ : [0, 0],
77
+ ...props?.MapLibreMapProps?.options,
78
+ }}
79
+ style={{
80
+ width: '100%',
81
+ height: '400px',
82
+ ...props?.MapLibreMapProps?.style,
83
+ }}
84
+ />
85
+ )}
86
+
87
+ {props.type === 'point' && (
88
+ <>
89
+ {oldGeoJson && (
90
+ <MlGeoJsonLayer
91
+ mapId={props?.mapId}
92
+ geojson={oldGeoJson as typeof feature}
93
+ options={{
94
+ paint: {
95
+ 'circle-radius': 8,
96
+ 'circle-color': '#6f6f96',
97
+ 'circle-stroke-color': 'white',
98
+ 'circle-stroke-width': 3,
99
+ 'circle-opacity': 0.8,
100
+ },
101
+ }}
102
+ type="circle"
103
+ insertBeforeLayer="gl-draw-polygon-fill-inactive.cold"
104
+ />
105
+ )}
106
+
107
+ <MlFeatureEditor
108
+ mapId={props?.mapId}
109
+ geojson={geojson as typeof feature}
110
+ mode={geojson ? 'simple_select' : 'draw_point'}
111
+ onChange={(_geojson) => {
112
+ if (typeof _geojson[0] !== 'undefined') {
113
+ onChange(wellknownStringify(_geojson[0] as unknown as Geometry));
114
+ }
115
+ }}
116
+ />
117
+ </>
118
+ )}
119
+ {props.type === 'polygon' && (
120
+ <>
121
+ {oldGeoJson && (
122
+ <MlGeoJsonLayer
123
+ mapId={props?.mapId}
124
+ geojson={oldGeoJson as typeof feature}
125
+ options={{
126
+ paint: {
127
+ 'fill-color': '#6f6f96',
128
+ 'fill-opacity': 0.6,
129
+ },
130
+ }}
131
+ type="fill"
132
+ insertBeforeLayer="gl-draw-polygon-fill-inactive.cold"
133
+ />
134
+ )}
135
+
136
+ <MlFeatureEditor
137
+ mapId={props?.mapId}
138
+ geojson={geojson as typeof feature}
139
+ mode={geojson ? 'simple_select' : 'draw_polygon'}
140
+ onChange={(_geojson) => {
141
+ if (typeof _geojson[0] !== 'undefined') {
142
+ onChange(wellknownStringify(_geojson[0] as unknown as Geometry));
143
+ }
144
+ }}
145
+ />
146
+ </>
147
+ )}
148
+ {props.type === 'line' && (
149
+ <>
150
+ {oldGeoJson && (
151
+ <MlGeoJsonLayer
152
+ mapId={props?.mapId}
153
+ geojson={oldGeoJson as typeof feature}
154
+ options={{
155
+ paint: {
156
+ 'line-width': 6,
157
+ 'line-color': '#6f6f96',
158
+ 'line-opacity': 0.6,
159
+ },
160
+ }}
161
+ type="line"
162
+ insertBeforeLayer="gl-draw-polygon-fill-inactive.cold"
163
+ />
164
+ )}
165
+
166
+ <MlFeatureEditor
167
+ mapId={props?.mapId}
168
+ geojson={geojson as typeof feature}
169
+ mode={geojson ? 'simple_select' : 'draw_line_string'}
170
+ onChange={(_geojson) => {
171
+ if (typeof _geojson[0] !== 'undefined') {
172
+ onChange(wellknownStringify(_geojson[0] as unknown as Geometry));
173
+ }
174
+ }}
175
+ />
176
+ </>
177
+ )}
178
+ </>
179
+ );
173
180
  }
174
181
 
175
182
  GeospatialInputMap.defaultProps = {
176
- type: "point",
177
- embeddedMap: true,
183
+ type: 'point',
184
+ embeddedMap: true,
178
185
  };
179
186
 
180
187
  export default GeospatialInputMap;
@@ -0,0 +1,84 @@
1
+ import type { Meta } from '@storybook/react-vite';
2
+ import GeospatialShow from './GeospatialShow';
3
+ import { ReactAdminDefaultDecorator } from '../decorators/ReactAdminDefaultDecorator';
4
+ import { PoiShow, PoiShowWebGis } from '../ra_components/Poi';
5
+ import { PropertyShow, PropertyShowWebGis } from '../ra_components/Property';
6
+ import { RouteShow, RouteShowWebGis } from '../ra_components/Route';
7
+ import GisLayout from '../layout/GisLayout';
8
+
9
+ const meta = {
10
+ component: GeospatialShow,
11
+ title: 'MapComponents/GeospatialShow',
12
+ decorators: [ReactAdminDefaultDecorator],
13
+ } satisfies Meta<typeof GeospatialShow>;
14
+
15
+ export default meta;
16
+
17
+ export const PoisShow = PoiShow.bind({});
18
+
19
+ PoisShow.args = {
20
+ primary: true,
21
+ embeddedMap: true,
22
+ };
23
+
24
+ PoisShow.parameters = {
25
+ name: 'pois',
26
+ };
27
+
28
+ export const PropertiesShow = PropertyShow.bind({});
29
+
30
+ PropertiesShow.args = {
31
+ primary: true,
32
+ embeddedMap: true,
33
+ };
34
+
35
+ PropertiesShow.parameters = {
36
+ name: 'properties',
37
+ };
38
+
39
+ export const RoutesShow = RouteShow.bind({});
40
+
41
+ RoutesShow.args = {
42
+ primary: true,
43
+ embeddedMap: true,
44
+ };
45
+
46
+ RoutesShow.parameters = {
47
+ name: 'routes',
48
+ };
49
+
50
+ export const PoisShowGIS = PoiShowWebGis.bind({});
51
+
52
+ PoisShowGIS.args = {
53
+ primary: true,
54
+ embeddedMap: false,
55
+ };
56
+
57
+ PoisShowGIS.parameters = {
58
+ name: 'pois',
59
+ layout: GisLayout,
60
+ };
61
+
62
+ export const PropertiesShowGIS = PropertyShowWebGis.bind({});
63
+
64
+ PropertiesShowGIS.args = {
65
+ primary: true,
66
+ embeddedMap: false,
67
+ };
68
+
69
+ PropertiesShowGIS.parameters = {
70
+ name: 'properties',
71
+ layout: GisLayout,
72
+ };
73
+
74
+ export const RoutesShowGIS = RouteShowWebGis.bind({});
75
+
76
+ RoutesShowGIS.args = {
77
+ primary: true,
78
+ embeddedMap: false,
79
+ };
80
+
81
+ RoutesShowGIS.parameters = {
82
+ name: 'routes',
83
+ layout: GisLayout,
84
+ };
@@ -1,24 +1,21 @@
1
- import React from "react";
2
- import { MapComponentsProvider } from "@mapcomponents/react-maplibre";
3
- import GeometryShowMap, {
4
- GeospatialShowMapProps,
5
- } from "./GeospatialShowMap.js";
1
+ import { MapComponentsProvider } from '@mapcomponents/react-maplibre';
2
+ import GeometryShowMap, { GeospatialShowMapProps } from './GeospatialShowMap.js';
6
3
 
7
4
  function GeospatialShow(props: GeospatialShowMapProps) {
8
- return (
9
- <>
10
- {props.embeddedMap ? (
11
- <MapComponentsProvider>
12
- <GeometryShowMap {...props} />
13
- </MapComponentsProvider>
14
- ) : (
15
- <GeometryShowMap {...props} />
16
- )}
17
- </>
18
- );
5
+ return (
6
+ <>
7
+ {props.embeddedMap ? (
8
+ <MapComponentsProvider>
9
+ <GeometryShowMap {...props} />
10
+ </MapComponentsProvider>
11
+ ) : (
12
+ <GeometryShowMap {...props} />
13
+ )}
14
+ </>
15
+ );
19
16
  }
20
17
  GeospatialShow.defaultProps = {
21
- embeddedMap: true,
18
+ embeddedMap: true,
22
19
  };
23
20
 
24
21
  export default GeospatialShow;
@@ -1,74 +1,69 @@
1
- import React, { useEffect, useState } from "react";
2
- import { InputProps, useRecordContext } from "react-admin";
3
- import { parse as wellknownParse, GeoJSONPoint } from "wellknown";
4
- import {
5
- MapLibreMap,
6
- MlGeoJsonLayer,
7
- useMap,
8
- } from "@mapcomponents/react-maplibre";
9
- import { LngLatLike } from "maplibre-gl";
10
- import { feature, centroid } from "@turf/turf";
11
- import { Feature } from "@turf/helpers";
1
+ import React, { useEffect, useState } from 'react';
2
+ import { InputProps, useRecordContext } from 'react-admin';
3
+ import { parse as wellknownParse } from 'wellknown';
4
+ import { MapLibreMap, MlGeoJsonLayer, useMap } from '@mapcomponents/react-maplibre';
5
+ import { LngLatLike } from 'maplibre-gl';
6
+ import { feature, centroid } from '@turf/turf';
7
+ import { Feature } from '@turf/helpers';
12
8
 
13
9
  export interface GeospatialShowMapProps extends InputProps<any> {
14
- MapLibreMapProps?: React.ComponentProps<typeof MapLibreMap>;
15
- embeddedMap?: boolean;
16
- mapId?: string;
10
+ MapLibreMapProps?: React.ComponentProps<typeof MapLibreMap>;
11
+ embeddedMap?: boolean;
12
+ mapId?: string;
17
13
  }
18
14
 
19
15
  function GeospatialShowMap(props: GeospatialShowMapProps) {
20
- const source = props.source;
21
- const record = useRecordContext();
22
- const mapHook = useMap();
16
+ const source = props.source;
17
+ const record = useRecordContext();
18
+ const mapHook = useMap();
23
19
 
24
- const [geojson, setGeojson] = useState<typeof feature>();
25
- useEffect(() => {
26
- if (!record?.[source]) return;
20
+ const [geojson, setGeojson] = useState<typeof feature>();
21
+ useEffect(() => {
22
+ if (!record?.[source]) return;
27
23
 
28
- const _geometry = wellknownParse(record[source]);
24
+ const _geometry = wellknownParse(record[source]);
29
25
 
30
- if (_geometry) {
31
- setGeojson({
32
- type: "Feature",
33
- properties: {},
34
- geometry: _geometry,
35
- } as unknown as typeof feature);
36
- }
37
- }, [record]);
26
+ if (_geometry) {
27
+ setGeojson({
28
+ type: 'Feature',
29
+ properties: {},
30
+ geometry: _geometry,
31
+ } as unknown as typeof feature);
32
+ }
33
+ }, [record]);
38
34
 
39
- useEffect(() => {
40
- if (!mapHook.map || !geojson) return;
35
+ useEffect(() => {
36
+ if (!mapHook.map || !geojson) return;
41
37
 
42
- const _center = centroid(geojson as typeof Feature);
38
+ const _center = centroid(geojson as typeof Feature);
43
39
 
44
- if (_center?.geometry?.coordinates) {
45
- mapHook.map.setCenter(_center.geometry.coordinates as LngLatLike);
46
- }
47
- }, [mapHook.map, geojson]);
40
+ if (_center?.geometry?.coordinates) {
41
+ mapHook.map.setCenter(_center.geometry.coordinates as LngLatLike);
42
+ }
43
+ }, [mapHook.map, geojson]);
48
44
 
49
- return (
50
- <>
51
- {props.embeddedMap && (
52
- <MapLibreMap
53
- {...props?.MapLibreMapProps}
54
- options={{
55
- zoom: 14,
56
- style:
57
- "https://wms.wheregroup.com/tileserver/style/klokantech-basic.json",
58
- center: [0, 0],
59
- ...props?.MapLibreMapProps?.options,
60
- }}
61
- style={{
62
- width: "100%",
63
- height: "400px",
64
- ...props?.MapLibreMapProps?.style,
65
- }}
66
- />
67
- )}
45
+ return (
46
+ <>
47
+ {props.embeddedMap && (
48
+ <MapLibreMap
49
+ {...props?.MapLibreMapProps}
50
+ options={{
51
+ zoom: 14,
52
+ style: 'https://wms.wheregroup.com/tileserver/style/klokantech-basic.json',
53
+ center: [0, 0],
54
+ ...props?.MapLibreMapProps?.options,
55
+ }}
56
+ style={{
57
+ width: '100%',
58
+ height: '400px',
59
+ ...props?.MapLibreMapProps?.style,
60
+ }}
61
+ />
62
+ )}
68
63
 
69
- {geojson && <MlGeoJsonLayer geojson={geojson}></MlGeoJsonLayer>}
70
- </>
71
- );
64
+ {geojson && <MlGeoJsonLayer geojson={geojson}></MlGeoJsonLayer>}
65
+ </>
66
+ );
72
67
  }
73
68
 
74
69
  export default GeospatialShowMap;
@@ -0,0 +1,66 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { parse as wellknownParse } from 'wellknown';
3
+ import { feature, featureCollection } from '@turf/helpers';
4
+ import { defaultData } from './dataProvider';
5
+
6
+ export const DataContext = React.createContext();
7
+
8
+ export default function DataContextProvider(props) {
9
+ const [data, setData] = useState({});
10
+
11
+ useEffect(() => {
12
+ refreshData();
13
+ const _eventHandler = () => {
14
+ console.log('refreshing data from localStorage');
15
+ refreshData();
16
+ };
17
+ window.addEventListener('storageItemUpdated', _eventHandler);
18
+ return () => {
19
+ window.removeEventListener('storageItemUpdated', _eventHandler);
20
+ };
21
+ }, []);
22
+
23
+ const refreshData = () => {
24
+ const storageDataTmp = localStorage.getItem('ra-data-local-storage');
25
+ if (storageDataTmp) {
26
+ const storageData = JSON.parse(storageDataTmp);
27
+ const _data = Object.keys(storageData).map((el) => {
28
+ const features = storageData[el].map((entry) => {
29
+ return feature(wellknownParse(entry.geom));
30
+ });
31
+ return {
32
+ name: el,
33
+ featureCollection: features?.[0] ? featureCollection(features) : undefined,
34
+ };
35
+ });
36
+
37
+ setData(_data);
38
+ } else {
39
+ const features = [];
40
+ let counter = 0;
41
+ Object.values(defaultData).map((geomArray) => {
42
+ features.push({
43
+ name: counter === 0 ? 'pois' : counter === 1 ? 'properties' : 'routes',
44
+ featureCollection: {
45
+ type: 'FeatureCollection',
46
+ features: geomArray.map((geom) => {
47
+ return {
48
+ type: 'Feature',
49
+ properties: {},
50
+ geometry: wellknownParse(geom.geom),
51
+ };
52
+ }),
53
+ },
54
+ });
55
+ counter++;
56
+ });
57
+ setData(features);
58
+ }
59
+ };
60
+ const value = {
61
+ data,
62
+ refreshData,
63
+ };
64
+
65
+ return <DataContext.Provider value={value}>{props.children}</DataContext.Provider>;
66
+ }