@biodiv-platform/naksha-gmaps-draw 4.5.5-beta.0 → 4.5.5
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.cjs +1106 -1
- package/dist/index.js +1073 -1
- package/package.json +4 -4
- package/dist/esm/index.js +0 -888
package/dist/esm/index.js
DELETED
|
@@ -1,888 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
|
|
21
|
-
// src/index.tsx
|
|
22
|
-
import {
|
|
23
|
-
GMAPS_LIBRARIES,
|
|
24
|
-
mapboxToGmapsViewState
|
|
25
|
-
} from "@biodiv-platform/naksha-commons";
|
|
26
|
-
import { Data, GoogleMap, LoadScriptNext } from "@react-google-maps/api";
|
|
27
|
-
import React6, { useEffect as useEffect4, useMemo, useReducer, useRef as useRef4, useState as useState7 } from "react";
|
|
28
|
-
|
|
29
|
-
// src/autocomplete/index.tsx
|
|
30
|
-
import { GMAPS_AUTOCOMPLETE_FIELDS } from "@biodiv-platform/naksha-commons";
|
|
31
|
-
import { Autocomplete } from "@react-google-maps/api";
|
|
32
|
-
import { useState } from "react";
|
|
33
|
-
|
|
34
|
-
// src/utils/geojson.tsx
|
|
35
|
-
import bbox from "@turf/bbox";
|
|
36
|
-
|
|
37
|
-
// src/static/constants.tsx
|
|
38
|
-
var GMAP_FEATURE_TYPES = {
|
|
39
|
-
POINT: "Point",
|
|
40
|
-
POLYGON: "Polygon",
|
|
41
|
-
LINESTRING: "LineString",
|
|
42
|
-
RECTANGLE: "Rectangle",
|
|
43
|
-
RAW: "Raw",
|
|
44
|
-
NONE: null
|
|
45
|
-
};
|
|
46
|
-
var GMAP_OPTIONS = {
|
|
47
|
-
mapTypeControlOptions: {
|
|
48
|
-
position: 10
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
// src/utils/geojson.tsx
|
|
53
|
-
var placeToGeoJsonFeature = (place) => {
|
|
54
|
-
return {
|
|
55
|
-
type: GMAP_FEATURE_TYPES.POINT,
|
|
56
|
-
properties: {
|
|
57
|
-
id: new Date().getTime(),
|
|
58
|
-
name: place.name,
|
|
59
|
-
formatted_address: place.formatted_address
|
|
60
|
-
},
|
|
61
|
-
coordinates: Object.values(place.geometry.location.toJSON()).reverse()
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
var geometryToGeoJsonFeature = (geometry) => {
|
|
65
|
-
const id = new Date().getTime();
|
|
66
|
-
switch (geometry.getType()) {
|
|
67
|
-
case GMAP_FEATURE_TYPES.POINT: {
|
|
68
|
-
return {
|
|
69
|
-
type: GMAP_FEATURE_TYPES.POINT,
|
|
70
|
-
properties: { id },
|
|
71
|
-
coordinates: Object.values(geometry.get().toJSON()).reverse()
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
case GMAP_FEATURE_TYPES.POLYGON: {
|
|
75
|
-
const clist = [];
|
|
76
|
-
const toLatLng = (c) => clist.push([c.lng(), c.lat()]);
|
|
77
|
-
geometry.forEachLatLng(toLatLng);
|
|
78
|
-
clist.push(clist[0]);
|
|
79
|
-
return {
|
|
80
|
-
type: GMAP_FEATURE_TYPES.POLYGON,
|
|
81
|
-
properties: { id },
|
|
82
|
-
coordinates: [clist]
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
case GMAP_FEATURE_TYPES.RAW: {
|
|
86
|
-
const clist = geometry.data;
|
|
87
|
-
clist.push(clist[0]);
|
|
88
|
-
return {
|
|
89
|
-
type: GMAP_FEATURE_TYPES.POLYGON,
|
|
90
|
-
properties: { id },
|
|
91
|
-
coordinates: [clist]
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
case GMAP_FEATURE_TYPES.LINESTRING: {
|
|
95
|
-
const clist = [];
|
|
96
|
-
const toLatLng = (c) => clist.push([c.lng(), c.lat()]);
|
|
97
|
-
geometry.forEachLatLng(toLatLng);
|
|
98
|
-
return {
|
|
99
|
-
type: GMAP_FEATURE_TYPES.LINESTRING,
|
|
100
|
-
properties: { id },
|
|
101
|
-
coordinates: clist
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
default:
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
var toFullGeoJson = (features) => {
|
|
109
|
-
const cleanFeaures = (features || []).filter((o) => o);
|
|
110
|
-
if (cleanFeaures.length === 0) {
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
|
-
const mergedGeoJson = {
|
|
114
|
-
type: "FeatureCollection",
|
|
115
|
-
features: cleanFeaures.map((value) => {
|
|
116
|
-
if (Array.isArray(value) && value.length > 0 && value[0].isGeojson) {
|
|
117
|
-
const feature = value[0];
|
|
118
|
-
return {
|
|
119
|
-
type: "Feature",
|
|
120
|
-
properties: feature.properties || {},
|
|
121
|
-
geometry: feature.geometry || null
|
|
122
|
-
};
|
|
123
|
-
} else {
|
|
124
|
-
return { type: "Feature", properties: {}, geometry: value };
|
|
125
|
-
}
|
|
126
|
-
})
|
|
127
|
-
};
|
|
128
|
-
return mergedGeoJson;
|
|
129
|
-
};
|
|
130
|
-
var calculateBounds = (geojson) => {
|
|
131
|
-
const b = bbox(geojson);
|
|
132
|
-
return {
|
|
133
|
-
east: b[2],
|
|
134
|
-
north: b[3],
|
|
135
|
-
south: b[1],
|
|
136
|
-
west: b[0]
|
|
137
|
-
};
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
// src/autocomplete/index.tsx
|
|
141
|
-
import { jsx } from "react/jsx-runtime";
|
|
142
|
-
function NakshaAutocomplete({
|
|
143
|
-
InputComponent,
|
|
144
|
-
addFeature,
|
|
145
|
-
gmapRegion
|
|
146
|
-
}) {
|
|
147
|
-
const [ac, setAc] = useState();
|
|
148
|
-
const onLoad = (autocomplete) => {
|
|
149
|
-
setAc(autocomplete);
|
|
150
|
-
};
|
|
151
|
-
const onPlaceChanged = () => {
|
|
152
|
-
const feature = placeToGeoJsonFeature(ac == null ? void 0 : ac.getPlace());
|
|
153
|
-
addFeature(feature);
|
|
154
|
-
};
|
|
155
|
-
return /* @__PURE__ */ jsx(Autocomplete, {
|
|
156
|
-
onLoad,
|
|
157
|
-
fields: GMAPS_AUTOCOMPLETE_FIELDS,
|
|
158
|
-
onPlaceChanged,
|
|
159
|
-
options: gmapRegion ? { componentRestrictions: { country: gmapRegion } } : {},
|
|
160
|
-
children: InputComponent
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// src/features/clear-features.tsx
|
|
165
|
-
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
166
|
-
var ButtonStyle = {
|
|
167
|
-
background: "white",
|
|
168
|
-
position: "absolute",
|
|
169
|
-
top: "5px",
|
|
170
|
-
left: "106px",
|
|
171
|
-
padding: "0.4rem",
|
|
172
|
-
borderRadius: "0.15rem",
|
|
173
|
-
outline: 0,
|
|
174
|
-
boxShadow: "rgba(0, 0, 0, 0.3) 0px 1px 4px -1px"
|
|
175
|
-
};
|
|
176
|
-
function ClearFeatures({ onClick }) {
|
|
177
|
-
return /* @__PURE__ */ jsx2("button", {
|
|
178
|
-
type: "button",
|
|
179
|
-
title: "Clear",
|
|
180
|
-
onClick,
|
|
181
|
-
style: ButtonStyle,
|
|
182
|
-
children: /* @__PURE__ */ jsx2("svg", {
|
|
183
|
-
viewBox: "0 0 24 24",
|
|
184
|
-
width: "12",
|
|
185
|
-
height: "12",
|
|
186
|
-
children: /* @__PURE__ */ jsx2("g", {
|
|
187
|
-
fill: "#E53E3E",
|
|
188
|
-
children: /* @__PURE__ */ jsx2("path", {
|
|
189
|
-
d: "M19.452 7.5H4.547a.5.5 0 00-.5.545l1.287 14.136A2 2 0 007.326 24h9.347a2 2 0 001.992-1.819L19.95 8.045a.5.5 0 00-.129-.382.5.5 0 00-.369-.163zm-9.2 13a.75.75 0 01-1.5 0v-9a.75.75 0 011.5 0zm5 0a.75.75 0 01-1.5 0v-9a.75.75 0 011.5 0zM22 4h-4.75a.25.25 0 01-.25-.25V2.5A2.5 2.5 0 0014.5 0h-5A2.5 2.5 0 007 2.5v1.25a.25.25 0 01-.25.25H2a1 1 0 000 2h20a1 1 0 000-2zM9 3.75V2.5a.5.5 0 01.5-.5h5a.5.5 0 01.5.5v1.25a.25.25 0 01-.25.25h-5.5A.25.25 0 019 3.75z"
|
|
190
|
-
})
|
|
191
|
-
})
|
|
192
|
-
})
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// src/reducers/features.tsx
|
|
197
|
-
var ACTION_TYPES = {
|
|
198
|
-
ADD: "add",
|
|
199
|
-
CLEAR: "clear",
|
|
200
|
-
REPLACE: "replace"
|
|
201
|
-
};
|
|
202
|
-
function featuresReducer(state, { action, data, isMultiple }) {
|
|
203
|
-
switch (action) {
|
|
204
|
-
case ACTION_TYPES.ADD:
|
|
205
|
-
return isMultiple ? [...state || [], data] : [data];
|
|
206
|
-
case ACTION_TYPES.CLEAR:
|
|
207
|
-
return [];
|
|
208
|
-
case ACTION_TYPES.REPLACE:
|
|
209
|
-
return data;
|
|
210
|
-
default:
|
|
211
|
-
return state;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// src/trace-location/index.tsx
|
|
216
|
-
import React2, { useEffect as useEffect2, useState as useState3 } from "react";
|
|
217
|
-
|
|
218
|
-
// src/utils/use-location.tsx
|
|
219
|
-
import { useState as useState2, useEffect } from "react";
|
|
220
|
-
var defaultSettings = {
|
|
221
|
-
enableHighAccuracy: false,
|
|
222
|
-
timeout: Infinity,
|
|
223
|
-
maximumAge: 0
|
|
224
|
-
};
|
|
225
|
-
var usePosition = (watch, settings = defaultSettings) => {
|
|
226
|
-
const [position, setPosition] = useState2();
|
|
227
|
-
const [error, setError] = useState2();
|
|
228
|
-
const onChange = ({ coords }) => {
|
|
229
|
-
setPosition([coords.longitude, coords.latitude]);
|
|
230
|
-
};
|
|
231
|
-
const onError = (error2) => {
|
|
232
|
-
setError(error2.message);
|
|
233
|
-
};
|
|
234
|
-
useEffect(() => {
|
|
235
|
-
if (!navigator || !navigator.geolocation) {
|
|
236
|
-
setError("Geolocation is not supported");
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
let watcher = null;
|
|
240
|
-
if (watch) {
|
|
241
|
-
watcher = navigator.geolocation.watchPosition(
|
|
242
|
-
onChange,
|
|
243
|
-
onError,
|
|
244
|
-
settings
|
|
245
|
-
);
|
|
246
|
-
} else {
|
|
247
|
-
watcher && navigator.geolocation.clearWatch(watcher);
|
|
248
|
-
}
|
|
249
|
-
return () => watcher && navigator.geolocation.clearWatch(watcher);
|
|
250
|
-
}, [settings, watch]);
|
|
251
|
-
return { position, error };
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
// src/trace-location/index.tsx
|
|
255
|
-
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
256
|
-
function TraceLocation({
|
|
257
|
-
TraceButtonComponent,
|
|
258
|
-
onFeatureAdded
|
|
259
|
-
}) {
|
|
260
|
-
const [trackData, setTrackData] = useState3([]);
|
|
261
|
-
const [isTracking, setIsTracking] = useState3(false);
|
|
262
|
-
const { position } = usePosition(isTracking);
|
|
263
|
-
useEffect2(() => {
|
|
264
|
-
if (isTracking && position) {
|
|
265
|
-
setTrackData([...trackData, position]);
|
|
266
|
-
}
|
|
267
|
-
}, [isTracking, position]);
|
|
268
|
-
const handleOnTraceAction = () => {
|
|
269
|
-
if (isTracking) {
|
|
270
|
-
setIsTracking(false);
|
|
271
|
-
onFeatureAdded({
|
|
272
|
-
getType: () => GMAP_FEATURE_TYPES.RAW,
|
|
273
|
-
data: [...trackData]
|
|
274
|
-
});
|
|
275
|
-
setTrackData([]);
|
|
276
|
-
} else {
|
|
277
|
-
setIsTracking(true);
|
|
278
|
-
}
|
|
279
|
-
};
|
|
280
|
-
return /* @__PURE__ */ jsx3("div", {
|
|
281
|
-
children: React2.cloneElement(TraceButtonComponent, {
|
|
282
|
-
onClick: handleOnTraceAction,
|
|
283
|
-
isTracking
|
|
284
|
-
})
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// src/ModalImport/index.tsx
|
|
289
|
-
import React5, { useState as useState6 } from "react";
|
|
290
|
-
|
|
291
|
-
// src/import/index.tsx
|
|
292
|
-
import React3, { useRef, useState as useState4 } from "react";
|
|
293
|
-
import { jsx as jsx4, jsxs } from "react/jsx-runtime";
|
|
294
|
-
var NakshaImport = ({
|
|
295
|
-
addFeature,
|
|
296
|
-
InputComponent,
|
|
297
|
-
ButtonComponent,
|
|
298
|
-
LocationIcon,
|
|
299
|
-
SuccessIcon,
|
|
300
|
-
FailureIcon
|
|
301
|
-
}) => {
|
|
302
|
-
const importInputRef = useRef(null);
|
|
303
|
-
const [isPointsValid, setIsPointsValid] = useState4(true);
|
|
304
|
-
const [uploadStatus, setUploadStatus] = useState4("");
|
|
305
|
-
const [importedPoints, setImportedPoints] = useState4([]);
|
|
306
|
-
const handleOnAddFeature = () => {
|
|
307
|
-
var _a, _b, _c;
|
|
308
|
-
try {
|
|
309
|
-
const txtLatLng = (_b = (_a = importInputRef.current) == null ? void 0 : _a.value) != null ? _b : "";
|
|
310
|
-
if (!txtLatLng.trim()) {
|
|
311
|
-
setIsPointsValid(false);
|
|
312
|
-
setUploadStatus("Invalid Format. Enter Latitude, Longitude.");
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
const numLatLng = (_c = txtLatLng.split(",").map(Number)) == null ? void 0 : _c.reverse();
|
|
316
|
-
if (!isValidLatLng(numLatLng)) {
|
|
317
|
-
setIsPointsValid(false);
|
|
318
|
-
setUploadStatus("Invalid Format. Enter Latitude, Longitude.");
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
const newFeature = {
|
|
322
|
-
type: GMAP_FEATURE_TYPES.POINT,
|
|
323
|
-
properties: {
|
|
324
|
-
id: new Date().getTime(),
|
|
325
|
-
name: txtLatLng,
|
|
326
|
-
formatted_address: txtLatLng
|
|
327
|
-
},
|
|
328
|
-
coordinates: numLatLng
|
|
329
|
-
};
|
|
330
|
-
addFeature(newFeature);
|
|
331
|
-
setImportedPoints((prevPoints) => [...prevPoints, newFeature]);
|
|
332
|
-
if (importInputRef.current) {
|
|
333
|
-
importInputRef.current.value = "";
|
|
334
|
-
}
|
|
335
|
-
setIsPointsValid(true);
|
|
336
|
-
setUploadStatus("Point added successfully");
|
|
337
|
-
} catch (e) {
|
|
338
|
-
setIsPointsValid(false);
|
|
339
|
-
} finally {
|
|
340
|
-
setTimeout(() => {
|
|
341
|
-
setUploadStatus("");
|
|
342
|
-
setIsPointsValid(true);
|
|
343
|
-
}, 3e3);
|
|
344
|
-
}
|
|
345
|
-
};
|
|
346
|
-
const isValidLatLng = (latLng) => {
|
|
347
|
-
return Array.isArray(latLng) && latLng.length === 2 && !isNaN(latLng[0]) && !isNaN(latLng[1]) && typeof latLng[0] === "number" && typeof latLng[1] === "number";
|
|
348
|
-
};
|
|
349
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
350
|
-
style: {
|
|
351
|
-
display: "flex",
|
|
352
|
-
flexDirection: "column",
|
|
353
|
-
alignItems: "flex-start"
|
|
354
|
-
},
|
|
355
|
-
children: [
|
|
356
|
-
/* @__PURE__ */ jsx4("h1", {
|
|
357
|
-
style: {
|
|
358
|
-
marginBottom: "10px",
|
|
359
|
-
fontWeight: "bold",
|
|
360
|
-
fontSize: "1.25rem"
|
|
361
|
-
},
|
|
362
|
-
children: "Point"
|
|
363
|
-
}),
|
|
364
|
-
/* @__PURE__ */ jsxs("div", {
|
|
365
|
-
style: { display: "flex", alignItems: "center" },
|
|
366
|
-
children: [
|
|
367
|
-
React3.cloneElement(InputComponent, {
|
|
368
|
-
ref: importInputRef,
|
|
369
|
-
width: "300px"
|
|
370
|
-
}),
|
|
371
|
-
React3.cloneElement(ButtonComponent, {
|
|
372
|
-
onClick: handleOnAddFeature,
|
|
373
|
-
type: "button",
|
|
374
|
-
marginLeft: "10px"
|
|
375
|
-
})
|
|
376
|
-
]
|
|
377
|
-
}),
|
|
378
|
-
uploadStatus && /* @__PURE__ */ jsxs("div", {
|
|
379
|
-
style: {
|
|
380
|
-
fontWeight: "bold",
|
|
381
|
-
color: isPointsValid ? "green" : "red",
|
|
382
|
-
marginTop: "10px",
|
|
383
|
-
display: "flex",
|
|
384
|
-
alignItems: "center"
|
|
385
|
-
},
|
|
386
|
-
children: [
|
|
387
|
-
isPointsValid ? /* @__PURE__ */ jsx4("span", {
|
|
388
|
-
style: { marginRight: "5px", fontSize: "1.25rem" },
|
|
389
|
-
children: React3.cloneElement(SuccessIcon, { boxSize: 6 })
|
|
390
|
-
}) : /* @__PURE__ */ jsx4("span", {
|
|
391
|
-
style: { marginRight: "5px", fontSize: "1.25rem", color: "red" },
|
|
392
|
-
children: React3.cloneElement(FailureIcon, { boxSize: 4 })
|
|
393
|
-
}),
|
|
394
|
-
uploadStatus
|
|
395
|
-
]
|
|
396
|
-
}),
|
|
397
|
-
importedPoints.length > 0 && /* @__PURE__ */ jsxs("div", {
|
|
398
|
-
style: { marginTop: "10px", paddingLeft: "15px" },
|
|
399
|
-
children: [
|
|
400
|
-
/* @__PURE__ */ jsx4("div", {
|
|
401
|
-
style: { fontSize: "sm" },
|
|
402
|
-
children: "Added Points:"
|
|
403
|
-
}),
|
|
404
|
-
/* @__PURE__ */ jsx4("ul", {
|
|
405
|
-
style: { listStyleType: "none", padding: "0" },
|
|
406
|
-
children: importedPoints.map((point) => /* @__PURE__ */ jsxs("li", {
|
|
407
|
-
style: { display: "flex", alignItems: "center", marginBottom: "5px" },
|
|
408
|
-
children: [
|
|
409
|
-
React3.cloneElement(LocationIcon, { boxSize: 6, marginRight: 2, color: "teal" }),
|
|
410
|
-
/* @__PURE__ */ jsx4("span", {
|
|
411
|
-
style: { overflow: "hidden", whiteSpace: "pre-wrap", textOverflow: "ellipsis", maxWidth: "300px" },
|
|
412
|
-
children: point.properties.name
|
|
413
|
-
})
|
|
414
|
-
]
|
|
415
|
-
}, point.properties.id))
|
|
416
|
-
})
|
|
417
|
-
]
|
|
418
|
-
})
|
|
419
|
-
]
|
|
420
|
-
});
|
|
421
|
-
};
|
|
422
|
-
var import_default = NakshaImport;
|
|
423
|
-
|
|
424
|
-
// src/geojson/index.tsx
|
|
425
|
-
import React4, { useState as useState5, useRef as useRef2 } from "react";
|
|
426
|
-
import { Fragment, jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
427
|
-
var GeojsonImport = ({ addFeature, ButtonComponent, FileIcon, SuccessIcon, FailureIcon, DeleteIcon }) => {
|
|
428
|
-
const [isGeoJSONValid, setIsGeoJSONValid] = useState5(true);
|
|
429
|
-
const [uploadStatus, setUploadStatus] = useState5("");
|
|
430
|
-
const [filesToUpload, setFilesToUpload] = useState5([]);
|
|
431
|
-
const [uploadedFiles, setUploadedFiles] = useState5([]);
|
|
432
|
-
const fileInputRef = useRef2(null);
|
|
433
|
-
const handleDragEnter = (e) => {
|
|
434
|
-
e.preventDefault();
|
|
435
|
-
};
|
|
436
|
-
const handleDragOver = (e) => {
|
|
437
|
-
e.preventDefault();
|
|
438
|
-
};
|
|
439
|
-
const handleDrop = (e) => {
|
|
440
|
-
e.preventDefault();
|
|
441
|
-
const droppedFiles = Array.from(e.dataTransfer.files);
|
|
442
|
-
setFilesToUpload(droppedFiles);
|
|
443
|
-
};
|
|
444
|
-
const handleFileInputChange = () => {
|
|
445
|
-
const selectedFiles = Array.from(fileInputRef.current.files);
|
|
446
|
-
setFilesToUpload(selectedFiles);
|
|
447
|
-
};
|
|
448
|
-
const handleAddFeature = () => {
|
|
449
|
-
try {
|
|
450
|
-
filesToUpload.forEach((file) => {
|
|
451
|
-
const reader = new FileReader();
|
|
452
|
-
reader.onabort = () => handleError("File reading was aborted. Please try again.");
|
|
453
|
-
reader.onerror = () => handleError("File reading has failed. Please try again.");
|
|
454
|
-
reader.onload = () => {
|
|
455
|
-
const result = reader.result;
|
|
456
|
-
if (result) {
|
|
457
|
-
const jsonString = typeof result === "string" ? result : new TextDecoder().decode(result);
|
|
458
|
-
try {
|
|
459
|
-
const geojsonObject = JSON.parse(jsonString);
|
|
460
|
-
const featuresToAdd = Array.isArray(geojsonObject.features) ? geojsonObject.features.map((feature) => __spreadProps(__spreadValues({}, feature), {
|
|
461
|
-
isGeojson: true
|
|
462
|
-
})) : [__spreadProps(__spreadValues({}, geojsonObject), { isGeojson: true })];
|
|
463
|
-
featuresToAdd.forEach((featureToAdd) => {
|
|
464
|
-
addFeature([featureToAdd]);
|
|
465
|
-
});
|
|
466
|
-
setUploadStatus("Geojson added successfully");
|
|
467
|
-
setIsGeoJSONValid(true);
|
|
468
|
-
setUploadedFiles((prevFiles) => [
|
|
469
|
-
...prevFiles,
|
|
470
|
-
{ name: file.name }
|
|
471
|
-
]);
|
|
472
|
-
setFilesToUpload([]);
|
|
473
|
-
} catch (error) {
|
|
474
|
-
console.error(error);
|
|
475
|
-
handleError("Upload failed. Invalid GeoJSON format.");
|
|
476
|
-
}
|
|
477
|
-
} else {
|
|
478
|
-
handleError("File reading result is null.");
|
|
479
|
-
}
|
|
480
|
-
};
|
|
481
|
-
reader.readAsText(file);
|
|
482
|
-
});
|
|
483
|
-
} catch (error) {
|
|
484
|
-
console.error(error);
|
|
485
|
-
handleError("File upload failed. Please try again.");
|
|
486
|
-
} finally {
|
|
487
|
-
setTimeout(() => {
|
|
488
|
-
setUploadStatus("");
|
|
489
|
-
setIsGeoJSONValid(true);
|
|
490
|
-
}, 2e3);
|
|
491
|
-
}
|
|
492
|
-
};
|
|
493
|
-
const handleError = (message) => {
|
|
494
|
-
setUploadStatus(message);
|
|
495
|
-
setIsGeoJSONValid(false);
|
|
496
|
-
};
|
|
497
|
-
const removeFile = () => {
|
|
498
|
-
setFilesToUpload([]);
|
|
499
|
-
};
|
|
500
|
-
return /* @__PURE__ */ jsxs2("div", {
|
|
501
|
-
style: {
|
|
502
|
-
display: "flex",
|
|
503
|
-
flexDirection: "column",
|
|
504
|
-
alignItems: "flex-start",
|
|
505
|
-
marginTop: "10px"
|
|
506
|
-
},
|
|
507
|
-
onDragEnter: handleDragEnter,
|
|
508
|
-
onDragOver: handleDragOver,
|
|
509
|
-
onDrop: handleDrop,
|
|
510
|
-
children: [
|
|
511
|
-
/* @__PURE__ */ jsx5("h1", {
|
|
512
|
-
style: {
|
|
513
|
-
marginBottom: "10px",
|
|
514
|
-
fontWeight: "bold",
|
|
515
|
-
fontSize: "1.25rem"
|
|
516
|
-
},
|
|
517
|
-
children: "GeoJSON"
|
|
518
|
-
}),
|
|
519
|
-
/* @__PURE__ */ jsxs2("div", {
|
|
520
|
-
style: {
|
|
521
|
-
display: "flex",
|
|
522
|
-
flexDirection: "row",
|
|
523
|
-
alignItems: "center"
|
|
524
|
-
},
|
|
525
|
-
children: [
|
|
526
|
-
/* @__PURE__ */ jsxs2("div", {
|
|
527
|
-
style: {
|
|
528
|
-
border: "2px solid #519895",
|
|
529
|
-
borderRadius: "4px",
|
|
530
|
-
display: "flex",
|
|
531
|
-
flexDirection: "column",
|
|
532
|
-
alignItems: "center",
|
|
533
|
-
padding: "10px",
|
|
534
|
-
cursor: "pointer",
|
|
535
|
-
marginLeft: "15px",
|
|
536
|
-
width: "300px",
|
|
537
|
-
height: "100px"
|
|
538
|
-
},
|
|
539
|
-
onClick: () => fileInputRef.current.click(),
|
|
540
|
-
children: [
|
|
541
|
-
/* @__PURE__ */ jsx5("input", {
|
|
542
|
-
type: "file",
|
|
543
|
-
ref: fileInputRef,
|
|
544
|
-
onChange: handleFileInputChange,
|
|
545
|
-
style: { display: "none" }
|
|
546
|
-
}),
|
|
547
|
-
/* @__PURE__ */ jsx5("div", {
|
|
548
|
-
style: {
|
|
549
|
-
display: "flex",
|
|
550
|
-
alignItems: "center"
|
|
551
|
-
},
|
|
552
|
-
children: filesToUpload.length > 0 ? /* @__PURE__ */ jsxs2("div", {
|
|
553
|
-
style: {
|
|
554
|
-
marginLeft: "10px",
|
|
555
|
-
display: "flex",
|
|
556
|
-
alignItems: "center"
|
|
557
|
-
},
|
|
558
|
-
children: [
|
|
559
|
-
/* @__PURE__ */ jsx5("div", {
|
|
560
|
-
style: {
|
|
561
|
-
marginTop: "10px",
|
|
562
|
-
overflow: "hidden",
|
|
563
|
-
whiteSpace: "pre-wrap",
|
|
564
|
-
textOverflow: "ellipsis",
|
|
565
|
-
maxWidth: "200px"
|
|
566
|
-
},
|
|
567
|
-
children: filesToUpload[0].name
|
|
568
|
-
}),
|
|
569
|
-
/* @__PURE__ */ jsx5("div", {
|
|
570
|
-
style: {
|
|
571
|
-
color: "red",
|
|
572
|
-
marginLeft: "10px",
|
|
573
|
-
marginTop: "10px",
|
|
574
|
-
cursor: "pointer"
|
|
575
|
-
},
|
|
576
|
-
onClick: removeFile,
|
|
577
|
-
children: React4.cloneElement(DeleteIcon, { boxSize: 6 })
|
|
578
|
-
})
|
|
579
|
-
]
|
|
580
|
-
}) : /* @__PURE__ */ jsx5(Fragment, {
|
|
581
|
-
children: /* @__PURE__ */ jsx5("div", {
|
|
582
|
-
children: "Drag 'n' drop GeoJSON file here, or click to select a file"
|
|
583
|
-
})
|
|
584
|
-
})
|
|
585
|
-
})
|
|
586
|
-
]
|
|
587
|
-
}),
|
|
588
|
-
React4.cloneElement(ButtonComponent, {
|
|
589
|
-
type: "button",
|
|
590
|
-
marginLeft: "30px",
|
|
591
|
-
style: { paddingLeft: "15px" },
|
|
592
|
-
onClick: handleAddFeature
|
|
593
|
-
})
|
|
594
|
-
]
|
|
595
|
-
}),
|
|
596
|
-
uploadStatus && /* @__PURE__ */ jsxs2("div", {
|
|
597
|
-
style: {
|
|
598
|
-
fontWeight: "bold",
|
|
599
|
-
color: isGeoJSONValid ? "green" : "red",
|
|
600
|
-
marginTop: "10px",
|
|
601
|
-
display: "flex",
|
|
602
|
-
alignItems: "center"
|
|
603
|
-
},
|
|
604
|
-
children: [
|
|
605
|
-
isGeoJSONValid ? /* @__PURE__ */ jsx5("span", {
|
|
606
|
-
style: {
|
|
607
|
-
marginRight: "5px",
|
|
608
|
-
fontSize: "1.25rem"
|
|
609
|
-
},
|
|
610
|
-
children: React4.cloneElement(SuccessIcon, { boxSize: 6 })
|
|
611
|
-
}) : /* @__PURE__ */ jsx5("span", {
|
|
612
|
-
style: {
|
|
613
|
-
marginRight: "5px",
|
|
614
|
-
fontSize: "1.25rem",
|
|
615
|
-
color: "red"
|
|
616
|
-
},
|
|
617
|
-
children: React4.cloneElement(FailureIcon, { boxSize: 4 })
|
|
618
|
-
}),
|
|
619
|
-
uploadStatus
|
|
620
|
-
]
|
|
621
|
-
}),
|
|
622
|
-
uploadedFiles.length > 0 && /* @__PURE__ */ jsxs2("div", {
|
|
623
|
-
style: {
|
|
624
|
-
marginTop: "10px",
|
|
625
|
-
paddingLeft: "15px"
|
|
626
|
-
},
|
|
627
|
-
children: [
|
|
628
|
-
/* @__PURE__ */ jsx5("div", {
|
|
629
|
-
style: {
|
|
630
|
-
fontSize: "sm"
|
|
631
|
-
},
|
|
632
|
-
children: "Added GeoJSONs:"
|
|
633
|
-
}),
|
|
634
|
-
/* @__PURE__ */ jsx5("ul", {
|
|
635
|
-
style: {
|
|
636
|
-
listStyleType: "none",
|
|
637
|
-
padding: "0"
|
|
638
|
-
},
|
|
639
|
-
children: uploadedFiles.map((file, index) => /* @__PURE__ */ jsxs2("li", {
|
|
640
|
-
style: {
|
|
641
|
-
display: "flex",
|
|
642
|
-
alignItems: "center"
|
|
643
|
-
},
|
|
644
|
-
children: [
|
|
645
|
-
React4.cloneElement(FileIcon, { boxSize: 6, marginRight: 2 }),
|
|
646
|
-
/* @__PURE__ */ jsx5("div", {
|
|
647
|
-
style: {
|
|
648
|
-
marginTop: "10px",
|
|
649
|
-
overflow: "hidden",
|
|
650
|
-
whiteSpace: "pre-wrap",
|
|
651
|
-
textOverflow: "ellipsis",
|
|
652
|
-
maxWidth: "300px"
|
|
653
|
-
},
|
|
654
|
-
children: file.name
|
|
655
|
-
})
|
|
656
|
-
]
|
|
657
|
-
}, index))
|
|
658
|
-
})
|
|
659
|
-
]
|
|
660
|
-
})
|
|
661
|
-
]
|
|
662
|
-
});
|
|
663
|
-
};
|
|
664
|
-
var geojson_default = GeojsonImport;
|
|
665
|
-
|
|
666
|
-
// src/ModalImport/index.tsx
|
|
667
|
-
import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
668
|
-
function ModalImport({
|
|
669
|
-
ButtonComponent,
|
|
670
|
-
ModalComponent,
|
|
671
|
-
addFeature,
|
|
672
|
-
InputComponent,
|
|
673
|
-
ButtonComponentModal,
|
|
674
|
-
DeleteIcon,
|
|
675
|
-
LocationIcon,
|
|
676
|
-
FileIcon,
|
|
677
|
-
SuccessIcon,
|
|
678
|
-
FailureIcon
|
|
679
|
-
}) {
|
|
680
|
-
const [isModalOpen, setIsModalOpen] = useState6(false);
|
|
681
|
-
const handleModalClose = () => {
|
|
682
|
-
setIsModalOpen(false);
|
|
683
|
-
};
|
|
684
|
-
const handleOpenModal = () => {
|
|
685
|
-
setIsModalOpen(true);
|
|
686
|
-
};
|
|
687
|
-
return /* @__PURE__ */ jsxs3("div", {
|
|
688
|
-
style: { display: "flex" },
|
|
689
|
-
children: [
|
|
690
|
-
React5.cloneElement(ModalComponent, {
|
|
691
|
-
isOpen: isModalOpen,
|
|
692
|
-
onClose: handleModalClose,
|
|
693
|
-
nakshaImport: /* @__PURE__ */ jsx6(import_default, {
|
|
694
|
-
addFeature,
|
|
695
|
-
InputComponent,
|
|
696
|
-
ButtonComponent,
|
|
697
|
-
LocationIcon,
|
|
698
|
-
SuccessIcon,
|
|
699
|
-
FailureIcon
|
|
700
|
-
}),
|
|
701
|
-
geoJSONImport: /* @__PURE__ */ jsx6(geojson_default, {
|
|
702
|
-
addFeature,
|
|
703
|
-
ButtonComponent,
|
|
704
|
-
DeleteIcon,
|
|
705
|
-
FileIcon,
|
|
706
|
-
SuccessIcon,
|
|
707
|
-
FailureIcon
|
|
708
|
-
})
|
|
709
|
-
}),
|
|
710
|
-
React5.cloneElement(ButtonComponentModal, {
|
|
711
|
-
onClick: handleOpenModal,
|
|
712
|
-
type: "button"
|
|
713
|
-
})
|
|
714
|
-
]
|
|
715
|
-
});
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
// src/index.tsx
|
|
719
|
-
import { Fragment as Fragment2, jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
720
|
-
var NakshaGmapsDraw = React6.forwardRef(
|
|
721
|
-
({
|
|
722
|
-
defaultViewState,
|
|
723
|
-
defaultDrawingMode,
|
|
724
|
-
data,
|
|
725
|
-
onDataChange,
|
|
726
|
-
gmapAccessToken,
|
|
727
|
-
isControlled,
|
|
728
|
-
isReadOnly,
|
|
729
|
-
isMultiple,
|
|
730
|
-
isImport,
|
|
731
|
-
isAutocomplete,
|
|
732
|
-
gmapRegion,
|
|
733
|
-
autoCompleteRegion,
|
|
734
|
-
mapStyle,
|
|
735
|
-
importInputComponent,
|
|
736
|
-
importButtonComponent,
|
|
737
|
-
autocompleteComponent,
|
|
738
|
-
showTrace,
|
|
739
|
-
traceButtonComponent,
|
|
740
|
-
maxZoom,
|
|
741
|
-
options,
|
|
742
|
-
importModalComponent,
|
|
743
|
-
isOpen,
|
|
744
|
-
onClose,
|
|
745
|
-
importButtonComponentModal,
|
|
746
|
-
importDeleteIcon,
|
|
747
|
-
importLocationIcon,
|
|
748
|
-
importFileIcon,
|
|
749
|
-
importSuccessIcon,
|
|
750
|
-
importFailureIcon
|
|
751
|
-
}, ref) => {
|
|
752
|
-
const mapRef = useRef4(null);
|
|
753
|
-
const [features, dispatch] = useReducer(featuresReducer, data);
|
|
754
|
-
const [isLoaded, setIsLoaded] = useState7();
|
|
755
|
-
const viewPort = useMemo(
|
|
756
|
-
() => mapboxToGmapsViewState(defaultViewState),
|
|
757
|
-
[defaultViewState]
|
|
758
|
-
);
|
|
759
|
-
const reloadFeatures = () => {
|
|
760
|
-
mapRef.current.state.map.data.forEach(function(feature) {
|
|
761
|
-
mapRef.current.state.map.data.remove(feature);
|
|
762
|
-
});
|
|
763
|
-
const fullGeoJson = toFullGeoJson(features);
|
|
764
|
-
if (fullGeoJson) {
|
|
765
|
-
fullGeoJson && mapRef.current.state.map.data.addGeoJson(fullGeoJson);
|
|
766
|
-
const bounds = calculateBounds(fullGeoJson);
|
|
767
|
-
bounds && mapRef.current.state.map.fitBounds(bounds);
|
|
768
|
-
if (maxZoom) {
|
|
769
|
-
google.maps.event.addListenerOnce(
|
|
770
|
-
mapRef.current.state.map,
|
|
771
|
-
"idle",
|
|
772
|
-
function() {
|
|
773
|
-
const z = mapRef.current.state.map.getZoom();
|
|
774
|
-
mapRef.current.state.map.setZoom(Math.min(maxZoom, z));
|
|
775
|
-
}
|
|
776
|
-
);
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
};
|
|
780
|
-
useEffect4(() => {
|
|
781
|
-
if (isLoaded) {
|
|
782
|
-
onDataChange && onDataChange(features);
|
|
783
|
-
if (ref) {
|
|
784
|
-
ref.current = { addFeature, replaceFeature };
|
|
785
|
-
}
|
|
786
|
-
reloadFeatures();
|
|
787
|
-
}
|
|
788
|
-
}, [isLoaded, features]);
|
|
789
|
-
useEffect4(() => {
|
|
790
|
-
if (isControlled && JSON.stringify(features) !== JSON.stringify(data)) {
|
|
791
|
-
dispatch({
|
|
792
|
-
action: ACTION_TYPES.REPLACE,
|
|
793
|
-
data
|
|
794
|
-
});
|
|
795
|
-
}
|
|
796
|
-
}, [data]);
|
|
797
|
-
const addFeature = (feature) => {
|
|
798
|
-
dispatch({ action: ACTION_TYPES.ADD, data: feature, isMultiple });
|
|
799
|
-
};
|
|
800
|
-
const replaceFeature = (feature) => {
|
|
801
|
-
dispatch({ action: ACTION_TYPES.REPLACE, data: [feature] });
|
|
802
|
-
};
|
|
803
|
-
const onFeatureAdded = (geometry) => {
|
|
804
|
-
const feature = geometryToGeoJsonFeature(geometry);
|
|
805
|
-
addFeature(feature);
|
|
806
|
-
};
|
|
807
|
-
const onClearFeatures = () => {
|
|
808
|
-
dispatch({ action: ACTION_TYPES.CLEAR });
|
|
809
|
-
};
|
|
810
|
-
const onMapLoaded = () => setIsLoaded(true);
|
|
811
|
-
return /* @__PURE__ */ jsx7(LoadScriptNext, {
|
|
812
|
-
googleMapsApiKey: gmapAccessToken,
|
|
813
|
-
region: gmapRegion,
|
|
814
|
-
libraries: isAutocomplete ? GMAPS_LIBRARIES.AUTOCOMPLETE : GMAPS_LIBRARIES.DEFAULT,
|
|
815
|
-
children: /* @__PURE__ */ jsxs4(Fragment2, {
|
|
816
|
-
children: [
|
|
817
|
-
/* @__PURE__ */ jsxs4("div", {
|
|
818
|
-
style: { display: "flex" },
|
|
819
|
-
children: [
|
|
820
|
-
isAutocomplete && /* @__PURE__ */ jsx7("div", {
|
|
821
|
-
style: { width: "500px" },
|
|
822
|
-
children: /* @__PURE__ */ jsx7(NakshaAutocomplete, {
|
|
823
|
-
InputComponent: autocompleteComponent || /* @__PURE__ */ jsx7("input", {}),
|
|
824
|
-
addFeature,
|
|
825
|
-
gmapRegion: autoCompleteRegion != null ? autoCompleteRegion : gmapRegion
|
|
826
|
-
})
|
|
827
|
-
}),
|
|
828
|
-
/* @__PURE__ */ jsx7("div", {
|
|
829
|
-
style: { flex: "1" }
|
|
830
|
-
}),
|
|
831
|
-
/* @__PURE__ */ jsx7(ModalImport, {
|
|
832
|
-
ButtonComponent: importButtonComponent || /* @__PURE__ */ jsx7("button", {
|
|
833
|
-
children: "add"
|
|
834
|
-
}),
|
|
835
|
-
ModalComponent: importModalComponent && React6.cloneElement(importModalComponent, { isOpen, onClose }),
|
|
836
|
-
InputComponent: importInputComponent || /* @__PURE__ */ jsx7("input", {}),
|
|
837
|
-
addFeature,
|
|
838
|
-
ButtonComponentModal: importButtonComponentModal || /* @__PURE__ */ jsx7("button", {
|
|
839
|
-
children: "add"
|
|
840
|
-
}),
|
|
841
|
-
DeleteIcon: importDeleteIcon,
|
|
842
|
-
LocationIcon: importLocationIcon,
|
|
843
|
-
FileIcon: importFileIcon,
|
|
844
|
-
SuccessIcon: importSuccessIcon,
|
|
845
|
-
FailureIcon: importFailureIcon
|
|
846
|
-
})
|
|
847
|
-
]
|
|
848
|
-
}),
|
|
849
|
-
showTrace && /* @__PURE__ */ jsx7(TraceLocation, {
|
|
850
|
-
TraceButtonComponent: traceButtonComponent || /* @__PURE__ */ jsx7("button", {
|
|
851
|
-
children: "trace"
|
|
852
|
-
}),
|
|
853
|
-
onFeatureAdded
|
|
854
|
-
}),
|
|
855
|
-
/* @__PURE__ */ jsxs4(GoogleMap, {
|
|
856
|
-
id: "naksha-gmaps-draw",
|
|
857
|
-
mapContainerStyle: mapStyle || { height: "100%", width: "100%" },
|
|
858
|
-
zoom: viewPort.zoom,
|
|
859
|
-
center: viewPort.center,
|
|
860
|
-
options: GMAP_OPTIONS,
|
|
861
|
-
ref: mapRef,
|
|
862
|
-
onLoad: onMapLoaded,
|
|
863
|
-
children: [
|
|
864
|
-
isMultiple && /* @__PURE__ */ jsx7(ClearFeatures, {
|
|
865
|
-
onClick: onClearFeatures
|
|
866
|
-
}),
|
|
867
|
-
!isReadOnly && /* @__PURE__ */ jsx7(Data, {
|
|
868
|
-
options: __spreadValues({
|
|
869
|
-
controls: [
|
|
870
|
-
GMAP_FEATURE_TYPES.POINT,
|
|
871
|
-
GMAP_FEATURE_TYPES.POLYGON,
|
|
872
|
-
GMAP_FEATURE_TYPES.LINESTRING
|
|
873
|
-
],
|
|
874
|
-
drawingMode: defaultDrawingMode || GMAP_FEATURE_TYPES.POLYGON,
|
|
875
|
-
featureFactory: onFeatureAdded
|
|
876
|
-
}, options || {})
|
|
877
|
-
})
|
|
878
|
-
]
|
|
879
|
-
})
|
|
880
|
-
]
|
|
881
|
-
})
|
|
882
|
-
});
|
|
883
|
-
}
|
|
884
|
-
);
|
|
885
|
-
export {
|
|
886
|
-
GMAP_FEATURE_TYPES,
|
|
887
|
-
NakshaGmapsDraw
|
|
888
|
-
};
|