@biodiv-platform/naksha-maplibre-layers 5.0.1 → 5.0.3

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
@@ -482,13 +482,14 @@ var LayersContext = createContext(
482
482
  {}
483
483
  );
484
484
  var LayersProvider = ({ mp: _mp, children }) => {
485
+ var _a, _b;
485
486
  const [mp, setMP] = useState(_mp);
486
487
  const { mapl } = useMap();
487
488
  const [queryTerm, setQueryTerm] = useState("");
488
489
  const queryTermDebounced = useDebounce(queryTerm, 500);
489
- const [mapStyle, setMapStyle] = useState(
490
- defaultMapStyles[(mp == null ? void 0 : mp.mapStyle) || 0].style
491
- );
490
+ const styles = mp.mapStyles && mp.mapStyles.length > 0 ? mp.mapStyles : defaultMapStyles;
491
+ const [mapStyle, setMapStyle] = useState((_a = styles[(mp == null ? void 0 : mp.mapStyle) || 0]) == null ? void 0 : _a.style);
492
+ const [maxZoom, setMaxZoom] = useState((_b = styles[(mp == null ? void 0 : mp.mapStyle) || 0]) == null ? void 0 : _b.maxZoom);
492
493
  const [selectionStyle, setSelectionStyle] = useState(
493
494
  SELECTION_STYLE.TOP
494
495
  );
@@ -502,12 +503,12 @@ var LayersProvider = ({ mp: _mp, children }) => {
502
503
  const [hoverFeatures, setHoverFeatures] = useState();
503
504
  const [selectedFeatures, setSelectedFeatures] = useState();
504
505
  const selectedFeaturesId = useMemo(() => {
505
- var _a;
506
+ var _a2;
506
507
  const meta = {};
507
508
  for (const qr of selectedFeatures || []) {
508
509
  meta[qr.sourceLayer] = [
509
510
  ...meta[qr.sourceLayer] || [],
510
- (_a = qr == null ? void 0 : qr.properties) == null ? void 0 : _a[PROPERTY_ID]
511
+ (_a2 = qr == null ? void 0 : qr.properties) == null ? void 0 : _a2[PROPERTY_ID]
511
512
  ];
512
513
  }
513
514
  return Object.keys(meta).length ? meta : void 0;
@@ -549,7 +550,7 @@ var LayersProvider = ({ mp: _mp, children }) => {
549
550
  toggleVectorLayer(layerIndex, styleIndex, false);
550
551
  });
551
552
  const onMapHover = (e) => __async(void 0, null, function* () {
552
- var _a, _b, _c, _d;
553
+ var _a2, _b2, _c, _d;
553
554
  if (!selectedLayerIds.length || !mapl)
554
555
  return;
555
556
  try {
@@ -558,14 +559,14 @@ var LayersProvider = ({ mp: _mp, children }) => {
558
559
  layers: [lastLayerId]
559
560
  });
560
561
  if (feats.length) {
561
- const fId = ((_a = feats[0]) == null ? void 0 : _a.id) || ((_c = (_b = feats[0]) == null ? void 0 : _b.properties) == null ? void 0 : _c[PROPERTY_ID]);
562
+ const fId = ((_a2 = feats[0]) == null ? void 0 : _a2.id) || ((_c = (_b2 = feats[0]) == null ? void 0 : _b2.properties) == null ? void 0 : _c[PROPERTY_ID]);
562
563
  if (fId === (hoverFeatures == null ? void 0 : hoverFeatures.id))
563
564
  return;
564
565
  const layer = layers[getLayerIndexById(lastLayerId)];
565
566
  const hoverProperties = (_d = layer == null ? void 0 : layer.data) == null ? void 0 : _d.summaryColumn.map((sc) => {
566
- var _a2, _b2, _c2;
567
+ var _a3, _b3, _c2;
567
568
  return [
568
- ((_b2 = (_a2 = layer.data) == null ? void 0 : _a2.propertyMap) == null ? void 0 : _b2[sc]) || sc,
569
+ ((_b3 = (_a3 = layer.data) == null ? void 0 : _a3.propertyMap) == null ? void 0 : _b3[sc]) || sc,
569
570
  (_c2 = feats[0].properties) == null ? void 0 : _c2[sc]
570
571
  ];
571
572
  });
@@ -586,7 +587,7 @@ var LayersProvider = ({ mp: _mp, children }) => {
586
587
  styleIndex = 0,
587
588
  focus = true
588
589
  }) {
589
- var _a;
590
+ var _a2;
590
591
  if (!add) {
591
592
  setSelectedLayerIds(
592
593
  selectedLayerIds.filter((_lyrId) => layerId !== _lyrId)
@@ -594,7 +595,7 @@ var LayersProvider = ({ mp: _mp, children }) => {
594
595
  return;
595
596
  }
596
597
  const layerIndex = getLayerIndexById(layerId);
597
- const sourceType = (_a = layers[layerIndex]) == null ? void 0 : _a.source.type;
598
+ const sourceType = (_a2 = layers[layerIndex]) == null ? void 0 : _a2.source.type;
598
599
  yield toggleVectorLayer(layerIndex, styleIndex, focus);
599
600
  setSelectedLayerIds((_slIds) => [
600
601
  layerId,
@@ -689,6 +690,9 @@ var LayersProvider = ({ mp: _mp, children }) => {
689
690
  mapStyle,
690
691
  featuresAtLatLng,
691
692
  setMapStyle,
693
+ maxZoom,
694
+ setMaxZoom,
695
+ mapStyles: styles,
692
696
  all: layers,
693
697
  setAll: setLayers,
694
698
  selectedIds: selectedLayerIds,
@@ -1947,13 +1951,19 @@ function SelectedTabPanel() {
1947
1951
  }
1948
1952
 
1949
1953
  // src/components/sidebar/settings/index.tsx
1950
- import { defaultMapStyles as defaultMapStyles2, useT as useT9 } from "@biodiv-platform/naksha-commons";
1954
+ import { useT as useT9 } from "@biodiv-platform/naksha-commons";
1951
1955
  import { tw as tw17 } from "twind";
1952
1956
  import { jsx as jsx22, jsxs as jsxs14 } from "react/jsx-runtime";
1953
1957
  function SettingsTabPanel() {
1954
1958
  const { layer } = useLayers();
1955
1959
  const { t } = useT9();
1956
- const handleOnStyleChange = (e) => layer.setMapStyle(e.target.value);
1960
+ const handleOnStyleChange = (e) => {
1961
+ var _a;
1962
+ layer.setMapStyle(e.target.value);
1963
+ layer.setMaxZoom(
1964
+ (_a = layer.mapStyles.find((ms) => ms.style === e.target.value)) == null ? void 0 : _a.maxZoom
1965
+ );
1966
+ };
1957
1967
  return /* @__PURE__ */ jsxs14("div", {
1958
1968
  className: tw17`w-full p-4 flex flex-col gap-4`,
1959
1969
  children: [
@@ -1962,7 +1972,7 @@ function SettingsTabPanel() {
1962
1972
  label: t("base_style"),
1963
1973
  defaultValue: layer.mapStyle,
1964
1974
  onChange: handleOnStyleChange,
1965
- children: defaultMapStyles2.map((ms) => /* @__PURE__ */ jsx22("option", {
1975
+ children: layer.mapStyles.map((ms) => /* @__PURE__ */ jsx22("option", {
1966
1976
  value: ms.style,
1967
1977
  children: ms.text
1968
1978
  }, ms.key))
@@ -2286,6 +2296,7 @@ function Map2() {
2286
2296
  setCoordinates(event.lngLat);
2287
2297
  hover.onHover(event);
2288
2298
  };
2299
+ console.info("NakshaMaplibreLayers props");
2289
2300
  return /* @__PURE__ */ jsxs18("div", {
2290
2301
  className: tw20`h-full w-full relative bg-gray-100`,
2291
2302
  children: [
@@ -2297,6 +2308,7 @@ function Map2() {
2297
2308
  initialViewState: viewState,
2298
2309
  style: { width: "100%", height: "100%" },
2299
2310
  mapStyle: layer.mapStyle,
2311
+ maxZoom: layer.maxZoom,
2300
2312
  onClick: onMapClick,
2301
2313
  onMouseMove: handleOnMouseMove,
2302
2314
  children: [
package/dist/index.d.ts CHANGED
@@ -24,6 +24,12 @@ interface NakshaMaplibreLayersProps {
24
24
  selectedLayers?: string[];
25
25
  onSelectedLayersChange?: any;
26
26
  mapStyle?: MapStyles;
27
+ mapStyles?: Array<{
28
+ text: string;
29
+ key: string;
30
+ style: string;
31
+ maxZoom?: number;
32
+ }>;
27
33
  layers?: GeoserverLayer[];
28
34
  onLayerDownload?: any;
29
35
  canLayerShare?: any;
package/dist/index.js CHANGED
@@ -503,13 +503,14 @@ var LayersContext = (0, import_react.createContext)(
503
503
  {}
504
504
  );
505
505
  var LayersProvider = ({ mp: _mp, children }) => {
506
+ var _a, _b;
506
507
  const [mp, setMP] = (0, import_react.useState)(_mp);
507
508
  const { mapl } = (0, import_maplibre.useMap)();
508
509
  const [queryTerm, setQueryTerm] = (0, import_react.useState)("");
509
510
  const queryTermDebounced = (0, import_naksha_commons2.useDebounce)(queryTerm, 500);
510
- const [mapStyle, setMapStyle] = (0, import_react.useState)(
511
- import_naksha_commons2.defaultMapStyles[(mp == null ? void 0 : mp.mapStyle) || 0].style
512
- );
511
+ const styles = mp.mapStyles && mp.mapStyles.length > 0 ? mp.mapStyles : import_naksha_commons2.defaultMapStyles;
512
+ const [mapStyle, setMapStyle] = (0, import_react.useState)((_a = styles[(mp == null ? void 0 : mp.mapStyle) || 0]) == null ? void 0 : _a.style);
513
+ const [maxZoom, setMaxZoom] = (0, import_react.useState)((_b = styles[(mp == null ? void 0 : mp.mapStyle) || 0]) == null ? void 0 : _b.maxZoom);
513
514
  const [selectionStyle, setSelectionStyle] = (0, import_react.useState)(
514
515
  SELECTION_STYLE.TOP
515
516
  );
@@ -523,12 +524,12 @@ var LayersProvider = ({ mp: _mp, children }) => {
523
524
  const [hoverFeatures, setHoverFeatures] = (0, import_react.useState)();
524
525
  const [selectedFeatures, setSelectedFeatures] = (0, import_react.useState)();
525
526
  const selectedFeaturesId = (0, import_react.useMemo)(() => {
526
- var _a;
527
+ var _a2;
527
528
  const meta = {};
528
529
  for (const qr of selectedFeatures || []) {
529
530
  meta[qr.sourceLayer] = [
530
531
  ...meta[qr.sourceLayer] || [],
531
- (_a = qr == null ? void 0 : qr.properties) == null ? void 0 : _a[PROPERTY_ID]
532
+ (_a2 = qr == null ? void 0 : qr.properties) == null ? void 0 : _a2[PROPERTY_ID]
532
533
  ];
533
534
  }
534
535
  return Object.keys(meta).length ? meta : void 0;
@@ -570,7 +571,7 @@ var LayersProvider = ({ mp: _mp, children }) => {
570
571
  toggleVectorLayer(layerIndex, styleIndex, false);
571
572
  });
572
573
  const onMapHover = (e) => __async(void 0, null, function* () {
573
- var _a, _b, _c, _d;
574
+ var _a2, _b2, _c, _d;
574
575
  if (!selectedLayerIds.length || !mapl)
575
576
  return;
576
577
  try {
@@ -579,14 +580,14 @@ var LayersProvider = ({ mp: _mp, children }) => {
579
580
  layers: [lastLayerId]
580
581
  });
581
582
  if (feats.length) {
582
- const fId = ((_a = feats[0]) == null ? void 0 : _a.id) || ((_c = (_b = feats[0]) == null ? void 0 : _b.properties) == null ? void 0 : _c[PROPERTY_ID]);
583
+ const fId = ((_a2 = feats[0]) == null ? void 0 : _a2.id) || ((_c = (_b2 = feats[0]) == null ? void 0 : _b2.properties) == null ? void 0 : _c[PROPERTY_ID]);
583
584
  if (fId === (hoverFeatures == null ? void 0 : hoverFeatures.id))
584
585
  return;
585
586
  const layer = layers[getLayerIndexById(lastLayerId)];
586
587
  const hoverProperties = (_d = layer == null ? void 0 : layer.data) == null ? void 0 : _d.summaryColumn.map((sc) => {
587
- var _a2, _b2, _c2;
588
+ var _a3, _b3, _c2;
588
589
  return [
589
- ((_b2 = (_a2 = layer.data) == null ? void 0 : _a2.propertyMap) == null ? void 0 : _b2[sc]) || sc,
590
+ ((_b3 = (_a3 = layer.data) == null ? void 0 : _a3.propertyMap) == null ? void 0 : _b3[sc]) || sc,
590
591
  (_c2 = feats[0].properties) == null ? void 0 : _c2[sc]
591
592
  ];
592
593
  });
@@ -607,7 +608,7 @@ var LayersProvider = ({ mp: _mp, children }) => {
607
608
  styleIndex = 0,
608
609
  focus = true
609
610
  }) {
610
- var _a;
611
+ var _a2;
611
612
  if (!add) {
612
613
  setSelectedLayerIds(
613
614
  selectedLayerIds.filter((_lyrId) => layerId !== _lyrId)
@@ -615,7 +616,7 @@ var LayersProvider = ({ mp: _mp, children }) => {
615
616
  return;
616
617
  }
617
618
  const layerIndex = getLayerIndexById(layerId);
618
- const sourceType = (_a = layers[layerIndex]) == null ? void 0 : _a.source.type;
619
+ const sourceType = (_a2 = layers[layerIndex]) == null ? void 0 : _a2.source.type;
619
620
  yield toggleVectorLayer(layerIndex, styleIndex, focus);
620
621
  setSelectedLayerIds((_slIds) => [
621
622
  layerId,
@@ -710,6 +711,9 @@ var LayersProvider = ({ mp: _mp, children }) => {
710
711
  mapStyle,
711
712
  featuresAtLatLng,
712
713
  setMapStyle,
714
+ maxZoom,
715
+ setMaxZoom,
716
+ mapStyles: styles,
713
717
  all: layers,
714
718
  setAll: setLayers,
715
719
  selectedIds: selectedLayerIds,
@@ -1974,7 +1978,13 @@ var import_jsx_runtime22 = require("react/jsx-runtime");
1974
1978
  function SettingsTabPanel() {
1975
1979
  const { layer } = useLayers();
1976
1980
  const { t } = (0, import_naksha_commons11.useT)();
1977
- const handleOnStyleChange = (e) => layer.setMapStyle(e.target.value);
1981
+ const handleOnStyleChange = (e) => {
1982
+ var _a;
1983
+ layer.setMapStyle(e.target.value);
1984
+ layer.setMaxZoom(
1985
+ (_a = layer.mapStyles.find((ms) => ms.style === e.target.value)) == null ? void 0 : _a.maxZoom
1986
+ );
1987
+ };
1978
1988
  return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", {
1979
1989
  className: import_twind17.tw`w-full p-4 flex flex-col gap-4`,
1980
1990
  children: [
@@ -1983,7 +1993,7 @@ function SettingsTabPanel() {
1983
1993
  label: t("base_style"),
1984
1994
  defaultValue: layer.mapStyle,
1985
1995
  onChange: handleOnStyleChange,
1986
- children: import_naksha_commons11.defaultMapStyles.map((ms) => /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("option", {
1996
+ children: layer.mapStyles.map((ms) => /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("option", {
1987
1997
  value: ms.style,
1988
1998
  children: ms.text
1989
1999
  }, ms.key))
@@ -2307,6 +2317,7 @@ function Map2() {
2307
2317
  setCoordinates(event.lngLat);
2308
2318
  hover.onHover(event);
2309
2319
  };
2320
+ console.info("NakshaMaplibreLayers props");
2310
2321
  return /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)("div", {
2311
2322
  className: import_twind20.tw`h-full w-full relative bg-gray-100`,
2312
2323
  children: [
@@ -2318,6 +2329,7 @@ function Map2() {
2318
2329
  initialViewState: viewState,
2319
2330
  style: { width: "100%", height: "100%" },
2320
2331
  mapStyle: layer.mapStyle,
2332
+ maxZoom: layer.maxZoom,
2321
2333
  onClick: onMapClick,
2322
2334
  onMouseMove: handleOnMouseMove,
2323
2335
  children: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biodiv-platform/naksha-maplibre-layers",
3
- "version": "5.0.1",
3
+ "version": "5.0.3",
4
4
  "author": "harshzalavadiya",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/esm/index.js",