@mapcomponents/ra-geospatial 1.0.2 → 1.0.3

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
@@ -34,7 +34,7 @@ function __rest(s, e) {
34
34
  function GeospatialInputMap(props) {
35
35
  const source = props === null || props === void 0 ? void 0 : props.source;
36
36
  const record = useRecordContext();
37
- const mapHook = useMap();
37
+ const mapHook = useMap({ mapId: props === null || props === void 0 ? void 0 : props.mapId });
38
38
  const [geojson, setGeojson] = useState();
39
39
  const [oldGeoJson, setOldGeoJson] = useState();
40
40
  const _a = useInput(props), _b = _a.field, { name, onChange } = _b; __rest(_b, ["name", "onChange"]);
@@ -61,41 +61,41 @@ function GeospatialInputMap(props) {
61
61
  }
62
62
  }, [mapHook.map]);
63
63
  return (React.createElement(React.Fragment, null,
64
- React.createElement(MapLibreMap, { options: {
64
+ props.embeddedMap && (React.createElement(MapLibreMap, { options: {
65
65
  zoom: 14.5,
66
66
  style: "https://wms.wheregroup.com/tileserver/style/klokantech-basic.json",
67
67
  center: [7.0851268, 50.73884],
68
- }, style: { width: "100%", height: "400px" } }),
68
+ }, style: { width: "100%", height: "400px" } })),
69
69
  props.type === "point" && (React.createElement(React.Fragment, null,
70
- oldGeoJson && (React.createElement(MlGeoJsonLayer, { geojson: oldGeoJson, paint: {
70
+ oldGeoJson && (React.createElement(MlGeoJsonLayer, { mapId: props === null || props === void 0 ? void 0 : props.mapId, geojson: oldGeoJson, paint: {
71
71
  "circle-radius": 8,
72
72
  "circle-color": "#6f6f96",
73
73
  "circle-stroke-color": "white",
74
74
  "circle-stroke-width": 3,
75
75
  "circle-opacity": 0.8,
76
- }, type: "circle" })),
77
- React.createElement(MlFeatureEditor, { geojson: geojson, mode: geojson ? "custom_select" : "draw_point", onChange: (_geojson) => {
76
+ }, type: "circle", insertBeforeLayer: "gl-draw-polygon-fill-inactive.cold" })),
77
+ React.createElement(MlFeatureEditor, { mapId: props === null || props === void 0 ? void 0 : props.mapId, geojson: geojson, mode: geojson ? "custom_select" : "draw_point", onChange: (_geojson) => {
78
78
  if (typeof _geojson[0] !== "undefined") {
79
79
  onChange(stringify(_geojson[0]));
80
80
  }
81
81
  } }))),
82
82
  props.type === "polygon" && (React.createElement(React.Fragment, null,
83
- oldGeoJson && (React.createElement(MlGeoJsonLayer, { geojson: oldGeoJson, paint: {
83
+ oldGeoJson && (React.createElement(MlGeoJsonLayer, { mapId: props === null || props === void 0 ? void 0 : props.mapId, geojson: oldGeoJson, paint: {
84
84
  "fill-color": "#6f6f96",
85
85
  "fill-opacity": 0.6,
86
- }, type: "fill" })),
87
- React.createElement(MlFeatureEditor, { geojson: geojson, mode: geojson ? "custom_select" : "draw_polygon", onChange: (_geojson) => {
86
+ }, type: "fill", insertBeforeLayer: "gl-draw-polygon-fill-inactive.cold" })),
87
+ React.createElement(MlFeatureEditor, { mapId: props === null || props === void 0 ? void 0 : props.mapId, geojson: geojson, mode: geojson ? "custom_select" : "draw_polygon", onChange: (_geojson) => {
88
88
  if (typeof _geojson[0] !== "undefined") {
89
89
  onChange(stringify(_geojson[0]));
90
90
  }
91
91
  } }))),
92
92
  props.type === "line" && (React.createElement(React.Fragment, null,
93
- oldGeoJson && (React.createElement(MlGeoJsonLayer, { geojson: oldGeoJson, paint: {
93
+ oldGeoJson && (React.createElement(MlGeoJsonLayer, { mapId: props === null || props === void 0 ? void 0 : props.mapId, geojson: oldGeoJson, paint: {
94
94
  "line-width": 6,
95
95
  "line-color": "#6f6f96",
96
96
  "line-opacity": 0.6,
97
- }, type: "line" })),
98
- React.createElement(MlFeatureEditor, { geojson: geojson, mode: geojson ? "custom_select" : "draw_line_string", onChange: (_geojson) => {
97
+ }, type: "line", insertBeforeLayer: "gl-draw-polygon-fill-inactive.cold" })),
98
+ 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
99
  if (typeof _geojson[0] !== "undefined") {
100
100
  onChange(stringify(_geojson[0]));
101
101
  }
@@ -103,14 +103,18 @@ function GeospatialInputMap(props) {
103
103
  }
104
104
  GeospatialInputMap.defaultProps = {
105
105
  type: "point",
106
+ embeddedMap: true,
106
107
  };
107
108
 
108
109
  function GeospatialInput(props) {
109
- return (React.createElement(MapComponentsProvider, null,
110
- React.createElement(GeospatialInputMap, Object.assign({}, props))));
111
- }
110
+ return (React.createElement(React.Fragment, null, props.embeddedMap ? (React.createElement(MapComponentsProvider, null,
111
+ React.createElement(GeospatialInputMap, Object.assign({}, props)))) : (React.createElement(GeospatialInputMap, Object.assign({}, props)))));
112
+ }
113
+ GeospatialInput.defaultProps = {
114
+ embeddedMap: true,
115
+ };
112
116
 
113
- function GeometryShowMap(props) {
117
+ function GeospatialShowMap(props) {
114
118
  const source = props.source;
115
119
  const record = useRecordContext();
116
120
  const mapHook = useMap();
@@ -136,18 +140,21 @@ function GeometryShowMap(props) {
136
140
  }
137
141
  }, [mapHook.map]);
138
142
  return (React.createElement(React.Fragment, null,
139
- React.createElement(MapLibreMap, { options: {
143
+ props.embeddedMap && (React.createElement(MapLibreMap, { options: {
140
144
  zoom: 14.5,
141
145
  style: "https://wms.wheregroup.com/tileserver/style/klokantech-basic.json",
142
146
  center: [0, 0],
143
- }, style: { width: "100%", height: "400px" } }),
147
+ }, style: { width: "100%", height: "400px" } })),
144
148
  geojson && React.createElement(MlGeoJsonLayer, { geojson: geojson })));
145
149
  }
146
150
 
147
- function GeometryShow(props) {
148
- return (React.createElement(MapComponentsProvider, null,
149
- React.createElement(GeometryShowMap, Object.assign({}, props))));
150
- }
151
+ function GeospatialShow(props) {
152
+ return (React.createElement(React.Fragment, null, props.embeddedMap ? (React.createElement(MapComponentsProvider, null,
153
+ React.createElement(GeospatialShowMap, Object.assign({}, props)))) : (React.createElement(GeospatialShowMap, Object.assign({}, props)))));
154
+ }
155
+ GeospatialShow.defaultProps = {
156
+ embeddedMap: true,
157
+ };
151
158
 
152
- export { GeospatialInput as RaGeospatialInput, GeometryShow as RaGeospatialShow };
159
+ export { GeospatialInput as RaGeospatialInput, GeospatialShow as RaGeospatialShow };
153
160
  //# 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.3",
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;
@@ -20,12 +20,14 @@ import { Feature } from "@turf/helpers";
20
20
  export interface GeospatialInputMapProps extends InputProps<any> {
21
21
  MapLibreMapProps?: unknown;
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,23 @@ 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
+ options={{
73
+ zoom: 14.5,
74
+ style:
75
+ "https://wms.wheregroup.com/tileserver/style/klokantech-basic.json",
76
+ center: [7.0851268, 50.73884],
77
+ }}
78
+ style={{ width: "100%", height: "400px" }}
79
+ />
80
+ )}
77
81
 
78
82
  {props.type === "point" && (
79
83
  <>
80
84
  {oldGeoJson && (
81
85
  <MlGeoJsonLayer
86
+ mapId={props?.mapId}
82
87
  geojson={oldGeoJson as typeof feature}
83
88
  paint={{
84
89
  "circle-radius": 8,
@@ -88,10 +93,12 @@ function GeospatialInputMap(props: GeospatialInputMapProps) {
88
93
  "circle-opacity": 0.8,
89
94
  }}
90
95
  type="circle"
96
+ insertBeforeLayer="gl-draw-polygon-fill-inactive.cold"
91
97
  />
92
98
  )}
93
99
 
94
100
  <MlFeatureEditor
101
+ mapId={props?.mapId}
95
102
  geojson={geojson as typeof feature}
96
103
  mode={geojson ? "custom_select" : "draw_point"}
97
104
  onChange={(_geojson) => {
@@ -106,16 +113,19 @@ function GeospatialInputMap(props: GeospatialInputMapProps) {
106
113
  <>
107
114
  {oldGeoJson && (
108
115
  <MlGeoJsonLayer
116
+ mapId={props?.mapId}
109
117
  geojson={oldGeoJson as typeof feature}
110
118
  paint={{
111
119
  "fill-color": "#6f6f96",
112
120
  "fill-opacity": 0.6,
113
121
  }}
114
122
  type="fill"
123
+ insertBeforeLayer="gl-draw-polygon-fill-inactive.cold"
115
124
  />
116
125
  )}
117
126
 
118
127
  <MlFeatureEditor
128
+ mapId={props?.mapId}
119
129
  geojson={geojson as typeof feature}
120
130
  mode={geojson ? "custom_select" : "draw_polygon"}
121
131
  onChange={(_geojson) => {
@@ -130,6 +140,7 @@ function GeospatialInputMap(props: GeospatialInputMapProps) {
130
140
  <>
131
141
  {oldGeoJson && (
132
142
  <MlGeoJsonLayer
143
+ mapId={props?.mapId}
133
144
  geojson={oldGeoJson as typeof feature}
134
145
  paint={{
135
146
  "line-width": 6,
@@ -137,10 +148,12 @@ function GeospatialInputMap(props: GeospatialInputMapProps) {
137
148
  "line-opacity": 0.6,
138
149
  }}
139
150
  type="line"
151
+ insertBeforeLayer="gl-draw-polygon-fill-inactive.cold"
140
152
  />
141
153
  )}
142
154
 
143
155
  <MlFeatureEditor
156
+ mapId={props?.mapId}
144
157
  geojson={geojson as typeof feature}
145
158
  mode={geojson ? "custom_select" : "draw_line_string"}
146
159
  onChange={(_geojson) => {
@@ -157,6 +170,7 @@ function GeospatialInputMap(props: GeospatialInputMapProps) {
157
170
 
158
171
  GeospatialInputMap.defaultProps = {
159
172
  type: "point",
173
+ embeddedMap: true,
160
174
  };
161
175
 
162
176
  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;
@@ -10,7 +10,12 @@ import { LngLatLike } from "maplibre-gl";
10
10
  import { feature, centroid } from "@turf/turf";
11
11
  import { Feature } from "@turf/helpers";
12
12
 
13
- function GeometryShowMap(props: InputProps<any>) {
13
+ export interface GeospatialShowMapProps extends InputProps<any> {
14
+ embeddedMap?: boolean;
15
+ mapId?: string;
16
+ }
17
+
18
+ function GeospatialShowMap(props: GeospatialShowMapProps) {
14
19
  const source = props.source;
15
20
  const record = useRecordContext();
16
21
  const mapHook = useMap();
@@ -40,19 +45,21 @@ function GeometryShowMap(props: InputProps<any>) {
40
45
 
41
46
  return (
42
47
  <>
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
- />
48
+ {props.embeddedMap && (
49
+ <MapLibreMap
50
+ options={{
51
+ zoom: 14.5,
52
+ style:
53
+ "https://wms.wheregroup.com/tileserver/style/klokantech-basic.json",
54
+ center: [0, 0],
55
+ }}
56
+ style={{ width: "100%", height: "400px" }}
57
+ />
58
+ )}
52
59
 
53
60
  {geojson && <MlGeoJsonLayer geojson={geojson}></MlGeoJsonLayer>}
54
61
  </>
55
62
  );
56
63
  }
57
64
 
58
- export default GeometryShowMap;
65
+ 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