@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.js CHANGED
@@ -1 +1,1073 @@
1
- import{GMAPS_LIBRARIES as xe,mapboxToGmapsViewState as We}from"@biodiv-platform/naksha-commons";import{Data as Be,GoogleMap as Ue,LoadScriptNext as Ye}from"@react-google-maps/api";import je,{useEffect as Ee,useMemo as He,useReducer as Ze,useRef as Ke,useState as qe}from"react";import{GMAPS_AUTOCOMPLETE_FIELDS as Ce}from"@biodiv-platform/naksha-commons";import{Autocomplete as Le}from"@react-google-maps/api";import{useState as Oe}from"react";import Ae from"@turf/bbox";var p={POINT:"Point",POLYGON:"Polygon",LINESTRING:"LineString",RECTANGLE:"Rectangle",RAW:"Raw",NONE:null},re={mapTypeControlOptions:{position:10}};var ie=t=>({type:p.POINT,properties:{id:new Date().getTime(),name:t.name,formatted_address:t.formatted_address},coordinates:Object.values(t.geometry.location.toJSON()).reverse()}),se=t=>{let o=new Date().getTime();switch(t.getType()){case p.POINT:return{type:p.POINT,properties:{id:o},coordinates:Object.values(t.get().toJSON()).reverse()};case p.POLYGON:{let e=[],a=n=>e.push([n.lng(),n.lat()]);return t.forEachLatLng(a),e.push(e[0]),{type:p.POLYGON,properties:{id:o},coordinates:[e]}}case p.RAW:{let e=t.data;return e.push(e[0]),{type:p.POLYGON,properties:{id:o},coordinates:[e]}}case p.LINESTRING:{let e=[],a=n=>e.push([n.lng(),n.lat()]);return t.forEachLatLng(a),{type:p.LINESTRING,properties:{id:o},coordinates:e}}default:return null}},le=t=>{let o=(t||[]).filter(a=>a);return o.length===0?!1:{type:"FeatureCollection",features:o.map(a=>{if(Array.isArray(a)&&a.length>0&&a[0].isGeojson){let n=a[0];return{type:"Feature",properties:n.properties||{},geometry:n.geometry||null}}else return{type:"Feature",properties:{},geometry:a}})}},pe=t=>{let o=Ae(t);return{east:o[2],north:o[3],south:o[1],west:o[0]}};import{jsx as Pe}from"react/jsx-runtime";function H({InputComponent:t,addFeature:o,gmapRegion:e}){let[a,n]=Oe();return Pe(Le,{onLoad:s=>{n(s)},fields:Ce,onPlaceChanged:()=>{let s=ie(a?.getPlace());o(s)},options:e?{componentRestrictions:{country:e}}:{},children:t})}import{jsx as W}from"react/jsx-runtime";var Ne={background:"white",position:"absolute",top:"5px",left:"106px",padding:"0.4rem",borderRadius:"0.15rem",outline:0,boxShadow:"rgba(0, 0, 0, 0.3) 0px 1px 4px -1px"};function Z({onClick:t}){return W("button",{type:"button",title:"Clear",onClick:t,style:Ne,children:W("svg",{viewBox:"0 0 24 24",width:"12",height:"12",children:W("g",{fill:"#E53E3E",children:W("path",{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"})})})})}var C={ADD:"add",CLEAR:"clear",REPLACE:"replace"};function de(t,{action:o,data:e,isMultiple:a}){switch(o){case C.ADD:return a?[...t||[],e]:[e];case C.CLEAR:return[];case C.REPLACE:return e;default:return t}}import ue,{useEffect as we,useState as fe}from"react";import{useState as ce,useEffect as Fe}from"react";var Ge={enableHighAccuracy:!1,timeout:1/0,maximumAge:0},me=(t,o=Ge)=>{let[e,a]=ce(),[n,c]=ce(),l=({coords:r})=>{a([r.longitude,r.latitude])},s=r=>{c(r.message)};return Fe(()=>{if(!navigator||!navigator.geolocation){c("Geolocation is not supported");return}let r=null;return t?r=navigator.geolocation.watchPosition(l,s,o):r&&navigator.geolocation.clearWatch(r),()=>r&&navigator.geolocation.clearWatch(r)},[o,t]),{position:e,error:n}};import{jsx as ge}from"react/jsx-runtime";function K({TraceButtonComponent:t,onFeatureAdded:o}){let[e,a]=fe([]),[n,c]=fe(!1),{position:l}=me(n);we(()=>{n&&l&&a([...e,l])},[n,l]);let s=()=>{n?(c(!1),o({getType:()=>p.RAW,data:[...e]}),a([])):c(!0)};return ge("div",{children:ue.isValidElement(t)?ue.cloneElement(t,{onClick:s,isTracking:n}):ge("button",{type:"button",onClick:s,style:{padding:"6px 12px",borderRadius:"4px",border:"1px solid #ccc",background:n?"#e53e3e":"#fff",color:n?"#fff":"#333",cursor:"pointer"},children:n?"Stop Tracing":"Trace Location"})})}import U,{useState as Ve}from"react";import v,{useRef as ke,useState as q}from"react";import{jsx as R,jsxs as M}from"react/jsx-runtime";var De=({addFeature:t,InputComponent:o,ButtonComponent:e,LocationIcon:a,SuccessIcon:n,FailureIcon:c})=>{let l=ke(null),[s,r]=q(!0),[g,m]=q(""),[y,I]=q([]),b=()=>{try{let i=l.current?.value??"";if(!i.trim()){r(!1),m("Invalid Format. Enter Latitude, Longitude.");return}let F=i.split(",").map(Number)?.reverse();if(!x(F)){r(!1),m("Invalid Format. Enter Latitude, Longitude.");return}let G={type:p.POINT,properties:{id:new Date().getTime(),name:i,formatted_address:i},coordinates:F};t(G),I(w=>[...w,G]),l.current&&(l.current.value=""),r(!0),m("Point added successfully")}catch{r(!1)}finally{setTimeout(()=>{m(""),r(!0)},3e3)}},x=i=>Array.isArray(i)&&i.length===2&&!isNaN(i[0])&&!isNaN(i[1])&&typeof i[0]=="number"&&typeof i[1]=="number";return M("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-start"},children:[R("h1",{style:{marginBottom:"10px",fontWeight:"bold",fontSize:"1.25rem"},children:"Point"}),M("div",{style:{display:"flex",alignItems:"center"},children:[v.isValidElement(o)?v.cloneElement(o,{ref:l,width:"300px"}):R("input",{ref:l,style:{width:"300px"}}),v.isValidElement(e)?v.cloneElement(e,{onClick:b,type:"button",marginLeft:"10px"}):R("button",{type:"button",onClick:b,style:{marginLeft:"10px"},children:"Add"})]}),g&&M("div",{style:{fontWeight:"bold",color:s?"green":"red",marginTop:"10px",display:"flex",alignItems:"center"},children:[s?R("span",{style:{marginRight:"5px",fontSize:"1.25rem"},children:v.isValidElement(n)?v.cloneElement(n,{boxSize:6}):"\u2713"}):R("span",{style:{marginRight:"5px",fontSize:"1.25rem",color:"red"},children:v.isValidElement(c)?v.cloneElement(c,{boxSize:4}):"\u26A0"}),g]}),y.length>0&&M("div",{style:{marginTop:"10px",paddingLeft:"15px"},children:[R("div",{style:{fontSize:"sm"},children:"Added Points:"}),R("ul",{style:{listStyleType:"none",padding:"0"},children:y.map(i=>M("li",{style:{display:"flex",alignItems:"center",marginBottom:"5px"},children:[v.isValidElement(a)?v.cloneElement(a,{boxSize:6,marginRight:2,color:"teal"}):R("span",{style:{marginRight:"6px"},children:"\u{1F4CD}"}),R("span",{style:{overflow:"hidden",whiteSpace:"pre-wrap",textOverflow:"ellipsis",maxWidth:"300px"},children:i.properties.name})]},i.properties.id))})]})]})},ye=De;import S,{useState as B,useRef as Me}from"react";import{Fragment as Je,jsx as u,jsxs as N}from"react/jsx-runtime";var ze=({addFeature:t,ButtonComponent:o,FileIcon:e,SuccessIcon:a,FailureIcon:n,DeleteIcon:c})=>{let[l,s]=B(!0),[r,g]=B(""),[m,y]=B([]),[I,b]=B([]),x=Me(null),i=d=>{d.preventDefault()},F=d=>{d.preventDefault()},G=d=>{d.preventDefault();let h=Array.from(d.dataTransfer.files);y(h)},w=()=>{let d=Array.from(x.current.files);y(d)},z=()=>{try{m.forEach(d=>{let h=new FileReader;h.onabort=()=>L("File reading was aborted. Please try again."),h.onerror=()=>L("File reading has failed. Please try again."),h.onload=()=>{let k=h.result;if(k){let j=typeof k=="string"?k:new TextDecoder().decode(k);try{let O=JSON.parse(j);(Array.isArray(O.features)?O.features.map(P=>({...P,isGeojson:!0})):[{...O,isGeojson:!0}]).forEach(P=>{t([P])}),g("Geojson added successfully"),s(!0),b(P=>[...P,{name:d.name}]),y([])}catch(O){console.error(O),L("Upload failed. Invalid GeoJSON format.")}}else L("File reading result is null.")},h.readAsText(d)})}catch(d){console.error(d),L("File upload failed. Please try again.")}finally{setTimeout(()=>{g(""),s(!0)},2e3)}},L=d=>{g(d),s(!1)},$=()=>{y([])};return N("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-start",marginTop:"10px"},onDragEnter:i,onDragOver:F,onDrop:G,children:[u("h1",{style:{marginBottom:"10px",fontWeight:"bold",fontSize:"1.25rem"},children:"GeoJSON"}),N("div",{style:{display:"flex",flexDirection:"row",alignItems:"center"},children:[N("div",{style:{border:"2px solid #519895",borderRadius:"4px",display:"flex",flexDirection:"column",alignItems:"center",padding:"10px",cursor:"pointer",marginLeft:"15px",width:"300px",height:"100px"},onClick:()=>x.current.click(),children:[u("input",{type:"file",ref:x,onChange:w,style:{display:"none"}}),u("div",{style:{display:"flex",alignItems:"center"},children:m.length>0?N("div",{style:{marginLeft:"10px",display:"flex",alignItems:"center"},children:[u("div",{style:{marginTop:"10px",overflow:"hidden",whiteSpace:"pre-wrap",textOverflow:"ellipsis",maxWidth:"200px"},children:m[0].name}),u("div",{style:{color:"red",marginLeft:"10px",marginTop:"10px",cursor:"pointer"},onClick:$,children:S.isValidElement(c)?S.cloneElement(c,{boxSize:6}):"\u2715"})]}):u(Je,{children:u("div",{children:"Drag 'n' drop GeoJSON file here, or click to select a file"})})})]}),S.isValidElement(o)?S.cloneElement(o,{type:"button",marginLeft:"30px",style:{paddingLeft:"15px"},onClick:z}):u("button",{type:"button",onClick:z,style:{marginLeft:"30px",padding:"6px 15px",cursor:"pointer"},children:"Add"})]}),r&&N("div",{style:{fontWeight:"bold",color:l?"green":"red",marginTop:"10px",display:"flex",alignItems:"center"},children:[l?u("span",{style:{marginRight:"5px",fontSize:"1.25rem"},children:S.isValidElement(a)?S.cloneElement(a,{boxSize:6}):"\u2713"}):u("span",{style:{marginRight:"5px",fontSize:"1.25rem",color:"red"},children:S.isValidElement(n)?S.cloneElement(n,{boxSize:4}):"\u26A0"}),r]}),I.length>0&&N("div",{style:{marginTop:"10px",paddingLeft:"15px"},children:[u("div",{style:{fontSize:"sm"},children:"Added GeoJSONs:"}),u("ul",{style:{listStyleType:"none",padding:"0"},children:I.map((d,h)=>N("li",{style:{display:"flex",alignItems:"center"},children:[S.isValidElement(e)?S.cloneElement(e,{boxSize:6,marginRight:2}):u("span",{style:{marginRight:"8px"},children:"\u{1F4C4}"}),u("div",{style:{marginTop:"10px",overflow:"hidden",whiteSpace:"pre-wrap",textOverflow:"ellipsis",maxWidth:"300px"},children:d.name})]},h))})]})]})},he=ze;import{jsx as T,jsxs as Y}from"react/jsx-runtime";var _e=({isOpen:t,onClose:o,nakshaImport:e,geoJSONImport:a})=>t?T("div",{style:{position:"fixed",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0, 0, 0, 0.5)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:99999},onClick:o,children:Y("div",{style:{background:"#fff",borderRadius:"8px",padding:"24px",maxWidth:"500px",width:"90%",maxHeight:"85vh",overflowY:"auto",boxShadow:"0 4px 12px rgba(0,0,0,0.15)",position:"relative"},onClick:n=>n.stopPropagation(),children:[T("button",{type:"button",onClick:o,style:{position:"absolute",top:12,right:12,border:"none",background:"none",fontSize:"18px",cursor:"pointer"},children:"\u2715"}),T("h3",{style:{margin:"0 0 16px 0",fontSize:"18px",fontWeight:600},children:"Import Data"}),Y("div",{style:{marginBottom:"20px"},children:[T("h4",{style:{margin:"0 0 8px 0",fontSize:"14px",fontWeight:500},children:"Import Coordinates"}),e]}),Y("div",{children:[T("h4",{style:{margin:"0 0 8px 0",fontSize:"14px",fontWeight:500},children:"Import GeoJSON"}),a]})]})}):null;function Q({ButtonComponent:t,ModalComponent:o,addFeature:e,InputComponent:a,ButtonComponentModal:n,DeleteIcon:c,LocationIcon:l,FileIcon:s,SuccessIcon:r,FailureIcon:g}){let[m,y]=Ve(!1),I=()=>{y(!1)},b=()=>{y(!0)},x=T(ye,{addFeature:e,InputComponent:a,ButtonComponent:t,LocationIcon:l,SuccessIcon:r,FailureIcon:g}),i=T(he,{addFeature:e,ButtonComponent:t,DeleteIcon:c,FileIcon:s,SuccessIcon:r,FailureIcon:g});return Y("div",{style:{display:"flex"},children:[U.isValidElement(o)?U.cloneElement(o,{isOpen:m,onClose:I,nakshaImport:x,geoJSONImport:i}):T(_e,{isOpen:m,onClose:I,nakshaImport:x,geoJSONImport:i}),U.isValidElement(n)?U.cloneElement(n,{onClick:b,type:"button"}):T("button",{type:"button",onClick:b,style:{padding:"6px 16px",backgroundColor:"#519895",color:"white",border:"none",borderRadius:"4px",cursor:"pointer"},children:"Import"})]})}import{Fragment as Qe,jsx as f,jsxs as X}from"react/jsx-runtime";var _t=je.forwardRef(({defaultViewState:t,defaultDrawingMode:o,data:e,onDataChange:a,gmapAccessToken:n,isControlled:c,isReadOnly:l,isMultiple:s,isImport:r,isAutocomplete:g,gmapRegion:m,autoCompleteRegion:y,mapStyle:I,importInputComponent:b,importButtonComponent:x,autocompleteComponent:i,showTrace:F,traceButtonComponent:G,maxZoom:w,options:z,importModalComponent:L,isOpen:$,onClose:d,importButtonComponentModal:h,importDeleteIcon:k,importLocationIcon:j,importFileIcon:O,importSuccessIcon:ee,importFailureIcon:P},te)=>{let A=Ke(null),[J,V]=Ze(de,e),[oe,ve]=qe(),ne=He(()=>We(t),[t]),Se=()=>{A.current.state.map.data.forEach(function(D){A.current.state.map.data.remove(D)});let E=le(J);if(E){E&&A.current.state.map.data.addGeoJson(E);let D=pe(E);D&&A.current.state.map.fitBounds(D),w&&google.maps.event.addListenerOnce(A.current.state.map,"idle",function(){let Te=A.current.state.map.getZoom();A.current.state.map.setZoom(Math.min(w,Te))})}};Ee(()=>{oe&&(a&&a(J),te&&(te.current={addFeature:_,replaceFeature:Ie}),Se())},[oe,J]),Ee(()=>{c&&JSON.stringify(J)!==JSON.stringify(e)&&V({action:C.REPLACE,data:e})},[e]);let _=E=>{V({action:C.ADD,data:E,isMultiple:s})},Ie=E=>{V({action:C.REPLACE,data:[E]})},ae=E=>{let D=se(E);_(D)},be=()=>{V({action:C.CLEAR})},Re=()=>ve(!0);return f(Ye,{googleMapsApiKey:n,region:m,libraries:g?xe.AUTOCOMPLETE:xe.DEFAULT,children:X(Qe,{children:[X("div",{style:{display:"flex"},children:[g&&f("div",{style:{width:"500px"},children:f(H,{InputComponent:i||f("input",{}),addFeature:_,gmapRegion:y??m})}),f("div",{style:{flex:"1"}}),r&&f(Q,{ButtonComponent:x||f("button",{children:"add"}),ModalComponent:L,InputComponent:b||f("input",{}),addFeature:_,ButtonComponentModal:h||f("button",{children:"Import"}),DeleteIcon:k,LocationIcon:j,FileIcon:O,SuccessIcon:ee,FailureIcon:P})]}),F&&f(K,{TraceButtonComponent:G||f("button",{children:"trace"}),onFeatureAdded:ae}),X(Ue,{id:"naksha-gmaps-draw",mapContainerStyle:I||{height:"100%",width:"100%"},zoom:ne.zoom,center:ne.center,options:re,ref:A,onLoad:Re,children:[s&&f(Z,{onClick:be}),!l&&f(Be,{options:{controls:[p.POINT,p.POLYGON,p.LINESTRING],drawingMode:o||p.POLYGON,featureFactory:ae,...z||{}}})]})]})})});export{p as GMAP_FEATURE_TYPES,_t as NakshaGmapsDraw};
1
+ // src/index.tsx
2
+ import {
3
+ GMAPS_LIBRARIES,
4
+ mapboxToGmapsViewState
5
+ } from "@biodiv-platform/naksha-commons";
6
+ import { Data, GoogleMap, LoadScriptNext } from "@react-google-maps/api";
7
+ import React6, { useEffect as useEffect3, useMemo, useReducer, useRef as useRef3, useState as useState7 } from "react";
8
+
9
+ // src/autocomplete/index.tsx
10
+ import { GMAPS_AUTOCOMPLETE_FIELDS } from "@biodiv-platform/naksha-commons";
11
+ import { Autocomplete } from "@react-google-maps/api";
12
+ import { useState } from "react";
13
+
14
+ // src/utils/geojson.tsx
15
+ import bbox from "@turf/bbox";
16
+
17
+ // src/static/constants.tsx
18
+ var GMAP_FEATURE_TYPES = {
19
+ POINT: "Point",
20
+ POLYGON: "Polygon",
21
+ LINESTRING: "LineString",
22
+ RECTANGLE: "Rectangle",
23
+ RAW: "Raw",
24
+ NONE: null
25
+ };
26
+ var GMAP_OPTIONS = {
27
+ mapTypeControlOptions: {
28
+ position: 10
29
+ }
30
+ };
31
+
32
+ // src/utils/geojson.tsx
33
+ var placeToGeoJsonFeature = (place) => {
34
+ return {
35
+ type: GMAP_FEATURE_TYPES.POINT,
36
+ properties: {
37
+ id: (/* @__PURE__ */ new Date()).getTime(),
38
+ name: place.name,
39
+ formatted_address: place.formatted_address
40
+ },
41
+ coordinates: Object.values(place.geometry.location.toJSON()).reverse()
42
+ };
43
+ };
44
+ var geometryToGeoJsonFeature = (geometry) => {
45
+ const id = (/* @__PURE__ */ new Date()).getTime();
46
+ switch (geometry.getType()) {
47
+ case GMAP_FEATURE_TYPES.POINT: {
48
+ return {
49
+ type: GMAP_FEATURE_TYPES.POINT,
50
+ properties: { id },
51
+ coordinates: Object.values(geometry.get().toJSON()).reverse()
52
+ };
53
+ }
54
+ case GMAP_FEATURE_TYPES.POLYGON: {
55
+ const clist = [];
56
+ const toLatLng = (c) => clist.push([c.lng(), c.lat()]);
57
+ geometry.forEachLatLng(toLatLng);
58
+ clist.push(clist[0]);
59
+ return {
60
+ type: GMAP_FEATURE_TYPES.POLYGON,
61
+ properties: { id },
62
+ coordinates: [clist]
63
+ };
64
+ }
65
+ case GMAP_FEATURE_TYPES.RAW: {
66
+ const clist = geometry.data;
67
+ clist.push(clist[0]);
68
+ return {
69
+ type: GMAP_FEATURE_TYPES.POLYGON,
70
+ properties: { id },
71
+ coordinates: [clist]
72
+ };
73
+ }
74
+ case GMAP_FEATURE_TYPES.LINESTRING: {
75
+ const clist = [];
76
+ const toLatLng = (c) => clist.push([c.lng(), c.lat()]);
77
+ geometry.forEachLatLng(toLatLng);
78
+ return {
79
+ type: GMAP_FEATURE_TYPES.LINESTRING,
80
+ properties: { id },
81
+ coordinates: clist
82
+ };
83
+ }
84
+ default:
85
+ return null;
86
+ }
87
+ };
88
+ var toFullGeoJson = (features) => {
89
+ const cleanFeaures = (features || []).filter((o) => o);
90
+ if (cleanFeaures.length === 0) {
91
+ return false;
92
+ }
93
+ const mergedGeoJson = {
94
+ type: "FeatureCollection",
95
+ features: cleanFeaures.map((value) => {
96
+ if (Array.isArray(value) && value.length > 0 && value[0].isGeojson) {
97
+ const feature = value[0];
98
+ return {
99
+ type: "Feature",
100
+ properties: feature.properties || {},
101
+ geometry: feature.geometry || null
102
+ };
103
+ } else {
104
+ return { type: "Feature", properties: {}, geometry: value };
105
+ }
106
+ })
107
+ };
108
+ return mergedGeoJson;
109
+ };
110
+ var calculateBounds = (geojson) => {
111
+ const b = bbox(geojson);
112
+ return {
113
+ east: b[2],
114
+ north: b[3],
115
+ south: b[1],
116
+ west: b[0]
117
+ };
118
+ };
119
+
120
+ // src/autocomplete/index.tsx
121
+ import { jsx } from "react/jsx-runtime";
122
+ function NakshaAutocomplete({
123
+ InputComponent,
124
+ addFeature,
125
+ gmapRegion
126
+ }) {
127
+ const [ac, setAc] = useState();
128
+ const onLoad = (autocomplete) => {
129
+ setAc(autocomplete);
130
+ };
131
+ const onPlaceChanged = () => {
132
+ const feature = placeToGeoJsonFeature(ac?.getPlace());
133
+ addFeature(feature);
134
+ };
135
+ return /* @__PURE__ */ jsx(
136
+ Autocomplete,
137
+ {
138
+ onLoad,
139
+ fields: GMAPS_AUTOCOMPLETE_FIELDS,
140
+ onPlaceChanged,
141
+ options: gmapRegion ? { componentRestrictions: { country: gmapRegion } } : {},
142
+ children: InputComponent
143
+ }
144
+ );
145
+ }
146
+
147
+ // src/features/clear-features.tsx
148
+ import { jsx as jsx2 } from "react/jsx-runtime";
149
+ var ButtonStyle = {
150
+ background: "white",
151
+ position: "absolute",
152
+ top: "5px",
153
+ left: "106px",
154
+ padding: "0.4rem",
155
+ borderRadius: "0.15rem",
156
+ outline: 0,
157
+ boxShadow: "rgba(0, 0, 0, 0.3) 0px 1px 4px -1px"
158
+ };
159
+ function ClearFeatures({ onClick }) {
160
+ return /* @__PURE__ */ jsx2("button", { type: "button", title: "Clear", onClick, style: ButtonStyle, children: /* @__PURE__ */ jsx2("svg", { viewBox: "0 0 24 24", width: "12", height: "12", children: /* @__PURE__ */ jsx2("g", { fill: "#E53E3E", children: /* @__PURE__ */ jsx2("path", { 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" }) }) }) });
161
+ }
162
+
163
+ // src/reducers/features.tsx
164
+ var ACTION_TYPES = {
165
+ ADD: "add",
166
+ CLEAR: "clear",
167
+ REPLACE: "replace"
168
+ };
169
+ function featuresReducer(state, { action, data, isMultiple }) {
170
+ switch (action) {
171
+ case ACTION_TYPES.ADD:
172
+ return isMultiple ? [...state || [], data] : [data];
173
+ case ACTION_TYPES.CLEAR:
174
+ return [];
175
+ case ACTION_TYPES.REPLACE:
176
+ return data;
177
+ default:
178
+ return state;
179
+ }
180
+ }
181
+
182
+ // src/trace-location/index.tsx
183
+ import React2, { useEffect as useEffect2, useState as useState3 } from "react";
184
+
185
+ // src/utils/use-location.tsx
186
+ import { useState as useState2, useEffect } from "react";
187
+ var defaultSettings = {
188
+ enableHighAccuracy: false,
189
+ timeout: Infinity,
190
+ maximumAge: 0
191
+ };
192
+ var usePosition = (watch, settings = defaultSettings) => {
193
+ const [position, setPosition] = useState2();
194
+ const [error, setError] = useState2();
195
+ const onChange = ({ coords }) => {
196
+ setPosition([coords.longitude, coords.latitude]);
197
+ };
198
+ const onError = (error2) => {
199
+ setError(error2.message);
200
+ };
201
+ useEffect(() => {
202
+ if (!navigator || !navigator.geolocation) {
203
+ setError("Geolocation is not supported");
204
+ return;
205
+ }
206
+ let watcher = null;
207
+ if (watch) {
208
+ watcher = navigator.geolocation.watchPosition(
209
+ onChange,
210
+ onError,
211
+ settings
212
+ );
213
+ } else {
214
+ watcher && navigator.geolocation.clearWatch(watcher);
215
+ }
216
+ return () => watcher && navigator.geolocation.clearWatch(watcher);
217
+ }, [settings, watch]);
218
+ return { position, error };
219
+ };
220
+
221
+ // src/trace-location/index.tsx
222
+ import { jsx as jsx3 } from "react/jsx-runtime";
223
+ function TraceLocation({
224
+ TraceButtonComponent,
225
+ onFeatureAdded
226
+ }) {
227
+ const [trackData, setTrackData] = useState3([]);
228
+ const [isTracking, setIsTracking] = useState3(false);
229
+ const { position } = usePosition(isTracking);
230
+ useEffect2(() => {
231
+ if (isTracking && position) {
232
+ setTrackData([...trackData, position]);
233
+ }
234
+ }, [isTracking, position]);
235
+ const handleOnTraceAction = () => {
236
+ if (isTracking) {
237
+ setIsTracking(false);
238
+ onFeatureAdded({
239
+ getType: () => GMAP_FEATURE_TYPES.RAW,
240
+ data: [...trackData]
241
+ });
242
+ setTrackData([]);
243
+ } else {
244
+ setIsTracking(true);
245
+ }
246
+ };
247
+ return /* @__PURE__ */ jsx3("div", { children: React2.isValidElement(TraceButtonComponent) ? React2.cloneElement(TraceButtonComponent, {
248
+ onClick: handleOnTraceAction,
249
+ isTracking
250
+ }) : /* @__PURE__ */ jsx3(
251
+ "button",
252
+ {
253
+ type: "button",
254
+ onClick: handleOnTraceAction,
255
+ style: {
256
+ padding: "6px 12px",
257
+ borderRadius: "4px",
258
+ border: "1px solid #ccc",
259
+ background: isTracking ? "#e53e3e" : "#fff",
260
+ color: isTracking ? "#fff" : "#333",
261
+ cursor: "pointer"
262
+ },
263
+ children: isTracking ? "Stop Tracing" : "Trace Location"
264
+ }
265
+ ) });
266
+ }
267
+
268
+ // src/ModalImport/index.tsx
269
+ import React5, { useState as useState6 } from "react";
270
+
271
+ // src/import/index.tsx
272
+ import React3, { useRef, useState as useState4 } from "react";
273
+ import { jsx as jsx4, jsxs } from "react/jsx-runtime";
274
+ var NakshaImport = ({
275
+ addFeature,
276
+ InputComponent,
277
+ ButtonComponent,
278
+ LocationIcon,
279
+ SuccessIcon,
280
+ FailureIcon
281
+ }) => {
282
+ const importInputRef = useRef(null);
283
+ const [isPointsValid, setIsPointsValid] = useState4(true);
284
+ const [uploadStatus, setUploadStatus] = useState4("");
285
+ const [importedPoints, setImportedPoints] = useState4([]);
286
+ const handleOnAddFeature = () => {
287
+ try {
288
+ const txtLatLng = importInputRef.current?.value ?? "";
289
+ if (!txtLatLng.trim()) {
290
+ setIsPointsValid(false);
291
+ setUploadStatus("Invalid Format. Enter Latitude, Longitude.");
292
+ return;
293
+ }
294
+ const numLatLng = txtLatLng.split(",").map(Number)?.reverse();
295
+ if (!isValidLatLng(numLatLng)) {
296
+ setIsPointsValid(false);
297
+ setUploadStatus("Invalid Format. Enter Latitude, Longitude.");
298
+ return;
299
+ }
300
+ const newFeature = {
301
+ type: GMAP_FEATURE_TYPES.POINT,
302
+ properties: {
303
+ id: (/* @__PURE__ */ new Date()).getTime(),
304
+ name: txtLatLng,
305
+ formatted_address: txtLatLng
306
+ },
307
+ coordinates: numLatLng
308
+ };
309
+ addFeature(newFeature);
310
+ setImportedPoints((prevPoints) => [...prevPoints, newFeature]);
311
+ if (importInputRef.current) {
312
+ importInputRef.current.value = "";
313
+ }
314
+ setIsPointsValid(true);
315
+ setUploadStatus("Point added successfully");
316
+ } catch (e) {
317
+ setIsPointsValid(false);
318
+ } finally {
319
+ setTimeout(() => {
320
+ setUploadStatus("");
321
+ setIsPointsValid(true);
322
+ }, 3e3);
323
+ }
324
+ };
325
+ const isValidLatLng = (latLng) => {
326
+ return Array.isArray(latLng) && latLng.length === 2 && !isNaN(latLng[0]) && !isNaN(latLng[1]) && typeof latLng[0] === "number" && typeof latLng[1] === "number";
327
+ };
328
+ return /* @__PURE__ */ jsxs(
329
+ "div",
330
+ {
331
+ style: {
332
+ display: "flex",
333
+ flexDirection: "column",
334
+ alignItems: "flex-start"
335
+ },
336
+ children: [
337
+ /* @__PURE__ */ jsx4(
338
+ "h1",
339
+ {
340
+ style: {
341
+ marginBottom: "10px",
342
+ fontWeight: "bold",
343
+ fontSize: "1.25rem"
344
+ },
345
+ children: "Point"
346
+ }
347
+ ),
348
+ /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center" }, children: [
349
+ React3.isValidElement(InputComponent) ? React3.cloneElement(InputComponent, {
350
+ ref: importInputRef,
351
+ width: "300px"
352
+ }) : /* @__PURE__ */ jsx4("input", { ref: importInputRef, style: { width: "300px" } }),
353
+ React3.isValidElement(ButtonComponent) ? React3.cloneElement(ButtonComponent, {
354
+ onClick: handleOnAddFeature,
355
+ type: "button",
356
+ marginLeft: "10px"
357
+ }) : /* @__PURE__ */ jsx4(
358
+ "button",
359
+ {
360
+ type: "button",
361
+ onClick: handleOnAddFeature,
362
+ style: { marginLeft: "10px" },
363
+ children: "Add"
364
+ }
365
+ )
366
+ ] }),
367
+ uploadStatus && /* @__PURE__ */ jsxs(
368
+ "div",
369
+ {
370
+ style: {
371
+ fontWeight: "bold",
372
+ color: isPointsValid ? "green" : "red",
373
+ marginTop: "10px",
374
+ display: "flex",
375
+ alignItems: "center"
376
+ },
377
+ children: [
378
+ isPointsValid ? /* @__PURE__ */ jsx4("span", { style: { marginRight: "5px", fontSize: "1.25rem" }, children: React3.isValidElement(SuccessIcon) ? React3.cloneElement(SuccessIcon, { boxSize: 6 }) : "\u2713" }) : /* @__PURE__ */ jsx4(
379
+ "span",
380
+ {
381
+ style: { marginRight: "5px", fontSize: "1.25rem", color: "red" },
382
+ children: React3.isValidElement(FailureIcon) ? React3.cloneElement(FailureIcon, { boxSize: 4 }) : "\u26A0"
383
+ }
384
+ ),
385
+ uploadStatus
386
+ ]
387
+ }
388
+ ),
389
+ importedPoints.length > 0 && /* @__PURE__ */ jsxs("div", { style: { marginTop: "10px", paddingLeft: "15px" }, children: [
390
+ /* @__PURE__ */ jsx4("div", { style: { fontSize: "sm" }, children: "Added Points:" }),
391
+ /* @__PURE__ */ jsx4("ul", { style: { listStyleType: "none", padding: "0" }, children: importedPoints.map((point) => /* @__PURE__ */ jsxs(
392
+ "li",
393
+ {
394
+ style: {
395
+ display: "flex",
396
+ alignItems: "center",
397
+ marginBottom: "5px"
398
+ },
399
+ children: [
400
+ React3.isValidElement(LocationIcon) ? React3.cloneElement(LocationIcon, {
401
+ boxSize: 6,
402
+ marginRight: 2,
403
+ color: "teal"
404
+ }) : /* @__PURE__ */ jsx4("span", { style: { marginRight: "6px" }, children: "\u{1F4CD}" }),
405
+ /* @__PURE__ */ jsx4(
406
+ "span",
407
+ {
408
+ style: {
409
+ overflow: "hidden",
410
+ whiteSpace: "pre-wrap",
411
+ textOverflow: "ellipsis",
412
+ maxWidth: "300px"
413
+ },
414
+ children: point.properties.name
415
+ }
416
+ )
417
+ ]
418
+ },
419
+ point.properties.id
420
+ )) })
421
+ ] })
422
+ ]
423
+ }
424
+ );
425
+ };
426
+ var import_default = NakshaImport;
427
+
428
+ // src/geojson/index.tsx
429
+ import React4, { useState as useState5, useRef as useRef2 } from "react";
430
+ import { Fragment, jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
431
+ var GeojsonImport = ({
432
+ addFeature,
433
+ ButtonComponent,
434
+ FileIcon,
435
+ SuccessIcon,
436
+ FailureIcon,
437
+ DeleteIcon
438
+ }) => {
439
+ const [isGeoJSONValid, setIsGeoJSONValid] = useState5(true);
440
+ const [uploadStatus, setUploadStatus] = useState5("");
441
+ const [filesToUpload, setFilesToUpload] = useState5([]);
442
+ const [uploadedFiles, setUploadedFiles] = useState5([]);
443
+ const fileInputRef = useRef2(null);
444
+ const handleDragEnter = (e) => {
445
+ e.preventDefault();
446
+ };
447
+ const handleDragOver = (e) => {
448
+ e.preventDefault();
449
+ };
450
+ const handleDrop = (e) => {
451
+ e.preventDefault();
452
+ const droppedFiles = Array.from(e.dataTransfer.files);
453
+ setFilesToUpload(droppedFiles);
454
+ };
455
+ const handleFileInputChange = () => {
456
+ const selectedFiles = Array.from(fileInputRef.current.files);
457
+ setFilesToUpload(selectedFiles);
458
+ };
459
+ const handleAddFeature = () => {
460
+ try {
461
+ filesToUpload.forEach((file) => {
462
+ const reader = new FileReader();
463
+ reader.onabort = () => handleError("File reading was aborted. Please try again.");
464
+ reader.onerror = () => handleError("File reading has failed. Please try again.");
465
+ reader.onload = () => {
466
+ const result = reader.result;
467
+ if (result) {
468
+ const jsonString = typeof result === "string" ? result : new TextDecoder().decode(result);
469
+ try {
470
+ const geojsonObject = JSON.parse(jsonString);
471
+ const featuresToAdd = Array.isArray(geojsonObject.features) ? geojsonObject.features.map((feature) => ({
472
+ ...feature,
473
+ isGeojson: true
474
+ })) : [{ ...geojsonObject, isGeojson: true }];
475
+ featuresToAdd.forEach((featureToAdd) => {
476
+ addFeature([featureToAdd]);
477
+ });
478
+ setUploadStatus("Geojson added successfully");
479
+ setIsGeoJSONValid(true);
480
+ setUploadedFiles((prevFiles) => [
481
+ ...prevFiles,
482
+ { name: file.name }
483
+ ]);
484
+ setFilesToUpload([]);
485
+ } catch (error) {
486
+ console.error(error);
487
+ handleError("Upload failed. Invalid GeoJSON format.");
488
+ }
489
+ } else {
490
+ handleError("File reading result is null.");
491
+ }
492
+ };
493
+ reader.readAsText(file);
494
+ });
495
+ } catch (error) {
496
+ console.error(error);
497
+ handleError("File upload failed. Please try again.");
498
+ } finally {
499
+ setTimeout(() => {
500
+ setUploadStatus("");
501
+ setIsGeoJSONValid(true);
502
+ }, 2e3);
503
+ }
504
+ };
505
+ const handleError = (message) => {
506
+ setUploadStatus(message);
507
+ setIsGeoJSONValid(false);
508
+ };
509
+ const removeFile = () => {
510
+ setFilesToUpload([]);
511
+ };
512
+ return /* @__PURE__ */ jsxs2(
513
+ "div",
514
+ {
515
+ style: {
516
+ display: "flex",
517
+ flexDirection: "column",
518
+ alignItems: "flex-start",
519
+ marginTop: "10px"
520
+ },
521
+ onDragEnter: handleDragEnter,
522
+ onDragOver: handleDragOver,
523
+ onDrop: handleDrop,
524
+ children: [
525
+ /* @__PURE__ */ jsx5(
526
+ "h1",
527
+ {
528
+ style: {
529
+ marginBottom: "10px",
530
+ fontWeight: "bold",
531
+ fontSize: "1.25rem"
532
+ },
533
+ children: "GeoJSON"
534
+ }
535
+ ),
536
+ /* @__PURE__ */ jsxs2(
537
+ "div",
538
+ {
539
+ style: {
540
+ display: "flex",
541
+ flexDirection: "row",
542
+ alignItems: "center"
543
+ },
544
+ children: [
545
+ /* @__PURE__ */ jsxs2(
546
+ "div",
547
+ {
548
+ style: {
549
+ border: "2px solid #519895",
550
+ borderRadius: "4px",
551
+ display: "flex",
552
+ flexDirection: "column",
553
+ alignItems: "center",
554
+ padding: "10px",
555
+ cursor: "pointer",
556
+ marginLeft: "15px",
557
+ width: "300px",
558
+ height: "100px"
559
+ },
560
+ onClick: () => fileInputRef.current.click(),
561
+ children: [
562
+ /* @__PURE__ */ jsx5(
563
+ "input",
564
+ {
565
+ type: "file",
566
+ ref: fileInputRef,
567
+ onChange: handleFileInputChange,
568
+ style: { display: "none" }
569
+ }
570
+ ),
571
+ /* @__PURE__ */ jsx5(
572
+ "div",
573
+ {
574
+ style: {
575
+ display: "flex",
576
+ alignItems: "center"
577
+ },
578
+ children: filesToUpload.length > 0 ? /* @__PURE__ */ jsxs2(
579
+ "div",
580
+ {
581
+ style: {
582
+ marginLeft: "10px",
583
+ display: "flex",
584
+ alignItems: "center"
585
+ },
586
+ children: [
587
+ /* @__PURE__ */ jsx5(
588
+ "div",
589
+ {
590
+ style: {
591
+ marginTop: "10px",
592
+ overflow: "hidden",
593
+ whiteSpace: "pre-wrap",
594
+ textOverflow: "ellipsis",
595
+ maxWidth: "200px"
596
+ },
597
+ children: filesToUpload[0].name
598
+ }
599
+ ),
600
+ /* @__PURE__ */ jsx5(
601
+ "div",
602
+ {
603
+ style: {
604
+ color: "red",
605
+ marginLeft: "10px",
606
+ marginTop: "10px",
607
+ cursor: "pointer"
608
+ },
609
+ onClick: removeFile,
610
+ children: React4.isValidElement(DeleteIcon) ? React4.cloneElement(DeleteIcon, { boxSize: 6 }) : "\u2715"
611
+ }
612
+ )
613
+ ]
614
+ }
615
+ ) : /* @__PURE__ */ jsx5(Fragment, { children: /* @__PURE__ */ jsx5("div", { children: "Drag 'n' drop GeoJSON file here, or click to select a file" }) })
616
+ }
617
+ )
618
+ ]
619
+ }
620
+ ),
621
+ React4.isValidElement(ButtonComponent) ? React4.cloneElement(ButtonComponent, {
622
+ type: "button",
623
+ marginLeft: "30px",
624
+ style: { paddingLeft: "15px" },
625
+ onClick: handleAddFeature
626
+ }) : /* @__PURE__ */ jsx5(
627
+ "button",
628
+ {
629
+ type: "button",
630
+ onClick: handleAddFeature,
631
+ style: {
632
+ marginLeft: "30px",
633
+ padding: "6px 15px",
634
+ cursor: "pointer"
635
+ },
636
+ children: "Add"
637
+ }
638
+ )
639
+ ]
640
+ }
641
+ ),
642
+ uploadStatus && /* @__PURE__ */ jsxs2(
643
+ "div",
644
+ {
645
+ style: {
646
+ fontWeight: "bold",
647
+ color: isGeoJSONValid ? "green" : "red",
648
+ marginTop: "10px",
649
+ display: "flex",
650
+ alignItems: "center"
651
+ },
652
+ children: [
653
+ isGeoJSONValid ? /* @__PURE__ */ jsx5(
654
+ "span",
655
+ {
656
+ style: {
657
+ marginRight: "5px",
658
+ fontSize: "1.25rem"
659
+ },
660
+ children: React4.isValidElement(SuccessIcon) ? React4.cloneElement(SuccessIcon, { boxSize: 6 }) : "\u2713"
661
+ }
662
+ ) : /* @__PURE__ */ jsx5(
663
+ "span",
664
+ {
665
+ style: {
666
+ marginRight: "5px",
667
+ fontSize: "1.25rem",
668
+ color: "red"
669
+ },
670
+ children: React4.isValidElement(FailureIcon) ? React4.cloneElement(FailureIcon, { boxSize: 4 }) : "\u26A0"
671
+ }
672
+ ),
673
+ uploadStatus
674
+ ]
675
+ }
676
+ ),
677
+ uploadedFiles.length > 0 && /* @__PURE__ */ jsxs2(
678
+ "div",
679
+ {
680
+ style: {
681
+ marginTop: "10px",
682
+ paddingLeft: "15px"
683
+ },
684
+ children: [
685
+ /* @__PURE__ */ jsx5(
686
+ "div",
687
+ {
688
+ style: {
689
+ fontSize: "sm"
690
+ },
691
+ children: "Added GeoJSONs:"
692
+ }
693
+ ),
694
+ /* @__PURE__ */ jsx5(
695
+ "ul",
696
+ {
697
+ style: {
698
+ listStyleType: "none",
699
+ padding: "0"
700
+ },
701
+ children: uploadedFiles.map((file, index) => /* @__PURE__ */ jsxs2(
702
+ "li",
703
+ {
704
+ style: {
705
+ display: "flex",
706
+ alignItems: "center"
707
+ },
708
+ children: [
709
+ React4.isValidElement(FileIcon) ? React4.cloneElement(FileIcon, { boxSize: 6, marginRight: 2 }) : /* @__PURE__ */ jsx5("span", { style: { marginRight: "8px" }, children: "\u{1F4C4}" }),
710
+ /* @__PURE__ */ jsx5(
711
+ "div",
712
+ {
713
+ style: {
714
+ marginTop: "10px",
715
+ overflow: "hidden",
716
+ whiteSpace: "pre-wrap",
717
+ textOverflow: "ellipsis",
718
+ maxWidth: "300px"
719
+ },
720
+ children: file.name
721
+ }
722
+ )
723
+ ]
724
+ },
725
+ index
726
+ ))
727
+ }
728
+ )
729
+ ]
730
+ }
731
+ )
732
+ ]
733
+ }
734
+ );
735
+ };
736
+ var geojson_default = GeojsonImport;
737
+
738
+ // src/ModalImport/index.tsx
739
+ import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
740
+ var DefaultModal = ({ isOpen, onClose, nakshaImport, geoJSONImport }) => {
741
+ if (!isOpen) return null;
742
+ return /* @__PURE__ */ jsx6(
743
+ "div",
744
+ {
745
+ style: {
746
+ position: "fixed",
747
+ top: 0,
748
+ left: 0,
749
+ right: 0,
750
+ bottom: 0,
751
+ backgroundColor: "rgba(0, 0, 0, 0.5)",
752
+ display: "flex",
753
+ alignItems: "center",
754
+ justifyContent: "center",
755
+ zIndex: 99999
756
+ },
757
+ onClick: onClose,
758
+ children: /* @__PURE__ */ jsxs3(
759
+ "div",
760
+ {
761
+ style: {
762
+ background: "#fff",
763
+ borderRadius: "8px",
764
+ padding: "24px",
765
+ maxWidth: "500px",
766
+ width: "90%",
767
+ maxHeight: "85vh",
768
+ overflowY: "auto",
769
+ boxShadow: "0 4px 12px rgba(0,0,0,0.15)",
770
+ position: "relative"
771
+ },
772
+ onClick: (e) => e.stopPropagation(),
773
+ children: [
774
+ /* @__PURE__ */ jsx6(
775
+ "button",
776
+ {
777
+ type: "button",
778
+ onClick: onClose,
779
+ style: {
780
+ position: "absolute",
781
+ top: 12,
782
+ right: 12,
783
+ border: "none",
784
+ background: "none",
785
+ fontSize: "18px",
786
+ cursor: "pointer"
787
+ },
788
+ children: "\u2715"
789
+ }
790
+ ),
791
+ /* @__PURE__ */ jsx6(
792
+ "h3",
793
+ {
794
+ style: { margin: "0 0 16px 0", fontSize: "18px", fontWeight: 600 },
795
+ children: "Import Data"
796
+ }
797
+ ),
798
+ /* @__PURE__ */ jsxs3("div", { style: { marginBottom: "20px" }, children: [
799
+ /* @__PURE__ */ jsx6(
800
+ "h4",
801
+ {
802
+ style: { margin: "0 0 8px 0", fontSize: "14px", fontWeight: 500 },
803
+ children: "Import Coordinates"
804
+ }
805
+ ),
806
+ nakshaImport
807
+ ] }),
808
+ /* @__PURE__ */ jsxs3("div", { children: [
809
+ /* @__PURE__ */ jsx6(
810
+ "h4",
811
+ {
812
+ style: { margin: "0 0 8px 0", fontSize: "14px", fontWeight: 500 },
813
+ children: "Import GeoJSON"
814
+ }
815
+ ),
816
+ geoJSONImport
817
+ ] })
818
+ ]
819
+ }
820
+ )
821
+ }
822
+ );
823
+ };
824
+ function ModalImport({
825
+ ButtonComponent,
826
+ ModalComponent,
827
+ addFeature,
828
+ InputComponent,
829
+ ButtonComponentModal,
830
+ DeleteIcon,
831
+ LocationIcon,
832
+ FileIcon,
833
+ SuccessIcon,
834
+ FailureIcon
835
+ }) {
836
+ const [isModalOpen, setIsModalOpen] = useState6(false);
837
+ const handleModalClose = () => {
838
+ setIsModalOpen(false);
839
+ };
840
+ const handleOpenModal = () => {
841
+ setIsModalOpen(true);
842
+ };
843
+ const nakshaImport = /* @__PURE__ */ jsx6(
844
+ import_default,
845
+ {
846
+ addFeature,
847
+ InputComponent,
848
+ ButtonComponent,
849
+ LocationIcon,
850
+ SuccessIcon,
851
+ FailureIcon
852
+ }
853
+ );
854
+ const geoJSONImport = /* @__PURE__ */ jsx6(
855
+ geojson_default,
856
+ {
857
+ addFeature,
858
+ ButtonComponent,
859
+ DeleteIcon,
860
+ FileIcon,
861
+ SuccessIcon,
862
+ FailureIcon
863
+ }
864
+ );
865
+ return /* @__PURE__ */ jsxs3("div", { style: { display: "flex" }, children: [
866
+ React5.isValidElement(ModalComponent) ? React5.cloneElement(ModalComponent, {
867
+ isOpen: isModalOpen,
868
+ onClose: handleModalClose,
869
+ nakshaImport,
870
+ geoJSONImport
871
+ }) : /* @__PURE__ */ jsx6(
872
+ DefaultModal,
873
+ {
874
+ isOpen: isModalOpen,
875
+ onClose: handleModalClose,
876
+ nakshaImport,
877
+ geoJSONImport
878
+ }
879
+ ),
880
+ React5.isValidElement(ButtonComponentModal) ? React5.cloneElement(ButtonComponentModal, {
881
+ onClick: handleOpenModal,
882
+ type: "button"
883
+ }) : /* @__PURE__ */ jsx6(
884
+ "button",
885
+ {
886
+ type: "button",
887
+ onClick: handleOpenModal,
888
+ style: {
889
+ padding: "6px 16px",
890
+ backgroundColor: "#519895",
891
+ color: "white",
892
+ border: "none",
893
+ borderRadius: "4px",
894
+ cursor: "pointer"
895
+ },
896
+ children: "Import"
897
+ }
898
+ )
899
+ ] });
900
+ }
901
+
902
+ // src/index.tsx
903
+ import { Fragment as Fragment2, jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
904
+ var NakshaGmapsDraw = React6.forwardRef(
905
+ ({
906
+ defaultViewState,
907
+ defaultDrawingMode,
908
+ data,
909
+ onDataChange,
910
+ gmapAccessToken,
911
+ isControlled,
912
+ isReadOnly,
913
+ isMultiple,
914
+ isImport,
915
+ isAutocomplete,
916
+ gmapRegion,
917
+ autoCompleteRegion,
918
+ mapStyle,
919
+ importInputComponent,
920
+ importButtonComponent,
921
+ autocompleteComponent,
922
+ showTrace,
923
+ traceButtonComponent,
924
+ maxZoom,
925
+ options,
926
+ importModalComponent,
927
+ isOpen,
928
+ onClose,
929
+ importButtonComponentModal,
930
+ importDeleteIcon,
931
+ importLocationIcon,
932
+ importFileIcon,
933
+ importSuccessIcon,
934
+ importFailureIcon
935
+ }, ref) => {
936
+ const mapRef = useRef3(null);
937
+ const [features, dispatch] = useReducer(featuresReducer, data);
938
+ const [isLoaded, setIsLoaded] = useState7();
939
+ const viewPort = useMemo(
940
+ () => mapboxToGmapsViewState(defaultViewState),
941
+ [defaultViewState]
942
+ );
943
+ const reloadFeatures = () => {
944
+ mapRef.current.state.map.data.forEach(function(feature) {
945
+ mapRef.current.state.map.data.remove(feature);
946
+ });
947
+ const fullGeoJson = toFullGeoJson(features);
948
+ if (fullGeoJson) {
949
+ fullGeoJson && mapRef.current.state.map.data.addGeoJson(fullGeoJson);
950
+ const bounds = calculateBounds(fullGeoJson);
951
+ bounds && mapRef.current.state.map.fitBounds(bounds);
952
+ if (maxZoom) {
953
+ google.maps.event.addListenerOnce(
954
+ mapRef.current.state.map,
955
+ "idle",
956
+ function() {
957
+ const z = mapRef.current.state.map.getZoom();
958
+ mapRef.current.state.map.setZoom(Math.min(maxZoom, z));
959
+ }
960
+ );
961
+ }
962
+ }
963
+ };
964
+ useEffect3(() => {
965
+ if (isLoaded) {
966
+ onDataChange && onDataChange(features);
967
+ if (ref) {
968
+ ref.current = { addFeature, replaceFeature };
969
+ }
970
+ reloadFeatures();
971
+ }
972
+ }, [isLoaded, features]);
973
+ useEffect3(() => {
974
+ if (isControlled && JSON.stringify(features) !== JSON.stringify(data)) {
975
+ dispatch({
976
+ action: ACTION_TYPES.REPLACE,
977
+ data
978
+ });
979
+ }
980
+ }, [data]);
981
+ const addFeature = (feature) => {
982
+ dispatch({ action: ACTION_TYPES.ADD, data: feature, isMultiple });
983
+ };
984
+ const replaceFeature = (feature) => {
985
+ dispatch({ action: ACTION_TYPES.REPLACE, data: [feature] });
986
+ };
987
+ const onFeatureAdded = (geometry) => {
988
+ const feature = geometryToGeoJsonFeature(geometry);
989
+ addFeature(feature);
990
+ };
991
+ const onClearFeatures = () => {
992
+ dispatch({ action: ACTION_TYPES.CLEAR });
993
+ };
994
+ const onMapLoaded = () => setIsLoaded(true);
995
+ return /* @__PURE__ */ jsx7(
996
+ LoadScriptNext,
997
+ {
998
+ googleMapsApiKey: gmapAccessToken,
999
+ region: gmapRegion,
1000
+ libraries: isAutocomplete ? GMAPS_LIBRARIES.AUTOCOMPLETE : GMAPS_LIBRARIES.DEFAULT,
1001
+ children: /* @__PURE__ */ jsxs4(Fragment2, { children: [
1002
+ /* @__PURE__ */ jsxs4("div", { style: { display: "flex" }, children: [
1003
+ isAutocomplete && /* @__PURE__ */ jsx7("div", { style: { width: "500px" }, children: /* @__PURE__ */ jsx7(
1004
+ NakshaAutocomplete,
1005
+ {
1006
+ InputComponent: autocompleteComponent || /* @__PURE__ */ jsx7("input", {}),
1007
+ addFeature,
1008
+ gmapRegion: autoCompleteRegion ?? gmapRegion
1009
+ }
1010
+ ) }),
1011
+ /* @__PURE__ */ jsx7("div", { style: { flex: "1" } }),
1012
+ isImport && /* @__PURE__ */ jsx7(
1013
+ ModalImport,
1014
+ {
1015
+ ButtonComponent: importButtonComponent || /* @__PURE__ */ jsx7("button", { children: "add" }),
1016
+ ModalComponent: importModalComponent,
1017
+ InputComponent: importInputComponent || /* @__PURE__ */ jsx7("input", {}),
1018
+ addFeature,
1019
+ ButtonComponentModal: importButtonComponentModal || /* @__PURE__ */ jsx7("button", { children: "Import" }),
1020
+ DeleteIcon: importDeleteIcon,
1021
+ LocationIcon: importLocationIcon,
1022
+ FileIcon: importFileIcon,
1023
+ SuccessIcon: importSuccessIcon,
1024
+ FailureIcon: importFailureIcon
1025
+ }
1026
+ )
1027
+ ] }),
1028
+ showTrace && /* @__PURE__ */ jsx7(
1029
+ TraceLocation,
1030
+ {
1031
+ TraceButtonComponent: traceButtonComponent || /* @__PURE__ */ jsx7("button", { children: "trace" }),
1032
+ onFeatureAdded
1033
+ }
1034
+ ),
1035
+ /* @__PURE__ */ jsxs4(
1036
+ GoogleMap,
1037
+ {
1038
+ id: "naksha-gmaps-draw",
1039
+ mapContainerStyle: mapStyle || { height: "100%", width: "100%" },
1040
+ zoom: viewPort.zoom,
1041
+ center: viewPort.center,
1042
+ options: GMAP_OPTIONS,
1043
+ ref: mapRef,
1044
+ onLoad: onMapLoaded,
1045
+ children: [
1046
+ isMultiple && /* @__PURE__ */ jsx7(ClearFeatures, { onClick: onClearFeatures }),
1047
+ !isReadOnly && /* @__PURE__ */ jsx7(
1048
+ Data,
1049
+ {
1050
+ options: {
1051
+ controls: [
1052
+ GMAP_FEATURE_TYPES.POINT,
1053
+ GMAP_FEATURE_TYPES.POLYGON,
1054
+ GMAP_FEATURE_TYPES.LINESTRING
1055
+ ],
1056
+ drawingMode: defaultDrawingMode || GMAP_FEATURE_TYPES.POLYGON,
1057
+ featureFactory: onFeatureAdded,
1058
+ ...options || {}
1059
+ }
1060
+ }
1061
+ )
1062
+ ]
1063
+ }
1064
+ )
1065
+ ] })
1066
+ }
1067
+ );
1068
+ }
1069
+ );
1070
+ export {
1071
+ GMAP_FEATURE_TYPES,
1072
+ NakshaGmapsDraw
1073
+ };