@biodiv-platform/naksha-maplibre-draw 5.0.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.
- package/README.md +9 -0
- package/dist/esm/index.js +219 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +244 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// src/index.tsx
|
|
19
|
+
import { MapProvider } from "react-map-gl/maplibre";
|
|
20
|
+
|
|
21
|
+
// src/components/map.tsx
|
|
22
|
+
import {
|
|
23
|
+
defaultMapStyles,
|
|
24
|
+
defaultViewState
|
|
25
|
+
} from "@biodiv-platform/naksha-commons";
|
|
26
|
+
import bbox from "@turf/bbox";
|
|
27
|
+
import { useEffect, useState } from "react";
|
|
28
|
+
import MapGL, { NavigationControl, useMap } from "react-map-gl/maplibre";
|
|
29
|
+
|
|
30
|
+
// src/components/draw-control.tsx
|
|
31
|
+
import { MaplibreTerradrawControl } from "@watergis/maplibre-gl-terradraw";
|
|
32
|
+
import { emit, useListener } from "react-gbus";
|
|
33
|
+
import { useControl } from "react-map-gl/maplibre";
|
|
34
|
+
|
|
35
|
+
// src/components/delete-panel.tsx
|
|
36
|
+
import { jsx } from "react/jsx-runtime";
|
|
37
|
+
function DeletePanel({ onDelete }) {
|
|
38
|
+
return /* @__PURE__ */ jsx("div", {
|
|
39
|
+
className: "maplibregl-ctrl-top-left",
|
|
40
|
+
style: { marginTop: "100px" },
|
|
41
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
42
|
+
className: "maplibregl-ctrl-group maplibregl-ctrl",
|
|
43
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
44
|
+
className: "maplibre-gl-draw_ctrl-draw-btn maplibre-gl-draw_trash",
|
|
45
|
+
title: "Delete",
|
|
46
|
+
onClick: onDelete,
|
|
47
|
+
style: {
|
|
48
|
+
display: "flex",
|
|
49
|
+
justifyContent: "center",
|
|
50
|
+
alignItems: "center",
|
|
51
|
+
width: "30px",
|
|
52
|
+
height: "30px"
|
|
53
|
+
},
|
|
54
|
+
children: /* @__PURE__ */ jsx("svg", {
|
|
55
|
+
width: "16",
|
|
56
|
+
height: "16",
|
|
57
|
+
viewBox: "0 0 24 24",
|
|
58
|
+
fill: "none",
|
|
59
|
+
stroke: "currentColor",
|
|
60
|
+
strokeWidth: "2",
|
|
61
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
62
|
+
d: "M3 6h18M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/components/draw-control.tsx
|
|
71
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
72
|
+
var UPDATE_EVENT = "rmsc-draw-updated";
|
|
73
|
+
function DrawControl(props) {
|
|
74
|
+
useListener(onUpdate, [UPDATE_EVENT]);
|
|
75
|
+
function onUpdate(e) {
|
|
76
|
+
var _a;
|
|
77
|
+
if (!terradrawControl)
|
|
78
|
+
return;
|
|
79
|
+
const allFeatures = terradrawControl.getFeatures().features;
|
|
80
|
+
const _features = props.isMultiple ? allFeatures : [allFeatures[allFeatures.length - 1]];
|
|
81
|
+
(_a = props.setFeatures) == null ? void 0 : _a.call(props, _features);
|
|
82
|
+
}
|
|
83
|
+
const terradrawControl = useControl(
|
|
84
|
+
({ map }) => {
|
|
85
|
+
const ctrl = new MaplibreTerradrawControl({
|
|
86
|
+
modes: ["point", "linestring", "polygon"],
|
|
87
|
+
open: true
|
|
88
|
+
});
|
|
89
|
+
map.on("terradraw.create", (e) => {
|
|
90
|
+
if (!props.isMultiple) {
|
|
91
|
+
ctrl.terradraw.clear();
|
|
92
|
+
}
|
|
93
|
+
ctrl.getTerraDrawInstance().setMode("select");
|
|
94
|
+
emit(UPDATE_EVENT, e);
|
|
95
|
+
});
|
|
96
|
+
map.on("terradraw.update", (e) => emit(UPDATE_EVENT, e));
|
|
97
|
+
map.on("terradraw.delete", (e) => emit(UPDATE_EVENT, e));
|
|
98
|
+
return ctrl;
|
|
99
|
+
},
|
|
100
|
+
() => {
|
|
101
|
+
},
|
|
102
|
+
{ position: "top-left" }
|
|
103
|
+
);
|
|
104
|
+
const onDelete = () => {
|
|
105
|
+
var _a;
|
|
106
|
+
terradrawControl.terradraw.clear();
|
|
107
|
+
(_a = props.setFeatures) == null ? void 0 : _a.call(props, []);
|
|
108
|
+
};
|
|
109
|
+
return /* @__PURE__ */ jsx2(DeletePanel, {
|
|
110
|
+
onDelete
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// src/components/geojson-layer.tsx
|
|
115
|
+
import { Layer, Source } from "react-map-gl/maplibre";
|
|
116
|
+
|
|
117
|
+
// src/static/constants.tsx
|
|
118
|
+
var featureStyle = {
|
|
119
|
+
id: "data",
|
|
120
|
+
type: "fill",
|
|
121
|
+
paint: {
|
|
122
|
+
"fill-color": "#f03b20",
|
|
123
|
+
"fill-opacity": 0.2
|
|
124
|
+
},
|
|
125
|
+
filter: ["==", ["geometry-type"], "Polygon"]
|
|
126
|
+
};
|
|
127
|
+
var pointStyle = {
|
|
128
|
+
type: "circle",
|
|
129
|
+
paint: {
|
|
130
|
+
"circle-radius": 8,
|
|
131
|
+
"circle-color": "#f03b20",
|
|
132
|
+
"circle-opacity": 0.8
|
|
133
|
+
},
|
|
134
|
+
filter: ["==", ["geometry-type"], "Point"]
|
|
135
|
+
};
|
|
136
|
+
var lineStyle = {
|
|
137
|
+
type: "line",
|
|
138
|
+
paint: {
|
|
139
|
+
"line-color": "#f03b20",
|
|
140
|
+
"line-width": 1.6,
|
|
141
|
+
"line-dasharray": [6, 3],
|
|
142
|
+
"line-opacity": 0.8
|
|
143
|
+
},
|
|
144
|
+
filter: ["==", ["geometry-type"], "LineString"]
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// src/components/geojson-layer.tsx
|
|
148
|
+
import { jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
149
|
+
function GeojsonLayer({ features }) {
|
|
150
|
+
if (!(features == null ? void 0 : features.length))
|
|
151
|
+
return null;
|
|
152
|
+
return /* @__PURE__ */ jsxs(Source, {
|
|
153
|
+
type: "geojson",
|
|
154
|
+
data: { type: "FeatureCollection", features },
|
|
155
|
+
children: [
|
|
156
|
+
/* @__PURE__ */ jsx3(Layer, __spreadValues({}, pointStyle)),
|
|
157
|
+
/* @__PURE__ */ jsx3(Layer, __spreadValues({}, lineStyle)),
|
|
158
|
+
/* @__PURE__ */ jsx3(Layer, __spreadValues({}, featureStyle))
|
|
159
|
+
]
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// src/components/map.tsx
|
|
164
|
+
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
165
|
+
var NavControl = NavigationControl;
|
|
166
|
+
function Map(props) {
|
|
167
|
+
const { mapv } = useMap();
|
|
168
|
+
const [mapStyle] = useState(defaultMapStyles[(props == null ? void 0 : props.mapStyle) || 0].style);
|
|
169
|
+
const [viewState] = useState(props.defaultViewState || defaultViewState);
|
|
170
|
+
const [features, setFeatures] = useState(props.features || []);
|
|
171
|
+
const autoFocus = () => {
|
|
172
|
+
if (!(features == null ? void 0 : features.length) || !mapv)
|
|
173
|
+
return;
|
|
174
|
+
const _bbox = bbox({ type: "FeatureCollection", features });
|
|
175
|
+
mapv.fitBounds(_bbox, { padding: 40, duration: 1e3 });
|
|
176
|
+
};
|
|
177
|
+
useEffect(() => {
|
|
178
|
+
props.onFeaturesChange && props.onFeaturesChange(features);
|
|
179
|
+
autoFocus();
|
|
180
|
+
}, [features]);
|
|
181
|
+
useEffect(() => {
|
|
182
|
+
if (props.isControlled && JSON.stringify(features) !== JSON.stringify(props.features)) {
|
|
183
|
+
setFeatures(props.features || []);
|
|
184
|
+
}
|
|
185
|
+
}, [props.features]);
|
|
186
|
+
return /* @__PURE__ */ jsxs2(MapGL, {
|
|
187
|
+
id: "mapv",
|
|
188
|
+
cursor: "default",
|
|
189
|
+
initialViewState: viewState,
|
|
190
|
+
style: { width: "100%", height: "100%" },
|
|
191
|
+
mapStyle,
|
|
192
|
+
onLoad: autoFocus,
|
|
193
|
+
children: [
|
|
194
|
+
/* @__PURE__ */ jsx4(NavControl, {
|
|
195
|
+
position: "bottom-right",
|
|
196
|
+
showZoom: true,
|
|
197
|
+
showCompass: true
|
|
198
|
+
}),
|
|
199
|
+
/* @__PURE__ */ jsx4(DrawControl, {
|
|
200
|
+
features,
|
|
201
|
+
setFeatures,
|
|
202
|
+
isControlled: props.isControlled,
|
|
203
|
+
isMultiple: props.isMultiple
|
|
204
|
+
}),
|
|
205
|
+
/* @__PURE__ */ jsx4(GeojsonLayer, {
|
|
206
|
+
features
|
|
207
|
+
})
|
|
208
|
+
]
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// src/index.tsx
|
|
213
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
214
|
+
var NakshaMaplibreDraw = (props) => /* @__PURE__ */ jsx5(MapProvider, {
|
|
215
|
+
children: /* @__PURE__ */ jsx5(Map, __spreadValues({}, props))
|
|
216
|
+
});
|
|
217
|
+
export {
|
|
218
|
+
NakshaMaplibreDraw
|
|
219
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { MapStyles } from '@biodiv-platform/naksha-commons';
|
|
2
|
+
import { ViewState } from 'react-map-gl/maplibre';
|
|
3
|
+
|
|
4
|
+
interface NakshaMaplibreViewProps {
|
|
5
|
+
defaultViewState?: Partial<ViewState>;
|
|
6
|
+
mapStyle?: MapStyles;
|
|
7
|
+
features?: any;
|
|
8
|
+
onFeaturesChange?: any;
|
|
9
|
+
isControlled?: boolean;
|
|
10
|
+
isMultiple?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare const NakshaMaplibreDraw: (props: NakshaMaplibreViewProps) => JSX.Element;
|
|
14
|
+
|
|
15
|
+
export { NakshaMaplibreDraw };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
22
|
+
var __export = (target, all) => {
|
|
23
|
+
for (var name in all)
|
|
24
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
25
|
+
};
|
|
26
|
+
var __copyProps = (to, from, except, desc) => {
|
|
27
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
28
|
+
for (let key of __getOwnPropNames(from))
|
|
29
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
30
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
31
|
+
}
|
|
32
|
+
return to;
|
|
33
|
+
};
|
|
34
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
35
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
36
|
+
mod
|
|
37
|
+
));
|
|
38
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
39
|
+
|
|
40
|
+
// src/index.tsx
|
|
41
|
+
var src_exports = {};
|
|
42
|
+
__export(src_exports, {
|
|
43
|
+
NakshaMaplibreDraw: () => NakshaMaplibreDraw
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(src_exports);
|
|
46
|
+
var import_maplibre4 = require("react-map-gl/maplibre");
|
|
47
|
+
|
|
48
|
+
// src/components/map.tsx
|
|
49
|
+
var import_naksha_commons = require("@biodiv-platform/naksha-commons");
|
|
50
|
+
var import_bbox = __toESM(require("@turf/bbox"));
|
|
51
|
+
var import_react = require("react");
|
|
52
|
+
var import_maplibre3 = __toESM(require("react-map-gl/maplibre"));
|
|
53
|
+
|
|
54
|
+
// src/components/draw-control.tsx
|
|
55
|
+
var import_maplibre_gl_terradraw = require("@watergis/maplibre-gl-terradraw");
|
|
56
|
+
var import_react_gbus = require("react-gbus");
|
|
57
|
+
var import_maplibre = require("react-map-gl/maplibre");
|
|
58
|
+
|
|
59
|
+
// src/components/delete-panel.tsx
|
|
60
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
61
|
+
function DeletePanel({ onDelete }) {
|
|
62
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
63
|
+
className: "maplibregl-ctrl-top-left",
|
|
64
|
+
style: { marginTop: "100px" },
|
|
65
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
66
|
+
className: "maplibregl-ctrl-group maplibregl-ctrl",
|
|
67
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
68
|
+
className: "maplibre-gl-draw_ctrl-draw-btn maplibre-gl-draw_trash",
|
|
69
|
+
title: "Delete",
|
|
70
|
+
onClick: onDelete,
|
|
71
|
+
style: {
|
|
72
|
+
display: "flex",
|
|
73
|
+
justifyContent: "center",
|
|
74
|
+
alignItems: "center",
|
|
75
|
+
width: "30px",
|
|
76
|
+
height: "30px"
|
|
77
|
+
},
|
|
78
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", {
|
|
79
|
+
width: "16",
|
|
80
|
+
height: "16",
|
|
81
|
+
viewBox: "0 0 24 24",
|
|
82
|
+
fill: "none",
|
|
83
|
+
stroke: "currentColor",
|
|
84
|
+
strokeWidth: "2",
|
|
85
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", {
|
|
86
|
+
d: "M3 6h18M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// src/components/draw-control.tsx
|
|
95
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
96
|
+
var UPDATE_EVENT = "rmsc-draw-updated";
|
|
97
|
+
function DrawControl(props) {
|
|
98
|
+
(0, import_react_gbus.useListener)(onUpdate, [UPDATE_EVENT]);
|
|
99
|
+
function onUpdate(e) {
|
|
100
|
+
var _a;
|
|
101
|
+
if (!terradrawControl)
|
|
102
|
+
return;
|
|
103
|
+
const allFeatures = terradrawControl.getFeatures().features;
|
|
104
|
+
const _features = props.isMultiple ? allFeatures : [allFeatures[allFeatures.length - 1]];
|
|
105
|
+
(_a = props.setFeatures) == null ? void 0 : _a.call(props, _features);
|
|
106
|
+
}
|
|
107
|
+
const terradrawControl = (0, import_maplibre.useControl)(
|
|
108
|
+
({ map }) => {
|
|
109
|
+
const ctrl = new import_maplibre_gl_terradraw.MaplibreTerradrawControl({
|
|
110
|
+
modes: ["point", "linestring", "polygon"],
|
|
111
|
+
open: true
|
|
112
|
+
});
|
|
113
|
+
map.on("terradraw.create", (e) => {
|
|
114
|
+
if (!props.isMultiple) {
|
|
115
|
+
ctrl.terradraw.clear();
|
|
116
|
+
}
|
|
117
|
+
ctrl.getTerraDrawInstance().setMode("select");
|
|
118
|
+
(0, import_react_gbus.emit)(UPDATE_EVENT, e);
|
|
119
|
+
});
|
|
120
|
+
map.on("terradraw.update", (e) => (0, import_react_gbus.emit)(UPDATE_EVENT, e));
|
|
121
|
+
map.on("terradraw.delete", (e) => (0, import_react_gbus.emit)(UPDATE_EVENT, e));
|
|
122
|
+
return ctrl;
|
|
123
|
+
},
|
|
124
|
+
() => {
|
|
125
|
+
},
|
|
126
|
+
{ position: "top-left" }
|
|
127
|
+
);
|
|
128
|
+
const onDelete = () => {
|
|
129
|
+
var _a;
|
|
130
|
+
terradrawControl.terradraw.clear();
|
|
131
|
+
(_a = props.setFeatures) == null ? void 0 : _a.call(props, []);
|
|
132
|
+
};
|
|
133
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(DeletePanel, {
|
|
134
|
+
onDelete
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/components/geojson-layer.tsx
|
|
139
|
+
var import_maplibre2 = require("react-map-gl/maplibre");
|
|
140
|
+
|
|
141
|
+
// src/static/constants.tsx
|
|
142
|
+
var featureStyle = {
|
|
143
|
+
id: "data",
|
|
144
|
+
type: "fill",
|
|
145
|
+
paint: {
|
|
146
|
+
"fill-color": "#f03b20",
|
|
147
|
+
"fill-opacity": 0.2
|
|
148
|
+
},
|
|
149
|
+
filter: ["==", ["geometry-type"], "Polygon"]
|
|
150
|
+
};
|
|
151
|
+
var pointStyle = {
|
|
152
|
+
type: "circle",
|
|
153
|
+
paint: {
|
|
154
|
+
"circle-radius": 8,
|
|
155
|
+
"circle-color": "#f03b20",
|
|
156
|
+
"circle-opacity": 0.8
|
|
157
|
+
},
|
|
158
|
+
filter: ["==", ["geometry-type"], "Point"]
|
|
159
|
+
};
|
|
160
|
+
var lineStyle = {
|
|
161
|
+
type: "line",
|
|
162
|
+
paint: {
|
|
163
|
+
"line-color": "#f03b20",
|
|
164
|
+
"line-width": 1.6,
|
|
165
|
+
"line-dasharray": [6, 3],
|
|
166
|
+
"line-opacity": 0.8
|
|
167
|
+
},
|
|
168
|
+
filter: ["==", ["geometry-type"], "LineString"]
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// src/components/geojson-layer.tsx
|
|
172
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
173
|
+
function GeojsonLayer({ features }) {
|
|
174
|
+
if (!(features == null ? void 0 : features.length))
|
|
175
|
+
return null;
|
|
176
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_maplibre2.Source, {
|
|
177
|
+
type: "geojson",
|
|
178
|
+
data: { type: "FeatureCollection", features },
|
|
179
|
+
children: [
|
|
180
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_maplibre2.Layer, __spreadValues({}, pointStyle)),
|
|
181
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_maplibre2.Layer, __spreadValues({}, lineStyle)),
|
|
182
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_maplibre2.Layer, __spreadValues({}, featureStyle))
|
|
183
|
+
]
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// src/components/map.tsx
|
|
188
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
189
|
+
var NavControl = import_maplibre3.NavigationControl;
|
|
190
|
+
function Map(props) {
|
|
191
|
+
const { mapv } = (0, import_maplibre3.useMap)();
|
|
192
|
+
const [mapStyle] = (0, import_react.useState)(import_naksha_commons.defaultMapStyles[(props == null ? void 0 : props.mapStyle) || 0].style);
|
|
193
|
+
const [viewState] = (0, import_react.useState)(props.defaultViewState || import_naksha_commons.defaultViewState);
|
|
194
|
+
const [features, setFeatures] = (0, import_react.useState)(props.features || []);
|
|
195
|
+
const autoFocus = () => {
|
|
196
|
+
if (!(features == null ? void 0 : features.length) || !mapv)
|
|
197
|
+
return;
|
|
198
|
+
const _bbox = (0, import_bbox.default)({ type: "FeatureCollection", features });
|
|
199
|
+
mapv.fitBounds(_bbox, { padding: 40, duration: 1e3 });
|
|
200
|
+
};
|
|
201
|
+
(0, import_react.useEffect)(() => {
|
|
202
|
+
props.onFeaturesChange && props.onFeaturesChange(features);
|
|
203
|
+
autoFocus();
|
|
204
|
+
}, [features]);
|
|
205
|
+
(0, import_react.useEffect)(() => {
|
|
206
|
+
if (props.isControlled && JSON.stringify(features) !== JSON.stringify(props.features)) {
|
|
207
|
+
setFeatures(props.features || []);
|
|
208
|
+
}
|
|
209
|
+
}, [props.features]);
|
|
210
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_maplibre3.default, {
|
|
211
|
+
id: "mapv",
|
|
212
|
+
cursor: "default",
|
|
213
|
+
initialViewState: viewState,
|
|
214
|
+
style: { width: "100%", height: "100%" },
|
|
215
|
+
mapStyle,
|
|
216
|
+
onLoad: autoFocus,
|
|
217
|
+
children: [
|
|
218
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(NavControl, {
|
|
219
|
+
position: "bottom-right",
|
|
220
|
+
showZoom: true,
|
|
221
|
+
showCompass: true
|
|
222
|
+
}),
|
|
223
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(DrawControl, {
|
|
224
|
+
features,
|
|
225
|
+
setFeatures,
|
|
226
|
+
isControlled: props.isControlled,
|
|
227
|
+
isMultiple: props.isMultiple
|
|
228
|
+
}),
|
|
229
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(GeojsonLayer, {
|
|
230
|
+
features
|
|
231
|
+
})
|
|
232
|
+
]
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// src/index.tsx
|
|
237
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
238
|
+
var NakshaMaplibreDraw = (props) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_maplibre4.MapProvider, {
|
|
239
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Map, __spreadValues({}, props))
|
|
240
|
+
});
|
|
241
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
242
|
+
0 && (module.exports = {
|
|
243
|
+
NakshaMaplibreDraw
|
|
244
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@biodiv-platform/naksha-maplibre-draw",
|
|
3
|
+
"version": "5.0.0",
|
|
4
|
+
"author": "harshzalavadiya",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/esm/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"repository": "strandls/naksha-components-react",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist/**",
|
|
13
|
+
"locales/**"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"clean": "rm -rf node_modules dist .turbo",
|
|
17
|
+
"build": "tsup src/index.tsx --legacy-output --minify --format esm,cjs --dts --external react",
|
|
18
|
+
"dev": "tsup src/index.tsx --legacy-output --format esm,cjs --watch --dts --external react"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"maplibre-gl": "^5.7.0",
|
|
22
|
+
"react": ">=18",
|
|
23
|
+
"react-map-gl": "^8.0.4"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@biodiv-platform/eslint-preset": "*",
|
|
27
|
+
"@biodiv-platform/tsconfig": "*",
|
|
28
|
+
"@types/react": "^18.0.13",
|
|
29
|
+
"@types/react-dom": "^18.0.5",
|
|
30
|
+
"maplibre-gl": "^5.7.0",
|
|
31
|
+
"react": ">=18",
|
|
32
|
+
"react-map-gl": "^8.0.4",
|
|
33
|
+
"tsup": "^6.1.2",
|
|
34
|
+
"typescript": "^4.7.3"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@biodiv-platform/naksha-commons": "*",
|
|
38
|
+
"@turf/bbox": "^6.5.0",
|
|
39
|
+
"@watergis/maplibre-gl-terradraw": "^1.7.2",
|
|
40
|
+
"boundingbox": "^1.4.0",
|
|
41
|
+
"react-gbus": "^1.1.2"
|
|
42
|
+
}
|
|
43
|
+
}
|