@biodiv-platform/naksha-maplibre-draw 5.0.0 → 5.0.2

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/esm/index.js CHANGED
@@ -1,219 +1 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __spreadValues = (a, b) => {
7
- for (var prop in b || (b = {}))
8
- if (__hasOwnProp.call(b, prop))
9
- __defNormalProp(a, prop, b[prop]);
10
- if (__getOwnPropSymbols)
11
- for (var prop of __getOwnPropSymbols(b)) {
12
- if (__propIsEnum.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- }
15
- return a;
16
- };
17
-
18
- // src/index.tsx
19
- import { MapProvider } from "react-map-gl/maplibre";
20
-
21
- // src/components/map.tsx
22
- import {
23
- defaultMapStyles,
24
- defaultViewState
25
- } from "@biodiv-platform/naksha-commons";
26
- import bbox from "@turf/bbox";
27
- import { useEffect, useState } from "react";
28
- import MapGL, { NavigationControl, useMap } from "react-map-gl/maplibre";
29
-
30
- // src/components/draw-control.tsx
31
- import { MaplibreTerradrawControl } from "@watergis/maplibre-gl-terradraw";
32
- import { emit, useListener } from "react-gbus";
33
- import { useControl } from "react-map-gl/maplibre";
34
-
35
- // src/components/delete-panel.tsx
36
- import { jsx } from "react/jsx-runtime";
37
- function DeletePanel({ onDelete }) {
38
- return /* @__PURE__ */ jsx("div", {
39
- className: "maplibregl-ctrl-top-left",
40
- style: { marginTop: "100px" },
41
- children: /* @__PURE__ */ jsx("div", {
42
- className: "maplibregl-ctrl-group maplibregl-ctrl",
43
- children: /* @__PURE__ */ jsx("button", {
44
- className: "maplibre-gl-draw_ctrl-draw-btn maplibre-gl-draw_trash",
45
- title: "Delete",
46
- onClick: onDelete,
47
- style: {
48
- display: "flex",
49
- justifyContent: "center",
50
- alignItems: "center",
51
- width: "30px",
52
- height: "30px"
53
- },
54
- children: /* @__PURE__ */ jsx("svg", {
55
- width: "16",
56
- height: "16",
57
- viewBox: "0 0 24 24",
58
- fill: "none",
59
- stroke: "currentColor",
60
- strokeWidth: "2",
61
- children: /* @__PURE__ */ jsx("path", {
62
- d: "M3 6h18M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"
63
- })
64
- })
65
- })
66
- })
67
- });
68
- }
69
-
70
- // src/components/draw-control.tsx
71
- import { jsx as jsx2 } from "react/jsx-runtime";
72
- var UPDATE_EVENT = "rmsc-draw-updated";
73
- function DrawControl(props) {
74
- useListener(onUpdate, [UPDATE_EVENT]);
75
- function onUpdate(e) {
76
- var _a;
77
- if (!terradrawControl)
78
- return;
79
- const allFeatures = terradrawControl.getFeatures().features;
80
- const _features = props.isMultiple ? allFeatures : [allFeatures[allFeatures.length - 1]];
81
- (_a = props.setFeatures) == null ? void 0 : _a.call(props, _features);
82
- }
83
- const terradrawControl = useControl(
84
- ({ map }) => {
85
- const ctrl = new MaplibreTerradrawControl({
86
- modes: ["point", "linestring", "polygon"],
87
- open: true
88
- });
89
- map.on("terradraw.create", (e) => {
90
- if (!props.isMultiple) {
91
- ctrl.terradraw.clear();
92
- }
93
- ctrl.getTerraDrawInstance().setMode("select");
94
- emit(UPDATE_EVENT, e);
95
- });
96
- map.on("terradraw.update", (e) => emit(UPDATE_EVENT, e));
97
- map.on("terradraw.delete", (e) => emit(UPDATE_EVENT, e));
98
- return ctrl;
99
- },
100
- () => {
101
- },
102
- { position: "top-left" }
103
- );
104
- const onDelete = () => {
105
- var _a;
106
- terradrawControl.terradraw.clear();
107
- (_a = props.setFeatures) == null ? void 0 : _a.call(props, []);
108
- };
109
- return /* @__PURE__ */ jsx2(DeletePanel, {
110
- onDelete
111
- });
112
- }
113
-
114
- // src/components/geojson-layer.tsx
115
- import { Layer, Source } from "react-map-gl/maplibre";
116
-
117
- // src/static/constants.tsx
118
- var featureStyle = {
119
- id: "data",
120
- type: "fill",
121
- paint: {
122
- "fill-color": "#f03b20",
123
- "fill-opacity": 0.2
124
- },
125
- filter: ["==", ["geometry-type"], "Polygon"]
126
- };
127
- var pointStyle = {
128
- type: "circle",
129
- paint: {
130
- "circle-radius": 8,
131
- "circle-color": "#f03b20",
132
- "circle-opacity": 0.8
133
- },
134
- filter: ["==", ["geometry-type"], "Point"]
135
- };
136
- var lineStyle = {
137
- type: "line",
138
- paint: {
139
- "line-color": "#f03b20",
140
- "line-width": 1.6,
141
- "line-dasharray": [6, 3],
142
- "line-opacity": 0.8
143
- },
144
- filter: ["==", ["geometry-type"], "LineString"]
145
- };
146
-
147
- // src/components/geojson-layer.tsx
148
- import { jsx as jsx3, jsxs } from "react/jsx-runtime";
149
- function GeojsonLayer({ features }) {
150
- if (!(features == null ? void 0 : features.length))
151
- return null;
152
- return /* @__PURE__ */ jsxs(Source, {
153
- type: "geojson",
154
- data: { type: "FeatureCollection", features },
155
- children: [
156
- /* @__PURE__ */ jsx3(Layer, __spreadValues({}, pointStyle)),
157
- /* @__PURE__ */ jsx3(Layer, __spreadValues({}, lineStyle)),
158
- /* @__PURE__ */ jsx3(Layer, __spreadValues({}, featureStyle))
159
- ]
160
- });
161
- }
162
-
163
- // src/components/map.tsx
164
- import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
165
- var NavControl = NavigationControl;
166
- function Map(props) {
167
- const { mapv } = useMap();
168
- const [mapStyle] = useState(defaultMapStyles[(props == null ? void 0 : props.mapStyle) || 0].style);
169
- const [viewState] = useState(props.defaultViewState || defaultViewState);
170
- const [features, setFeatures] = useState(props.features || []);
171
- const autoFocus = () => {
172
- if (!(features == null ? void 0 : features.length) || !mapv)
173
- return;
174
- const _bbox = bbox({ type: "FeatureCollection", features });
175
- mapv.fitBounds(_bbox, { padding: 40, duration: 1e3 });
176
- };
177
- useEffect(() => {
178
- props.onFeaturesChange && props.onFeaturesChange(features);
179
- autoFocus();
180
- }, [features]);
181
- useEffect(() => {
182
- if (props.isControlled && JSON.stringify(features) !== JSON.stringify(props.features)) {
183
- setFeatures(props.features || []);
184
- }
185
- }, [props.features]);
186
- return /* @__PURE__ */ jsxs2(MapGL, {
187
- id: "mapv",
188
- cursor: "default",
189
- initialViewState: viewState,
190
- style: { width: "100%", height: "100%" },
191
- mapStyle,
192
- onLoad: autoFocus,
193
- children: [
194
- /* @__PURE__ */ jsx4(NavControl, {
195
- position: "bottom-right",
196
- showZoom: true,
197
- showCompass: true
198
- }),
199
- /* @__PURE__ */ jsx4(DrawControl, {
200
- features,
201
- setFeatures,
202
- isControlled: props.isControlled,
203
- isMultiple: props.isMultiple
204
- }),
205
- /* @__PURE__ */ jsx4(GeojsonLayer, {
206
- features
207
- })
208
- ]
209
- });
210
- }
211
-
212
- // src/index.tsx
213
- import { jsx as jsx5 } from "react/jsx-runtime";
214
- var NakshaMaplibreDraw = (props) => /* @__PURE__ */ jsx5(MapProvider, {
215
- children: /* @__PURE__ */ jsx5(Map, __spreadValues({}, props))
216
- });
217
- export {
218
- NakshaMaplibreDraw
219
- };
1
+ var ne=Object.defineProperty,ae=Object.defineProperties;var ie=Object.getOwnPropertyDescriptors;var J=Object.getOwnPropertySymbols;var se=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable;var O=(e,t,r)=>t in e?ne(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,b=(e,t)=>{for(var r in t||(t={}))se.call(t,r)&&O(e,r,t[r]);if(J)for(var r of J(t))le.call(t,r)&&O(e,r,t[r]);return e},D=(e,t)=>ae(e,ie(t));import Y from"maplibre-gl";import{TerraDraw as ue,TerraDrawSelectMode as de,TerraDrawPointMode as ce,TerraDrawLineStringMode as pe,TerraDrawPolygonMode as ge,TerraDrawCircleMode as me,TerraDrawFreehandMode as fe,ValidateNotSelfIntersecting as F,TerraDrawRectangleMode as he}from"terra-draw";import{TerraDrawMapLibreGLAdapter as we}from"terra-draw-maplibre-gl-adapter";function V(e){return new ue({tracked:!0,adapter:new we({map:e,coordinatePrecision:9}),modes:[new de({flags:{polygon:{feature:{scaleable:!0,rotateable:!0,draggable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},linestring:{feature:{draggable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},circle:{feature:{draggable:!0}},point:{feature:{draggable:!0}},rectangle:{feature:{draggable:!0,coordinates:{resizable:"opposite"}}},freehand:{feature:{draggable:!0}}}}),new ce,new pe({validation:(t,{updateType:r})=>r==="finish"||r==="commit"?F(t):{valid:!0}}),new he,new ge({pointerDistance:30,validation:(t,{updateType:r})=>r==="finish"||r==="commit"?F(t):{valid:!0}}),new me,new fe({pointerDistance:5,validation:t=>F(t)})]})}import{useRef as ye,useState as m,useEffect as X,useCallback as P}from"react";import L from"maplibre-gl";function z({containerId:e,latitude:t=0,longitude:r=0,zoom:d,pitch:i,bearing:c,mapstyle:N}){return L.getRTLTextPluginStatus()==="unavailable"&&L.setRTLTextPlugin("https://unpkg.com/@mapbox/mapbox-gl-rtl-text@0.2.3/mapbox-gl-rtl-text.min.js",!0),new L.Map({container:e,style:N,center:{lat:t,lng:r},zoom:d,pitch:i,bearing:c})}import{jsx as l,jsxs as q}from"react/jsx-runtime";var E=()=>q("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[l("path",{d:"M12.586 12.586 19 19"}),l("path",{d:"M3.688 3.037a.497.497 0 0 0-.651.651l6.5 15.999a.501.501 0 0 0 .947-.062l1.569-6.083a2 2 0 0 1 1.448-1.479l6.124-1.579a.5.5 0 0 0 .063-.947z"})]}),W=()=>q("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[l("path",{d:"M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0"}),l("circle",{cx:"12",cy:"10",r:"3"})]}),A=()=>l("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:l("line",{x1:"4",y1:"20",x2:"20",y2:"4"})}),H=()=>l("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:l("polygon",{points:"12,2 22,8 18,22 6,22 2,8"})}),Z=()=>l("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:l("path",{d:"M3 6h18M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})});import{jsx as K}from"react/jsx-runtime";var be=({draw:e})=>e?K("button",{onClick:()=>e.clear(),title:"Delete",style:{display:"flex",justifyContent:"center",alignItems:"center",width:"30px",height:"30px",padding:"0",borderRadius:"4px",backgroundColor:"#f0f0f0",cursor:"pointer"},children:K(Z,{})}):null,Q=be;import{jsx as xe}from"react/jsx-runtime";var Me=({mode:e,currentMode:t,changeMode:r,icon:d,tooltip:i})=>xe("button",{onClick:()=>r(e),title:i,style:{display:"flex",justifyContent:"center",alignItems:"center",width:"30px",height:"30px",padding:"0",borderRadius:"4px",backgroundColor:t===e?"#02cf87":"#f0f0f0",cursor:"pointer"},children:d}),M=Me;import{jsx as u,jsxs as ve}from"react/jsx-runtime";var Se=({mode:e,changeMode:t,draw:r})=>ve("div",{style:{position:"absolute",top:"10px",left:"10px",display:"flex",flexDirection:"column",gap:"6px",zIndex:1e3,backgroundColor:"rgba(255, 255, 255, 0.9)",padding:"8px",borderRadius:"6px",boxShadow:"0 2px 6px rgba(0,0,0,0.2)"},children:[u(M,{mode:"select",icon:u(E,{}),currentMode:e,changeMode:t,tooltip:"Select"}),u(M,{mode:"point",icon:u(W,{}),currentMode:e,changeMode:t,tooltip:"Point"}),u(M,{mode:"linestring",icon:u(A,{}),currentMode:e,changeMode:t,tooltip:"Line"}),u(M,{mode:"polygon",icon:u(H,{}),currentMode:e,changeMode:t,tooltip:"Polygon"}),r&&u(Q,{draw:r})]}),U=Se;import{defaultMapStyles as ke}from"@biodiv-platform/naksha-commons";import{Fragment as Pe,jsx as T,jsxs as Te}from"react/jsx-runtime";var Ce=e=>e.map(t=>{var i,c;if((i=t.properties)!=null&&i.mode)return t;let r=(c=t.geometry)==null?void 0:c.type,d=r==="Point"?"point":r==="Polygon"?"polygon":r==="LineString"?"linestring":"unknown";return D(b({},t),{properties:D(b({},t.properties),{mode:d})})}),De=e=>{if(!e.length)return null;let t=new Y.LngLatBounds;return e.forEach(r=>{Fe(r).forEach(i=>{Array.isArray(i[0])?i.forEach(c=>t.extend(c)):t.extend(i)})}),t},Fe=e=>{let t=e.geometry;switch(t.type){case"Point":return[t.coordinates];case"LineString":return[t.coordinates];case"Polygon":return t.coordinates;default:return[]}},Le=e=>{let t=ye(null),[r,d]=m(),[i,c]=m("static"),[N,$]=m(),[Ie,I]=m([]),[p,j]=m(),ee=ke[(e==null?void 0:e.mapStyle)||0].style,{isMultiple:x=!0,isControlled:S=!1,setFeatures:v}=e,[te,re]=m([]),y=P(o=>{S&&v?v(o):re(o)},[S,v]),Be=S?e.features||[]:te,k=P(o=>{if(!r||o.length===0)return;let s=De(o);s&&!s.isEmpty()&&r.fitBounds(s,{padding:50,duration:1e3,maxZoom:5})},[r]);X(()=>{var f,a,n,h,C,w,g,B,R,G;let o=z({containerId:"maplibre-map",latitude:(a=(f=e.defaultViewState)==null?void 0:f.latitude)!=null?a:0,longitude:(h=(n=e.defaultViewState)==null?void 0:n.longitude)!=null?h:0,zoom:(w=(C=e.defaultViewState)==null?void 0:C.zoom)!=null?w:0,pitch:(B=(g=e.defaultViewState)==null?void 0:g.pitch)!=null?B:0,bearing:(G=(R=e.defaultViewState)==null?void 0:R.bearing)!=null?G:0,mapstyle:ee}),s=new Y.NavigationControl({showCompass:!0,showZoom:!0,visualizePitch:!0});return o.addControl(s,"bottom-right"),o.once("style.load",()=>d(o)),()=>{s&&o&&o.removeControl(s)}},[]),X(()=>{var f;if(!r)return;let o=V(r);o.start(),j(o);let s=()=>{let a=o.getSnapshot(),n=a;if(!x&&a.length>1){n=[a[a.length-1]];let w=a.slice(0,-1).map(g=>g.id).filter(g=>g!==void 0);w.length>0&&o.removeFeatures(w)}I(n),y(n),$(n.find(h=>h.properties.selected)),n.length>0&&k(n)};return o.on("change",s),(f=e.features)!=null&&f.length&&setTimeout(()=>{if(o.getSnapshot().length===0){let a=Ce(e.features),n=a;!x&&a.length>1&&(n=[a[a.length-1]]),o.addFeatures(n),I(n),y(n),k(n)}},300),()=>{o.off("change",s),o.stop()}},[r,x,y,k]);let oe=P(o=>{p==null||p.setMode(o),c(o)},[p]);return Te("div",{children:[T("div",{ref:t,id:"maplibre-map",style:{width:"100%",height:"100vh"}}),p&&T(Pe,{children:T(U,{mode:i,changeMode:oe,draw:p})})]})},_=Le;import{jsx as Ne}from"react/jsx-runtime";var ut=e=>Ne(_,b({},e));export{ut as NakshaMaplibreDraw};
package/dist/index.js CHANGED
@@ -1,244 +1 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
- var __spreadValues = (a, b) => {
12
- for (var prop in b || (b = {}))
13
- if (__hasOwnProp.call(b, prop))
14
- __defNormalProp(a, prop, b[prop]);
15
- if (__getOwnPropSymbols)
16
- for (var prop of __getOwnPropSymbols(b)) {
17
- if (__propIsEnum.call(b, prop))
18
- __defNormalProp(a, prop, b[prop]);
19
- }
20
- return a;
21
- };
22
- var __export = (target, all) => {
23
- for (var name in all)
24
- __defProp(target, name, { get: all[name], enumerable: true });
25
- };
26
- var __copyProps = (to, from, except, desc) => {
27
- if (from && typeof from === "object" || typeof from === "function") {
28
- for (let key of __getOwnPropNames(from))
29
- if (!__hasOwnProp.call(to, key) && key !== except)
30
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
31
- }
32
- return to;
33
- };
34
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
35
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
36
- mod
37
- ));
38
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
39
-
40
- // src/index.tsx
41
- var src_exports = {};
42
- __export(src_exports, {
43
- NakshaMaplibreDraw: () => NakshaMaplibreDraw
44
- });
45
- module.exports = __toCommonJS(src_exports);
46
- var import_maplibre4 = require("react-map-gl/maplibre");
47
-
48
- // src/components/map.tsx
49
- var import_naksha_commons = require("@biodiv-platform/naksha-commons");
50
- var import_bbox = __toESM(require("@turf/bbox"));
51
- var import_react = require("react");
52
- var import_maplibre3 = __toESM(require("react-map-gl/maplibre"));
53
-
54
- // src/components/draw-control.tsx
55
- var import_maplibre_gl_terradraw = require("@watergis/maplibre-gl-terradraw");
56
- var import_react_gbus = require("react-gbus");
57
- var import_maplibre = require("react-map-gl/maplibre");
58
-
59
- // src/components/delete-panel.tsx
60
- var import_jsx_runtime = require("react/jsx-runtime");
61
- function DeletePanel({ onDelete }) {
62
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
63
- className: "maplibregl-ctrl-top-left",
64
- style: { marginTop: "100px" },
65
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
66
- className: "maplibregl-ctrl-group maplibregl-ctrl",
67
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
68
- className: "maplibre-gl-draw_ctrl-draw-btn maplibre-gl-draw_trash",
69
- title: "Delete",
70
- onClick: onDelete,
71
- style: {
72
- display: "flex",
73
- justifyContent: "center",
74
- alignItems: "center",
75
- width: "30px",
76
- height: "30px"
77
- },
78
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", {
79
- width: "16",
80
- height: "16",
81
- viewBox: "0 0 24 24",
82
- fill: "none",
83
- stroke: "currentColor",
84
- strokeWidth: "2",
85
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", {
86
- d: "M3 6h18M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"
87
- })
88
- })
89
- })
90
- })
91
- });
92
- }
93
-
94
- // src/components/draw-control.tsx
95
- var import_jsx_runtime2 = require("react/jsx-runtime");
96
- var UPDATE_EVENT = "rmsc-draw-updated";
97
- function DrawControl(props) {
98
- (0, import_react_gbus.useListener)(onUpdate, [UPDATE_EVENT]);
99
- function onUpdate(e) {
100
- var _a;
101
- if (!terradrawControl)
102
- return;
103
- const allFeatures = terradrawControl.getFeatures().features;
104
- const _features = props.isMultiple ? allFeatures : [allFeatures[allFeatures.length - 1]];
105
- (_a = props.setFeatures) == null ? void 0 : _a.call(props, _features);
106
- }
107
- const terradrawControl = (0, import_maplibre.useControl)(
108
- ({ map }) => {
109
- const ctrl = new import_maplibre_gl_terradraw.MaplibreTerradrawControl({
110
- modes: ["point", "linestring", "polygon"],
111
- open: true
112
- });
113
- map.on("terradraw.create", (e) => {
114
- if (!props.isMultiple) {
115
- ctrl.terradraw.clear();
116
- }
117
- ctrl.getTerraDrawInstance().setMode("select");
118
- (0, import_react_gbus.emit)(UPDATE_EVENT, e);
119
- });
120
- map.on("terradraw.update", (e) => (0, import_react_gbus.emit)(UPDATE_EVENT, e));
121
- map.on("terradraw.delete", (e) => (0, import_react_gbus.emit)(UPDATE_EVENT, e));
122
- return ctrl;
123
- },
124
- () => {
125
- },
126
- { position: "top-left" }
127
- );
128
- const onDelete = () => {
129
- var _a;
130
- terradrawControl.terradraw.clear();
131
- (_a = props.setFeatures) == null ? void 0 : _a.call(props, []);
132
- };
133
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(DeletePanel, {
134
- onDelete
135
- });
136
- }
137
-
138
- // src/components/geojson-layer.tsx
139
- var import_maplibre2 = require("react-map-gl/maplibre");
140
-
141
- // src/static/constants.tsx
142
- var featureStyle = {
143
- id: "data",
144
- type: "fill",
145
- paint: {
146
- "fill-color": "#f03b20",
147
- "fill-opacity": 0.2
148
- },
149
- filter: ["==", ["geometry-type"], "Polygon"]
150
- };
151
- var pointStyle = {
152
- type: "circle",
153
- paint: {
154
- "circle-radius": 8,
155
- "circle-color": "#f03b20",
156
- "circle-opacity": 0.8
157
- },
158
- filter: ["==", ["geometry-type"], "Point"]
159
- };
160
- var lineStyle = {
161
- type: "line",
162
- paint: {
163
- "line-color": "#f03b20",
164
- "line-width": 1.6,
165
- "line-dasharray": [6, 3],
166
- "line-opacity": 0.8
167
- },
168
- filter: ["==", ["geometry-type"], "LineString"]
169
- };
170
-
171
- // src/components/geojson-layer.tsx
172
- var import_jsx_runtime3 = require("react/jsx-runtime");
173
- function GeojsonLayer({ features }) {
174
- if (!(features == null ? void 0 : features.length))
175
- return null;
176
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_maplibre2.Source, {
177
- type: "geojson",
178
- data: { type: "FeatureCollection", features },
179
- children: [
180
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_maplibre2.Layer, __spreadValues({}, pointStyle)),
181
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_maplibre2.Layer, __spreadValues({}, lineStyle)),
182
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_maplibre2.Layer, __spreadValues({}, featureStyle))
183
- ]
184
- });
185
- }
186
-
187
- // src/components/map.tsx
188
- var import_jsx_runtime4 = require("react/jsx-runtime");
189
- var NavControl = import_maplibre3.NavigationControl;
190
- function Map(props) {
191
- const { mapv } = (0, import_maplibre3.useMap)();
192
- const [mapStyle] = (0, import_react.useState)(import_naksha_commons.defaultMapStyles[(props == null ? void 0 : props.mapStyle) || 0].style);
193
- const [viewState] = (0, import_react.useState)(props.defaultViewState || import_naksha_commons.defaultViewState);
194
- const [features, setFeatures] = (0, import_react.useState)(props.features || []);
195
- const autoFocus = () => {
196
- if (!(features == null ? void 0 : features.length) || !mapv)
197
- return;
198
- const _bbox = (0, import_bbox.default)({ type: "FeatureCollection", features });
199
- mapv.fitBounds(_bbox, { padding: 40, duration: 1e3 });
200
- };
201
- (0, import_react.useEffect)(() => {
202
- props.onFeaturesChange && props.onFeaturesChange(features);
203
- autoFocus();
204
- }, [features]);
205
- (0, import_react.useEffect)(() => {
206
- if (props.isControlled && JSON.stringify(features) !== JSON.stringify(props.features)) {
207
- setFeatures(props.features || []);
208
- }
209
- }, [props.features]);
210
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_maplibre3.default, {
211
- id: "mapv",
212
- cursor: "default",
213
- initialViewState: viewState,
214
- style: { width: "100%", height: "100%" },
215
- mapStyle,
216
- onLoad: autoFocus,
217
- children: [
218
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(NavControl, {
219
- position: "bottom-right",
220
- showZoom: true,
221
- showCompass: true
222
- }),
223
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(DrawControl, {
224
- features,
225
- setFeatures,
226
- isControlled: props.isControlled,
227
- isMultiple: props.isMultiple
228
- }),
229
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(GeojsonLayer, {
230
- features
231
- })
232
- ]
233
- });
234
- }
235
-
236
- // src/index.tsx
237
- var import_jsx_runtime5 = require("react/jsx-runtime");
238
- var NakshaMaplibreDraw = (props) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_maplibre4.MapProvider, {
239
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Map, __spreadValues({}, props))
240
- });
241
- // Annotate the CommonJS export names for ESM import in node:
242
- 0 && (module.exports = {
243
- NakshaMaplibreDraw
244
- });
1
+ "use strict";var ue=Object.create;var x=Object.defineProperty,de=Object.defineProperties,ce=Object.getOwnPropertyDescriptor,pe=Object.getOwnPropertyDescriptors,ge=Object.getOwnPropertyNames,V=Object.getOwnPropertySymbols,me=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty,fe=Object.prototype.propertyIsEnumerable;var z=(e,t,r)=>t in e?x(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,S=(e,t)=>{for(var r in t||(t={}))E.call(t,r)&&z(e,r,t[r]);if(V)for(var r of V(t))fe.call(t,r)&&z(e,r,t[r]);return e},T=(e,t)=>de(e,pe(t));var he=(e,t)=>{for(var r in t)x(e,r,{get:t[r],enumerable:!0})},W=(e,t,r,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of ge(t))!E.call(e,a)&&a!==r&&x(e,a,{get:()=>t[a],enumerable:!(c=ce(t,a))||c.enumerable});return e};var A=(e,t,r)=>(r=e!=null?ue(me(e)):{},W(t||!e||!e.__esModule?x(r,"default",{value:e,enumerable:!0}):r,e)),we=e=>W(x({},"__esModule",{value:!0}),e);var De={};he(De,{NakshaMaplibreDraw:()=>Ce});module.exports=we(De);var I=A(require("maplibre-gl"));var n=require("terra-draw"),H=require("terra-draw-maplibre-gl-adapter");function Z(e){return new n.TerraDraw({tracked:!0,adapter:new H.TerraDrawMapLibreGLAdapter({map:e,coordinatePrecision:9}),modes:[new n.TerraDrawSelectMode({flags:{polygon:{feature:{scaleable:!0,rotateable:!0,draggable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},linestring:{feature:{draggable:!0,coordinates:{midpoints:!0,draggable:!0,deletable:!0}}},circle:{feature:{draggable:!0}},point:{feature:{draggable:!0}},rectangle:{feature:{draggable:!0,coordinates:{resizable:"opposite"}}},freehand:{feature:{draggable:!0}}}}),new n.TerraDrawPointMode,new n.TerraDrawLineStringMode({validation:(t,{updateType:r})=>r==="finish"||r==="commit"?(0,n.ValidateNotSelfIntersecting)(t):{valid:!0}}),new n.TerraDrawRectangleMode,new n.TerraDrawPolygonMode({pointerDistance:30,validation:(t,{updateType:r})=>r==="finish"||r==="commit"?(0,n.ValidateNotSelfIntersecting)(t):{valid:!0}}),new n.TerraDrawCircleMode,new n.TerraDrawFreehandMode({pointerDistance:5,validation:t=>(0,n.ValidateNotSelfIntersecting)(t)})]})}var i=require("react");var y=A(require("maplibre-gl"));function q({containerId:e,latitude:t=0,longitude:r=0,zoom:c,pitch:a,bearing:g,mapstyle:B}){return y.default.getRTLTextPluginStatus()==="unavailable"&&y.default.setRTLTextPlugin("https://unpkg.com/@mapbox/mapbox-gl-rtl-text@0.2.3/mapbox-gl-rtl-text.min.js",!0),new y.default.Map({container:e,style:B,center:{lat:t,lng:r},zoom:c,pitch:a,bearing:g})}var l=require("react/jsx-runtime"),K=()=>(0,l.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,l.jsx)("path",{d:"M12.586 12.586 19 19"}),(0,l.jsx)("path",{d:"M3.688 3.037a.497.497 0 0 0-.651.651l6.5 15.999a.501.501 0 0 0 .947-.062l1.569-6.083a2 2 0 0 1 1.448-1.479l6.124-1.579a.5.5 0 0 0 .063-.947z"})]}),Q=()=>(0,l.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,l.jsx)("path",{d:"M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0"}),(0,l.jsx)("circle",{cx:"12",cy:"10",r:"3"})]}),U=()=>(0,l.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,l.jsx)("line",{x1:"4",y1:"20",x2:"20",y2:"4"})}),X=()=>(0,l.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,l.jsx)("polygon",{points:"12,2 22,8 18,22 6,22 2,8"})}),Y=()=>(0,l.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,l.jsx)("path",{d:"M3 6h18M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})});var N=require("react/jsx-runtime"),be=({draw:e})=>e?(0,N.jsx)("button",{onClick:()=>e.clear(),title:"Delete",style:{display:"flex",justifyContent:"center",alignItems:"center",width:"30px",height:"30px",padding:"0",borderRadius:"4px",backgroundColor:"#f0f0f0",cursor:"pointer"},children:(0,N.jsx)(Y,{})}):null,_=be;var $=require("react/jsx-runtime"),Me=({mode:e,currentMode:t,changeMode:r,icon:c,tooltip:a})=>(0,$.jsx)("button",{onClick:()=>r(e),title:a,style:{display:"flex",justifyContent:"center",alignItems:"center",width:"30px",height:"30px",padding:"0",borderRadius:"4px",backgroundColor:t===e?"#02cf87":"#f0f0f0",cursor:"pointer"},children:c}),v=Me;var d=require("react/jsx-runtime"),xe=({mode:e,changeMode:t,draw:r})=>(0,d.jsxs)("div",{style:{position:"absolute",top:"10px",left:"10px",display:"flex",flexDirection:"column",gap:"6px",zIndex:1e3,backgroundColor:"rgba(255, 255, 255, 0.9)",padding:"8px",borderRadius:"6px",boxShadow:"0 2px 6px rgba(0,0,0,0.2)"},children:[(0,d.jsx)(v,{mode:"select",icon:(0,d.jsx)(K,{}),currentMode:e,changeMode:t,tooltip:"Select"}),(0,d.jsx)(v,{mode:"point",icon:(0,d.jsx)(Q,{}),currentMode:e,changeMode:t,tooltip:"Point"}),(0,d.jsx)(v,{mode:"linestring",icon:(0,d.jsx)(U,{}),currentMode:e,changeMode:t,tooltip:"Line"}),(0,d.jsx)(v,{mode:"polygon",icon:(0,d.jsx)(X,{}),currentMode:e,changeMode:t,tooltip:"Polygon"}),r&&(0,d.jsx)(_,{draw:r})]}),j=xe;var ee=require("@biodiv-platform/naksha-commons");var m=require("react/jsx-runtime"),Se=e=>e.map(t=>{var a,g;if((a=t.properties)!=null&&a.mode)return t;let r=(g=t.geometry)==null?void 0:g.type,c=r==="Point"?"point":r==="Polygon"?"polygon":r==="LineString"?"linestring":"unknown";return T(S({},t),{properties:T(S({},t.properties),{mode:c})})}),ve=e=>{if(!e.length)return null;let t=new I.default.LngLatBounds;return e.forEach(r=>{ye(r).forEach(a=>{Array.isArray(a[0])?a.forEach(g=>t.extend(g)):t.extend(a)})}),t},ye=e=>{let t=e.geometry;switch(t.type){case"Point":return[t.coordinates];case"LineString":return[t.coordinates];case"Polygon":return t.coordinates;default:return[]}},ke=e=>{let t=(0,i.useRef)(null),[r,c]=(0,i.useState)(),[a,g]=(0,i.useState)("static"),[B,oe]=(0,i.useState)(),[Fe,R]=(0,i.useState)([]),[f,ne]=(0,i.useState)(),ae=ee.defaultMapStyles[(e==null?void 0:e.mapStyle)||0].style,{isMultiple:k=!0,isControlled:C=!1,setFeatures:D}=e,[ie,se]=(0,i.useState)([]),F=(0,i.useCallback)(o=>{C&&D?D(o):se(o)},[C,D]),Le=C?e.features||[]:ie,L=(0,i.useCallback)(o=>{if(!r||o.length===0)return;let p=ve(o);p&&!p.isEmpty()&&r.fitBounds(p,{padding:50,duration:1e3,maxZoom:5})},[r]);(0,i.useEffect)(()=>{var w,u,s,b,P,M,h,G,J,O;let o=q({containerId:"maplibre-map",latitude:(u=(w=e.defaultViewState)==null?void 0:w.latitude)!=null?u:0,longitude:(b=(s=e.defaultViewState)==null?void 0:s.longitude)!=null?b:0,zoom:(M=(P=e.defaultViewState)==null?void 0:P.zoom)!=null?M:0,pitch:(G=(h=e.defaultViewState)==null?void 0:h.pitch)!=null?G:0,bearing:(O=(J=e.defaultViewState)==null?void 0:J.bearing)!=null?O:0,mapstyle:ae}),p=new I.default.NavigationControl({showCompass:!0,showZoom:!0,visualizePitch:!0});return o.addControl(p,"bottom-right"),o.once("style.load",()=>c(o)),()=>{p&&o&&o.removeControl(p)}},[]),(0,i.useEffect)(()=>{var w;if(!r)return;let o=Z(r);o.start(),ne(o);let p=()=>{let u=o.getSnapshot(),s=u;if(!k&&u.length>1){s=[u[u.length-1]];let M=u.slice(0,-1).map(h=>h.id).filter(h=>h!==void 0);M.length>0&&o.removeFeatures(M)}R(s),F(s),oe(s.find(b=>b.properties.selected)),s.length>0&&L(s)};return o.on("change",p),(w=e.features)!=null&&w.length&&setTimeout(()=>{if(o.getSnapshot().length===0){let u=Se(e.features),s=u;!k&&u.length>1&&(s=[u[u.length-1]]),o.addFeatures(s),R(s),F(s),L(s)}},300),()=>{o.off("change",p),o.stop()}},[r,k,F,L]);let le=(0,i.useCallback)(o=>{f==null||f.setMode(o),g(o)},[f]);return(0,m.jsxs)("div",{children:[(0,m.jsx)("div",{ref:t,id:"maplibre-map",style:{width:"100%",height:"100vh"}}),f&&(0,m.jsx)(m.Fragment,{children:(0,m.jsx)(j,{mode:a,changeMode:le,draw:f})})]})},te=ke;var re=require("react/jsx-runtime"),Ce=e=>(0,re.jsx)(te,S({},e));0&&(module.exports={NakshaMaplibreDraw});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biodiv-platform/naksha-maplibre-draw",
3
- "version": "5.0.0",
3
+ "version": "5.0.2",
4
4
  "author": "harshzalavadiya",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -20,7 +20,8 @@
20
20
  "peerDependencies": {
21
21
  "maplibre-gl": "^5.7.0",
22
22
  "react": ">=18",
23
- "react-map-gl": "^8.0.4"
23
+ "react-map-gl": "^8.0.4",
24
+ "react-icons": "^5.5.0"
24
25
  },
25
26
  "devDependencies": {
26
27
  "@biodiv-platform/eslint-preset": "*",
@@ -31,13 +32,15 @@
31
32
  "react": ">=18",
32
33
  "react-map-gl": "^8.0.4",
33
34
  "tsup": "^6.1.2",
34
- "typescript": "^4.7.3"
35
+ "typescript": "^4.7.3",
36
+ "react-icons": "^5.5.0"
35
37
  },
36
38
  "dependencies": {
37
- "@biodiv-platform/naksha-commons": "*",
39
+ "@biodiv-platform/naksha-commons": "5.0.0-beta.1",
38
40
  "@turf/bbox": "^6.5.0",
39
- "@watergis/maplibre-gl-terradraw": "^1.7.2",
40
41
  "boundingbox": "^1.4.0",
41
- "react-gbus": "^1.1.2"
42
+ "react-gbus": "^1.1.2",
43
+ "terra-draw": "^1.13.0",
44
+ "terra-draw-maplibre-gl-adapter": "^1.1.2"
42
45
  }
43
46
  }