@mapcomponents/ra-geospatial 1.0.2 → 1.0.4

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.
package/dist/index.esm.js CHANGED
@@ -32,12 +32,13 @@ function __rest(s, e) {
32
32
  }
33
33
 
34
34
  function GeospatialInputMap(props) {
35
+ var _a, _b;
35
36
  const source = props === null || props === void 0 ? void 0 : props.source;
36
37
  const record = useRecordContext();
37
- const mapHook = useMap();
38
+ const mapHook = useMap({ mapId: props === null || props === void 0 ? void 0 : props.mapId });
38
39
  const [geojson, setGeojson] = useState();
39
40
  const [oldGeoJson, setOldGeoJson] = useState();
40
- const _a = useInput(props), _b = _a.field, { name, onChange } = _b; __rest(_b, ["name", "onChange"]);
41
+ const _c = useInput(props), _d = _c.field, { name, onChange } = _d; __rest(_d, ["name", "onChange"]);
41
42
  useEffect(() => {
42
43
  if (typeof record === "undefined" || !record[source])
43
44
  return;
@@ -61,41 +62,37 @@ function GeospatialInputMap(props) {
61
62
  }
62
63
  }, [mapHook.map]);
63
64
  return (React.createElement(React.Fragment, null,
64
- React.createElement(MapLibreMap, { options: {
65
- zoom: 14.5,
66
- style: "https://wms.wheregroup.com/tileserver/style/klokantech-basic.json",
67
- center: [7.0851268, 50.73884],
68
- }, style: { width: "100%", height: "400px" } }),
65
+ props.embeddedMap && (React.createElement(MapLibreMap, Object.assign({}, props === null || props === void 0 ? void 0 : props.MapLibreMapProps, { options: Object.assign({ zoom: 14, style: "https://wms.wheregroup.com/tileserver/style/klokantech-basic.json", center: [0, 0] }, (_a = props === null || props === void 0 ? void 0 : props.MapLibreMapProps) === null || _a === void 0 ? void 0 : _a.options), style: Object.assign({ width: "100%", height: "400px" }, (_b = props === null || props === void 0 ? void 0 : props.MapLibreMapProps) === null || _b === void 0 ? void 0 : _b.style) }))),
69
66
  props.type === "point" && (React.createElement(React.Fragment, null,
70
- oldGeoJson && (React.createElement(MlGeoJsonLayer, { geojson: oldGeoJson, paint: {
67
+ oldGeoJson && (React.createElement(MlGeoJsonLayer, { mapId: props === null || props === void 0 ? void 0 : props.mapId, geojson: oldGeoJson, paint: {
71
68
  "circle-radius": 8,
72
69
  "circle-color": "#6f6f96",
73
70
  "circle-stroke-color": "white",
74
71
  "circle-stroke-width": 3,
75
72
  "circle-opacity": 0.8,
76
- }, type: "circle" })),
77
- React.createElement(MlFeatureEditor, { geojson: geojson, mode: geojson ? "custom_select" : "draw_point", onChange: (_geojson) => {
73
+ }, type: "circle", insertBeforeLayer: "gl-draw-polygon-fill-inactive.cold" })),
74
+ React.createElement(MlFeatureEditor, { mapId: props === null || props === void 0 ? void 0 : props.mapId, geojson: geojson, mode: geojson ? "custom_select" : "draw_point", onChange: (_geojson) => {
78
75
  if (typeof _geojson[0] !== "undefined") {
79
76
  onChange(stringify(_geojson[0]));
80
77
  }
81
78
  } }))),
82
79
  props.type === "polygon" && (React.createElement(React.Fragment, null,
83
- oldGeoJson && (React.createElement(MlGeoJsonLayer, { geojson: oldGeoJson, paint: {
80
+ oldGeoJson && (React.createElement(MlGeoJsonLayer, { mapId: props === null || props === void 0 ? void 0 : props.mapId, geojson: oldGeoJson, paint: {
84
81
  "fill-color": "#6f6f96",
85
82
  "fill-opacity": 0.6,
86
- }, type: "fill" })),
87
- React.createElement(MlFeatureEditor, { geojson: geojson, mode: geojson ? "custom_select" : "draw_polygon", onChange: (_geojson) => {
83
+ }, type: "fill", insertBeforeLayer: "gl-draw-polygon-fill-inactive.cold" })),
84
+ React.createElement(MlFeatureEditor, { mapId: props === null || props === void 0 ? void 0 : props.mapId, geojson: geojson, mode: geojson ? "custom_select" : "draw_polygon", onChange: (_geojson) => {
88
85
  if (typeof _geojson[0] !== "undefined") {
89
86
  onChange(stringify(_geojson[0]));
90
87
  }
91
88
  } }))),
92
89
  props.type === "line" && (React.createElement(React.Fragment, null,
93
- oldGeoJson && (React.createElement(MlGeoJsonLayer, { geojson: oldGeoJson, paint: {
90
+ oldGeoJson && (React.createElement(MlGeoJsonLayer, { mapId: props === null || props === void 0 ? void 0 : props.mapId, geojson: oldGeoJson, paint: {
94
91
  "line-width": 6,
95
92
  "line-color": "#6f6f96",
96
93
  "line-opacity": 0.6,
97
- }, type: "line" })),
98
- React.createElement(MlFeatureEditor, { geojson: geojson, mode: geojson ? "custom_select" : "draw_line_string", onChange: (_geojson) => {
94
+ }, type: "line", insertBeforeLayer: "gl-draw-polygon-fill-inactive.cold" })),
95
+ React.createElement(MlFeatureEditor, { mapId: props === null || props === void 0 ? void 0 : props.mapId, geojson: geojson, mode: geojson ? "custom_select" : "draw_line_string", onChange: (_geojson) => {
99
96
  if (typeof _geojson[0] !== "undefined") {
100
97
  onChange(stringify(_geojson[0]));
101
98
  }
@@ -103,51 +100,56 @@ function GeospatialInputMap(props) {
103
100
  }
104
101
  GeospatialInputMap.defaultProps = {
105
102
  type: "point",
103
+ embeddedMap: true,
106
104
  };
107
105
 
108
106
  function GeospatialInput(props) {
109
- return (React.createElement(MapComponentsProvider, null,
110
- React.createElement(GeospatialInputMap, Object.assign({}, props))));
111
- }
107
+ return (React.createElement(React.Fragment, null, props.embeddedMap ? (React.createElement(MapComponentsProvider, null,
108
+ React.createElement(GeospatialInputMap, Object.assign({}, props)))) : (React.createElement(GeospatialInputMap, Object.assign({}, props)))));
109
+ }
110
+ GeospatialInput.defaultProps = {
111
+ embeddedMap: true,
112
+ };
112
113
 
113
- function GeometryShowMap(props) {
114
+ function GeospatialShowMap(props) {
115
+ var _a, _b;
114
116
  const source = props.source;
115
117
  const record = useRecordContext();
116
118
  const mapHook = useMap();
117
119
  const [geojson, setGeojson] = useState();
118
120
  useEffect(() => {
119
- if (typeof record === "undefined")
121
+ if (!(record === null || record === void 0 ? void 0 : record[source]))
120
122
  return;
121
- setGeojson({
122
- type: "Feature",
123
- properties: {},
124
- geometry: parse(record[source]),
125
- });
126
- //console.log(record)
127
- //onChange({target:{value:"POINT(7.083199846086359 50.73716918021759)"}});
123
+ const _geometry = parse(record[source]);
124
+ if (_geometry) {
125
+ setGeojson({
126
+ type: "Feature",
127
+ properties: {},
128
+ geometry: _geometry,
129
+ });
130
+ }
128
131
  }, [record]);
129
132
  useEffect(() => {
130
133
  var _a;
131
- if (!mapHook.map)
134
+ if (!mapHook.map || !geojson)
132
135
  return;
133
- const _center = centroid(parse(record[source]));
136
+ const _center = centroid(geojson);
134
137
  if ((_a = _center === null || _center === void 0 ? void 0 : _center.geometry) === null || _a === void 0 ? void 0 : _a.coordinates) {
135
138
  mapHook.map.setCenter(_center.geometry.coordinates);
136
139
  }
137
- }, [mapHook.map]);
140
+ }, [mapHook.map, geojson]);
138
141
  return (React.createElement(React.Fragment, null,
139
- React.createElement(MapLibreMap, { options: {
140
- zoom: 14.5,
141
- style: "https://wms.wheregroup.com/tileserver/style/klokantech-basic.json",
142
- center: [0, 0],
143
- }, style: { width: "100%", height: "400px" } }),
142
+ props.embeddedMap && (React.createElement(MapLibreMap, Object.assign({}, props === null || props === void 0 ? void 0 : props.MapLibreMapProps, { options: Object.assign({ zoom: 14, style: "https://wms.wheregroup.com/tileserver/style/klokantech-basic.json", center: [0, 0] }, (_a = props === null || props === void 0 ? void 0 : props.MapLibreMapProps) === null || _a === void 0 ? void 0 : _a.options), style: Object.assign({ width: "100%", height: "400px" }, (_b = props === null || props === void 0 ? void 0 : props.MapLibreMapProps) === null || _b === void 0 ? void 0 : _b.style) }))),
144
143
  geojson && React.createElement(MlGeoJsonLayer, { geojson: geojson })));
145
144
  }
146
145
 
147
- function GeometryShow(props) {
148
- return (React.createElement(MapComponentsProvider, null,
149
- React.createElement(GeometryShowMap, Object.assign({}, props))));
150
- }
146
+ function GeospatialShow(props) {
147
+ return (React.createElement(React.Fragment, null, props.embeddedMap ? (React.createElement(MapComponentsProvider, null,
148
+ React.createElement(GeospatialShowMap, Object.assign({}, props)))) : (React.createElement(GeospatialShowMap, Object.assign({}, props)))));
149
+ }
150
+ GeospatialShow.defaultProps = {
151
+ embeddedMap: true,
152
+ };
151
153
 
152
- export { GeospatialInput as RaGeospatialInput, GeometryShow as RaGeospatialShow };
154
+ export { GeospatialInput as RaGeospatialInput, GeospatialShow as RaGeospatialShow };
153
155
  //# sourceMappingURL=index.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapcomponents/ra-geospatial",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
5
  "private": false,
6
6
  "main": "index.js",
@@ -3,14 +3,22 @@ import { MapComponentsProvider } from "@mapcomponents/react-maplibre";
3
3
  import GeometryInputMap, {
4
4
  GeospatialInputMapProps,
5
5
  } from "./GeospatialInputMap.js";
6
- import { InputProps } from "react-admin";
7
6
 
8
7
  function GeospatialInput(props: GeospatialInputMapProps) {
9
8
  return (
10
- <MapComponentsProvider>
11
- <GeometryInputMap {...props} />
12
- </MapComponentsProvider>
9
+ <>
10
+ {props.embeddedMap ? (
11
+ <MapComponentsProvider>
12
+ <GeometryInputMap {...props} />
13
+ </MapComponentsProvider>
14
+ ) : (
15
+ <GeometryInputMap {...props} />
16
+ )}
17
+ </>
13
18
  );
14
19
  }
20
+ GeospatialInput.defaultProps = {
21
+ embeddedMap: true,
22
+ };
15
23
 
16
24
  export default GeospatialInput;
@@ -18,14 +18,16 @@ import { feature, centroid } from "@turf/turf";
18
18
  import { Feature } from "@turf/helpers";
19
19
 
20
20
  export interface GeospatialInputMapProps extends InputProps<any> {
21
- MapLibreMapProps?: unknown;
21
+ MapLibreMapProps?: React.ComponentProps<typeof MapLibreMap>;
22
22
  geometrytype?: "point" | "line" | "polygon";
23
+ embeddedMap?: boolean;
24
+ mapId?: string;
23
25
  }
24
26
 
25
27
  function GeospatialInputMap(props: GeospatialInputMapProps) {
26
28
  const source = props?.source;
27
29
  const record = useRecordContext();
28
- const mapHook = useMap();
30
+ const mapHook = useMap({mapId:props?.mapId});
29
31
 
30
32
  const [geojson, setGeojson] = useState<typeof feature>();
31
33
  const [oldGeoJson, setOldGeoJson] = useState<typeof feature>();
@@ -65,20 +67,29 @@ function GeospatialInputMap(props: GeospatialInputMapProps) {
65
67
 
66
68
  return (
67
69
  <>
68
- <MapLibreMap
69
- options={{
70
- zoom: 14.5,
71
- style:
72
- "https://wms.wheregroup.com/tileserver/style/klokantech-basic.json",
73
- center: [7.0851268, 50.73884],
74
- }}
75
- style={{ width: "100%", height: "400px" }}
76
- />
70
+ {props.embeddedMap && (
71
+ <MapLibreMap
72
+ {...props?.MapLibreMapProps}
73
+ options={{
74
+ zoom: 14,
75
+ style:
76
+ "https://wms.wheregroup.com/tileserver/style/klokantech-basic.json",
77
+ center: [0, 0],
78
+ ...props?.MapLibreMapProps?.options,
79
+ }}
80
+ style={{
81
+ width: "100%",
82
+ height: "400px",
83
+ ...props?.MapLibreMapProps?.style,
84
+ }}
85
+ />
86
+ )}
77
87
 
78
88
  {props.type === "point" && (
79
89
  <>
80
90
  {oldGeoJson && (
81
91
  <MlGeoJsonLayer
92
+ mapId={props?.mapId}
82
93
  geojson={oldGeoJson as typeof feature}
83
94
  paint={{
84
95
  "circle-radius": 8,
@@ -88,10 +99,12 @@ function GeospatialInputMap(props: GeospatialInputMapProps) {
88
99
  "circle-opacity": 0.8,
89
100
  }}
90
101
  type="circle"
102
+ insertBeforeLayer="gl-draw-polygon-fill-inactive.cold"
91
103
  />
92
104
  )}
93
105
 
94
106
  <MlFeatureEditor
107
+ mapId={props?.mapId}
95
108
  geojson={geojson as typeof feature}
96
109
  mode={geojson ? "custom_select" : "draw_point"}
97
110
  onChange={(_geojson) => {
@@ -106,16 +119,19 @@ function GeospatialInputMap(props: GeospatialInputMapProps) {
106
119
  <>
107
120
  {oldGeoJson && (
108
121
  <MlGeoJsonLayer
122
+ mapId={props?.mapId}
109
123
  geojson={oldGeoJson as typeof feature}
110
124
  paint={{
111
125
  "fill-color": "#6f6f96",
112
126
  "fill-opacity": 0.6,
113
127
  }}
114
128
  type="fill"
129
+ insertBeforeLayer="gl-draw-polygon-fill-inactive.cold"
115
130
  />
116
131
  )}
117
132
 
118
133
  <MlFeatureEditor
134
+ mapId={props?.mapId}
119
135
  geojson={geojson as typeof feature}
120
136
  mode={geojson ? "custom_select" : "draw_polygon"}
121
137
  onChange={(_geojson) => {
@@ -130,6 +146,7 @@ function GeospatialInputMap(props: GeospatialInputMapProps) {
130
146
  <>
131
147
  {oldGeoJson && (
132
148
  <MlGeoJsonLayer
149
+ mapId={props?.mapId}
133
150
  geojson={oldGeoJson as typeof feature}
134
151
  paint={{
135
152
  "line-width": 6,
@@ -137,10 +154,12 @@ function GeospatialInputMap(props: GeospatialInputMapProps) {
137
154
  "line-opacity": 0.6,
138
155
  }}
139
156
  type="line"
157
+ insertBeforeLayer="gl-draw-polygon-fill-inactive.cold"
140
158
  />
141
159
  )}
142
160
 
143
161
  <MlFeatureEditor
162
+ mapId={props?.mapId}
144
163
  geojson={geojson as typeof feature}
145
164
  mode={geojson ? "custom_select" : "draw_line_string"}
146
165
  onChange={(_geojson) => {
@@ -157,6 +176,7 @@ function GeospatialInputMap(props: GeospatialInputMapProps) {
157
176
 
158
177
  GeospatialInputMap.defaultProps = {
159
178
  type: "point",
179
+ embeddedMap: true,
160
180
  };
161
181
 
162
182
  export default GeospatialInputMap;
@@ -0,0 +1,24 @@
1
+ import React from "react";
2
+ import { MapComponentsProvider } from "@mapcomponents/react-maplibre";
3
+ import GeometryShowMap, {
4
+ GeospatialShowMapProps,
5
+ } from "./GeospatialShowMap.js";
6
+
7
+ function GeospatialShow(props: GeospatialShowMapProps) {
8
+ return (
9
+ <>
10
+ {props.embeddedMap ? (
11
+ <MapComponentsProvider>
12
+ <GeometryShowMap {...props} />
13
+ </MapComponentsProvider>
14
+ ) : (
15
+ <GeometryShowMap {...props} />
16
+ )}
17
+ </>
18
+ );
19
+ }
20
+ GeospatialShow.defaultProps = {
21
+ embeddedMap: true,
22
+ };
23
+
24
+ export default GeospatialShow;
@@ -0,0 +1,74 @@
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";
12
+
13
+ export interface GeospatialShowMapProps extends InputProps<any> {
14
+ MapLibreMapProps?: React.ComponentProps<typeof MapLibreMap>;
15
+ embeddedMap?: boolean;
16
+ mapId?: string;
17
+ }
18
+
19
+ function GeospatialShowMap(props: GeospatialShowMapProps) {
20
+ const source = props.source;
21
+ const record = useRecordContext();
22
+ const mapHook = useMap();
23
+
24
+ const [geojson, setGeojson] = useState<typeof feature>();
25
+ useEffect(() => {
26
+ if (!record?.[source]) return;
27
+
28
+ const _geometry = wellknownParse(record[source]);
29
+
30
+ if (_geometry) {
31
+ setGeojson({
32
+ type: "Feature",
33
+ properties: {},
34
+ geometry: _geometry,
35
+ } as unknown as typeof feature);
36
+ }
37
+ }, [record]);
38
+
39
+ useEffect(() => {
40
+ if (!mapHook.map || !geojson) return;
41
+
42
+ const _center = centroid(geojson as typeof Feature);
43
+
44
+ if (_center?.geometry?.coordinates) {
45
+ mapHook.map.setCenter(_center.geometry.coordinates as LngLatLike);
46
+ }
47
+ }, [mapHook.map, geojson]);
48
+
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
+ )}
68
+
69
+ {geojson && <MlGeoJsonLayer geojson={geojson}></MlGeoJsonLayer>}
70
+ </>
71
+ );
72
+ }
73
+
74
+ export default GeospatialShowMap;
package/src/index.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export {default as RaGeospatialInput} from "./components/GeospatialInput.js";
2
- export {default as RaGeospatialShow} from "./components/GeometryShow.js";
2
+ export {default as RaGeospatialShow} from "./components/GeospatialShow.js";
@@ -1,14 +0,0 @@
1
- import React from "react"
2
- import {MapComponentsProvider} from "@mapcomponents/react-maplibre";
3
- import GeometryShowMap from "./GeometryShowMap.js";
4
- import { InputProps } from "react-admin";
5
-
6
- function GeometryShow(props:InputProps<any>) {
7
- return (
8
- <MapComponentsProvider>
9
- <GeometryShowMap {...props} />
10
- </MapComponentsProvider>
11
- )
12
- }
13
-
14
- export default GeometryShow
@@ -1,58 +0,0 @@
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";
12
-
13
- function GeometryShowMap(props: InputProps<any>) {
14
- const source = props.source;
15
- const record = useRecordContext();
16
- const mapHook = useMap();
17
-
18
- const [geojson, setGeojson] = useState<typeof feature>();
19
- useEffect(() => {
20
- if (typeof record === "undefined") return;
21
-
22
- setGeojson({
23
- type: "Feature",
24
- properties: {},
25
- geometry: wellknownParse(record[source]),
26
- } as unknown as typeof feature);
27
- //console.log(record)
28
- //onChange({target:{value:"POINT(7.083199846086359 50.73716918021759)"}});
29
- }, [record]);
30
-
31
- useEffect(() => {
32
- if (!mapHook.map) return;
33
-
34
- const _center = centroid(wellknownParse(record[source]) as typeof Feature);
35
-
36
- if (_center?.geometry?.coordinates) {
37
- mapHook.map.setCenter(_center.geometry.coordinates as LngLatLike);
38
- }
39
- }, [mapHook.map]);
40
-
41
- return (
42
- <>
43
- <MapLibreMap
44
- options={{
45
- zoom: 14.5,
46
- style:
47
- "https://wms.wheregroup.com/tileserver/style/klokantech-basic.json",
48
- center: [0, 0],
49
- }}
50
- style={{ width: "100%", height: "400px" }}
51
- />
52
-
53
- {geojson && <MlGeoJsonLayer geojson={geojson}></MlGeoJsonLayer>}
54
- </>
55
- );
56
- }
57
-
58
- export default GeometryShowMap;