@biodiv-platform/naksha-gmaps-view 4.5.1-beta.0 → 4.5.1

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,124 @@
1
- "use strict";var x=Object.create;var c=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,O=Object.prototype.hasOwnProperty;var T=(t,e)=>{for(var o in e)c(t,o,{get:e[o],enumerable:!0})},g=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of N(e))!O.call(t,n)&&n!==o&&c(t,n,{get:()=>e[n],enumerable:!(r=M(e,n))||r.enumerable});return t};var k=(t,e,o)=>(o=t!=null?x(R(t)):{},g(e||!t||!t.__esModule?c(o,"default",{value:t,enumerable:!0}):o,t)),I=t=>g(c({},"__esModule",{value:!0}),t);var v={};T(v,{NakshaGmapsView:()=>V});module.exports=I(v);var m=require("@biodiv-platform/naksha-commons"),u=require("@react-google-maps/api"),s=require("react");var h={mapTypeControlOptions:{position:10}};var G=k(require("@turf/bbox"),1),w=t=>{let e=(0,G.default)(t);return{east:e[2],north:e[3],south:e[1],west:e[0]}};var d=require("react/jsx-runtime");function V({defaultViewState:t,gmapAccessToken:e,gmapRegion:o,features:r,mapStyle:n,maxZoom:f,options:A}){let a=(0,s.useRef)(null),[l]=(0,s.useState)((0,m.mapboxToGmapsViewState)(t)),[S,L]=(0,s.useState)(),P=()=>{a.current.state.map.data.forEach(function(i){a.current.state.map.data.remove(i)});let p=Array.isArray(r)?{type:"FeatureCollection",features:r}:r;if(p){p&&a.current.state.map.data.addGeoJson(p);let i=w(p);i&&a.current.state.map.fitBounds(i),f&&google.maps.event.addListenerOnce(a.current.state.map,"idle",function(){let b=a.current.state.map.getZoom();a.current.state.map.setZoom(Math.min(f,b))})}};(0,s.useEffect)(()=>{S&&P()},[S,r]);let y=()=>L(!0);return(0,d.jsx)(u.LoadScriptNext,{googleMapsApiKey:e,region:o,libraries:m.GMAPS_LIBRARIES.DEFAULT,children:(0,d.jsx)(u.GoogleMap,{id:"naksha-gmaps-view",mapContainerStyle:n||{height:"100%",width:"100%"},zoom:l.zoom,center:l.center,options:{...h,...A||{}},ref:a,onLoad:y})})}0&&(module.exports={NakshaGmapsView});
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
+ NakshaGmapsView: () => NakshaGmapsView
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+ var import_naksha_commons = require("@biodiv-platform/naksha-commons");
37
+ var import_api = require("@react-google-maps/api");
38
+ var import_react = require("react");
39
+
40
+ // src/static/constants.tsx
41
+ var GMAP_OPTIONS = {
42
+ mapTypeControlOptions: {
43
+ position: 10
44
+ }
45
+ };
46
+
47
+ // src/utils/geojson.tsx
48
+ var import_bbox = __toESM(require("@turf/bbox"), 1);
49
+ var calculateBounds = (geojson) => {
50
+ const b = (0, import_bbox.default)(geojson);
51
+ return {
52
+ east: b[2],
53
+ north: b[3],
54
+ south: b[1],
55
+ west: b[0]
56
+ };
57
+ };
58
+
59
+ // src/index.tsx
60
+ var import_jsx_runtime = require("react/jsx-runtime");
61
+ function NakshaGmapsView({
62
+ defaultViewState,
63
+ gmapAccessToken,
64
+ gmapRegion,
65
+ features,
66
+ mapStyle,
67
+ maxZoom,
68
+ options
69
+ }) {
70
+ const mapRef = (0, import_react.useRef)(null);
71
+ const [viewPort] = (0, import_react.useState)((0, import_naksha_commons.mapboxToGmapsViewState)(defaultViewState));
72
+ const [isLoaded, setIsLoaded] = (0, import_react.useState)();
73
+ const reloadFeatures = () => {
74
+ mapRef.current.state.map.data.forEach(function(feature) {
75
+ mapRef.current.state.map.data.remove(feature);
76
+ });
77
+ const fullGeoJson = Array.isArray(features) ? { type: "FeatureCollection", features } : features;
78
+ if (fullGeoJson) {
79
+ fullGeoJson && mapRef.current.state.map.data.addGeoJson(fullGeoJson);
80
+ const bounds = calculateBounds(fullGeoJson);
81
+ bounds && mapRef.current.state.map.fitBounds(bounds);
82
+ if (maxZoom) {
83
+ google.maps.event.addListenerOnce(
84
+ mapRef.current.state.map,
85
+ "idle",
86
+ function() {
87
+ const z = mapRef.current.state.map.getZoom();
88
+ mapRef.current.state.map.setZoom(Math.min(maxZoom, z));
89
+ }
90
+ );
91
+ }
92
+ }
93
+ };
94
+ (0, import_react.useEffect)(() => {
95
+ if (isLoaded) {
96
+ reloadFeatures();
97
+ }
98
+ }, [isLoaded, features]);
99
+ const onMapLoaded = () => setIsLoaded(true);
100
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
101
+ import_api.LoadScriptNext,
102
+ {
103
+ googleMapsApiKey: gmapAccessToken,
104
+ region: gmapRegion,
105
+ libraries: import_naksha_commons.GMAPS_LIBRARIES.DEFAULT,
106
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
107
+ import_api.GoogleMap,
108
+ {
109
+ id: "naksha-gmaps-view",
110
+ mapContainerStyle: mapStyle || { height: "100%", width: "100%" },
111
+ zoom: viewPort.zoom,
112
+ center: viewPort.center,
113
+ options: { ...GMAP_OPTIONS, ...options || {} },
114
+ ref: mapRef,
115
+ onLoad: onMapLoaded
116
+ }
117
+ )
118
+ }
119
+ );
120
+ }
121
+ // Annotate the CommonJS export names for ESM import in node:
122
+ 0 && (module.exports = {
123
+ NakshaGmapsView
124
+ });
package/dist/index.js CHANGED
@@ -1 +1,92 @@
1
- import{GMAPS_LIBRARIES as L,mapboxToGmapsViewState as P}from"@biodiv-platform/naksha-commons";import{GoogleMap as y,LoadScriptNext as b}from"@react-google-maps/api";import{useEffect as x,useRef as M,useState as u}from"react";var c={mapTypeControlOptions:{position:10}};import A from"@turf/bbox";var m=n=>{let e=A(n);return{east:e[2],north:e[3],south:e[1],west:e[0]}};import{jsx as d}from"react/jsx-runtime";function C({defaultViewState:n,gmapAccessToken:e,gmapRegion:f,features:o,mapStyle:l,maxZoom:s,options:S}){let t=M(null),[p]=u(P(n)),[i,g]=u(),h=()=>{t.current.state.map.data.forEach(function(r){t.current.state.map.data.remove(r)});let a=Array.isArray(o)?{type:"FeatureCollection",features:o}:o;if(a){a&&t.current.state.map.data.addGeoJson(a);let r=m(a);r&&t.current.state.map.fitBounds(r),s&&google.maps.event.addListenerOnce(t.current.state.map,"idle",function(){let w=t.current.state.map.getZoom();t.current.state.map.setZoom(Math.min(s,w))})}};x(()=>{i&&h()},[i,o]);let G=()=>g(!0);return d(b,{googleMapsApiKey:e,region:f,libraries:L.DEFAULT,children:d(y,{id:"naksha-gmaps-view",mapContainerStyle:l||{height:"100%",width:"100%"},zoom:p.zoom,center:p.center,options:{...c,...S||{}},ref:t,onLoad:G})})}export{C as NakshaGmapsView};
1
+ // src/index.tsx
2
+ import {
3
+ GMAPS_LIBRARIES,
4
+ mapboxToGmapsViewState
5
+ } from "@biodiv-platform/naksha-commons";
6
+ import { GoogleMap, LoadScriptNext } from "@react-google-maps/api";
7
+ import { useEffect, useRef, useState } from "react";
8
+
9
+ // src/static/constants.tsx
10
+ var GMAP_OPTIONS = {
11
+ mapTypeControlOptions: {
12
+ position: 10
13
+ }
14
+ };
15
+
16
+ // src/utils/geojson.tsx
17
+ import bbox from "@turf/bbox";
18
+ var calculateBounds = (geojson) => {
19
+ const b = bbox(geojson);
20
+ return {
21
+ east: b[2],
22
+ north: b[3],
23
+ south: b[1],
24
+ west: b[0]
25
+ };
26
+ };
27
+
28
+ // src/index.tsx
29
+ import { jsx } from "react/jsx-runtime";
30
+ function NakshaGmapsView({
31
+ defaultViewState,
32
+ gmapAccessToken,
33
+ gmapRegion,
34
+ features,
35
+ mapStyle,
36
+ maxZoom,
37
+ options
38
+ }) {
39
+ const mapRef = useRef(null);
40
+ const [viewPort] = useState(mapboxToGmapsViewState(defaultViewState));
41
+ const [isLoaded, setIsLoaded] = useState();
42
+ const reloadFeatures = () => {
43
+ mapRef.current.state.map.data.forEach(function(feature) {
44
+ mapRef.current.state.map.data.remove(feature);
45
+ });
46
+ const fullGeoJson = Array.isArray(features) ? { type: "FeatureCollection", features } : features;
47
+ if (fullGeoJson) {
48
+ fullGeoJson && mapRef.current.state.map.data.addGeoJson(fullGeoJson);
49
+ const bounds = calculateBounds(fullGeoJson);
50
+ bounds && mapRef.current.state.map.fitBounds(bounds);
51
+ if (maxZoom) {
52
+ google.maps.event.addListenerOnce(
53
+ mapRef.current.state.map,
54
+ "idle",
55
+ function() {
56
+ const z = mapRef.current.state.map.getZoom();
57
+ mapRef.current.state.map.setZoom(Math.min(maxZoom, z));
58
+ }
59
+ );
60
+ }
61
+ }
62
+ };
63
+ useEffect(() => {
64
+ if (isLoaded) {
65
+ reloadFeatures();
66
+ }
67
+ }, [isLoaded, features]);
68
+ const onMapLoaded = () => setIsLoaded(true);
69
+ return /* @__PURE__ */ jsx(
70
+ LoadScriptNext,
71
+ {
72
+ googleMapsApiKey: gmapAccessToken,
73
+ region: gmapRegion,
74
+ libraries: GMAPS_LIBRARIES.DEFAULT,
75
+ children: /* @__PURE__ */ jsx(
76
+ GoogleMap,
77
+ {
78
+ id: "naksha-gmaps-view",
79
+ mapContainerStyle: mapStyle || { height: "100%", width: "100%" },
80
+ zoom: viewPort.zoom,
81
+ center: viewPort.center,
82
+ options: { ...GMAP_OPTIONS, ...options || {} },
83
+ ref: mapRef,
84
+ onLoad: onMapLoaded
85
+ }
86
+ )
87
+ }
88
+ );
89
+ }
90
+ export {
91
+ NakshaGmapsView
92
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biodiv-platform/naksha-gmaps-view",
3
- "version": "4.5.1-beta.0",
3
+ "version": "4.5.1",
4
4
  "type": "module",
5
5
  "author": "harshzalavadiya",
6
6
  "main": "./dist/index.cjs",
@@ -35,12 +35,12 @@
35
35
  "react-map-gl": "^8.1.3",
36
36
  "tsup": "^9.0.0",
37
37
  "typescript": "^5.8.3",
38
- "@biodiv-platform/tsconfig": "4.4.9",
39
- "@biodiv-platform/eslint-preset": "4.4.9"
38
+ "@biodiv-platform/tsconfig": "4.5.0",
39
+ "@biodiv-platform/eslint-preset": "4.5.0"
40
40
  },
41
41
  "dependencies": {
42
42
  "@turf/bbox": "^7.4.0",
43
- "@biodiv-platform/naksha-commons": "5.0.0-beta.3"
43
+ "@biodiv-platform/naksha-commons": "5.0.0"
44
44
  },
45
45
  "publishConfig": {
46
46
  "access": "public"
package/dist/esm/index.js DELETED
@@ -1,100 +0,0 @@
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 { GMAPS_LIBRARIES, mapboxToGmapsViewState } from "@biodiv-platform/naksha-commons";
20
- import { GoogleMap, LoadScriptNext } from "@react-google-maps/api";
21
- import { useEffect, useRef, useState } from "react";
22
-
23
- // src/static/constants.tsx
24
- var GMAP_OPTIONS = {
25
- mapTypeControlOptions: {
26
- position: 10
27
- }
28
- };
29
-
30
- // src/utils/geojson.tsx
31
- import bbox from "@turf/bbox";
32
- var calculateBounds = (geojson) => {
33
- const b = bbox(geojson);
34
- return {
35
- east: b[2],
36
- north: b[3],
37
- south: b[1],
38
- west: b[0]
39
- };
40
- };
41
-
42
- // src/index.tsx
43
- import { jsx } from "react/jsx-runtime";
44
- function NakshaGmapsView({
45
- defaultViewState,
46
- gmapAccessToken,
47
- gmapRegion,
48
- features,
49
- mapStyle,
50
- maxZoom,
51
- options
52
- }) {
53
- const mapRef = useRef(null);
54
- const [viewPort] = useState(mapboxToGmapsViewState(defaultViewState));
55
- const [isLoaded, setIsLoaded] = useState();
56
- const reloadFeatures = () => {
57
- mapRef.current.state.map.data.forEach(function(feature) {
58
- mapRef.current.state.map.data.remove(feature);
59
- });
60
- const fullGeoJson = Array.isArray(features) ? { type: "FeatureCollection", features } : features;
61
- if (fullGeoJson) {
62
- fullGeoJson && mapRef.current.state.map.data.addGeoJson(fullGeoJson);
63
- const bounds = calculateBounds(fullGeoJson);
64
- bounds && mapRef.current.state.map.fitBounds(bounds);
65
- if (maxZoom) {
66
- google.maps.event.addListenerOnce(
67
- mapRef.current.state.map,
68
- "idle",
69
- function() {
70
- const z = mapRef.current.state.map.getZoom();
71
- mapRef.current.state.map.setZoom(Math.min(maxZoom, z));
72
- }
73
- );
74
- }
75
- }
76
- };
77
- useEffect(() => {
78
- if (isLoaded) {
79
- reloadFeatures();
80
- }
81
- }, [isLoaded, features]);
82
- const onMapLoaded = () => setIsLoaded(true);
83
- return /* @__PURE__ */ jsx(LoadScriptNext, {
84
- googleMapsApiKey: gmapAccessToken,
85
- region: gmapRegion,
86
- libraries: GMAPS_LIBRARIES.DEFAULT,
87
- children: /* @__PURE__ */ jsx(GoogleMap, {
88
- id: "naksha-gmaps-view",
89
- mapContainerStyle: mapStyle || { height: "100%", width: "100%" },
90
- zoom: viewPort.zoom,
91
- center: viewPort.center,
92
- options: __spreadValues(__spreadValues({}, GMAP_OPTIONS), options || {}),
93
- ref: mapRef,
94
- onLoad: onMapLoaded
95
- })
96
- });
97
- }
98
- export {
99
- NakshaGmapsView
100
- };