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