@biodiv-platform/naksha-maplibre-layers 5.0.1 → 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
@@ -482,13 +482,13 @@ var LayersContext = createContext(
482
482
  {}
483
483
  );
484
484
  var LayersProvider = ({ mp: _mp, children }) => {
485
+ var _a;
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
492
  const [selectionStyle, setSelectionStyle] = useState(
493
493
  SELECTION_STYLE.TOP
494
494
  );
@@ -502,12 +502,12 @@ var LayersProvider = ({ mp: _mp, children }) => {
502
502
  const [hoverFeatures, setHoverFeatures] = useState();
503
503
  const [selectedFeatures, setSelectedFeatures] = useState();
504
504
  const selectedFeaturesId = useMemo(() => {
505
- var _a;
505
+ var _a2;
506
506
  const meta = {};
507
507
  for (const qr of selectedFeatures || []) {
508
508
  meta[qr.sourceLayer] = [
509
509
  ...meta[qr.sourceLayer] || [],
510
- (_a = qr == null ? void 0 : qr.properties) == null ? void 0 : _a[PROPERTY_ID]
510
+ (_a2 = qr == null ? void 0 : qr.properties) == null ? void 0 : _a2[PROPERTY_ID]
511
511
  ];
512
512
  }
513
513
  return Object.keys(meta).length ? meta : void 0;
@@ -549,7 +549,7 @@ var LayersProvider = ({ mp: _mp, children }) => {
549
549
  toggleVectorLayer(layerIndex, styleIndex, false);
550
550
  });
551
551
  const onMapHover = (e) => __async(void 0, null, function* () {
552
- var _a, _b, _c, _d;
552
+ var _a2, _b, _c, _d;
553
553
  if (!selectedLayerIds.length || !mapl)
554
554
  return;
555
555
  try {
@@ -558,14 +558,14 @@ var LayersProvider = ({ mp: _mp, children }) => {
558
558
  layers: [lastLayerId]
559
559
  });
560
560
  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]);
561
+ const fId = ((_a2 = feats[0]) == null ? void 0 : _a2.id) || ((_c = (_b = feats[0]) == null ? void 0 : _b.properties) == null ? void 0 : _c[PROPERTY_ID]);
562
562
  if (fId === (hoverFeatures == null ? void 0 : hoverFeatures.id))
563
563
  return;
564
564
  const layer = layers[getLayerIndexById(lastLayerId)];
565
565
  const hoverProperties = (_d = layer == null ? void 0 : layer.data) == null ? void 0 : _d.summaryColumn.map((sc) => {
566
- var _a2, _b2, _c2;
566
+ var _a3, _b2, _c2;
567
567
  return [
568
- ((_b2 = (_a2 = layer.data) == null ? void 0 : _a2.propertyMap) == null ? void 0 : _b2[sc]) || sc,
568
+ ((_b2 = (_a3 = layer.data) == null ? void 0 : _a3.propertyMap) == null ? void 0 : _b2[sc]) || sc,
569
569
  (_c2 = feats[0].properties) == null ? void 0 : _c2[sc]
570
570
  ];
571
571
  });
@@ -586,7 +586,7 @@ var LayersProvider = ({ mp: _mp, children }) => {
586
586
  styleIndex = 0,
587
587
  focus = true
588
588
  }) {
589
- var _a;
589
+ var _a2;
590
590
  if (!add) {
591
591
  setSelectedLayerIds(
592
592
  selectedLayerIds.filter((_lyrId) => layerId !== _lyrId)
@@ -594,7 +594,7 @@ var LayersProvider = ({ mp: _mp, children }) => {
594
594
  return;
595
595
  }
596
596
  const layerIndex = getLayerIndexById(layerId);
597
- const sourceType = (_a = layers[layerIndex]) == null ? void 0 : _a.source.type;
597
+ const sourceType = (_a2 = layers[layerIndex]) == null ? void 0 : _a2.source.type;
598
598
  yield toggleVectorLayer(layerIndex, styleIndex, focus);
599
599
  setSelectedLayerIds((_slIds) => [
600
600
  layerId,
@@ -689,6 +689,7 @@ var LayersProvider = ({ mp: _mp, children }) => {
689
689
  mapStyle,
690
690
  featuresAtLatLng,
691
691
  setMapStyle,
692
+ mapStyles: styles,
692
693
  all: layers,
693
694
  setAll: setLayers,
694
695
  selectedIds: selectedLayerIds,
@@ -1947,7 +1948,7 @@ function SelectedTabPanel() {
1947
1948
  }
1948
1949
 
1949
1950
  // src/components/sidebar/settings/index.tsx
1950
- import { defaultMapStyles as defaultMapStyles2, useT as useT9 } from "@biodiv-platform/naksha-commons";
1951
+ import { useT as useT9 } from "@biodiv-platform/naksha-commons";
1951
1952
  import { tw as tw17 } from "twind";
1952
1953
  import { jsx as jsx22, jsxs as jsxs14 } from "react/jsx-runtime";
1953
1954
  function SettingsTabPanel() {
@@ -1962,7 +1963,7 @@ function SettingsTabPanel() {
1962
1963
  label: t("base_style"),
1963
1964
  defaultValue: layer.mapStyle,
1964
1965
  onChange: handleOnStyleChange,
1965
- children: defaultMapStyles2.map((ms) => /* @__PURE__ */ jsx22("option", {
1966
+ children: layer.mapStyles.map((ms) => /* @__PURE__ */ jsx22("option", {
1966
1967
  value: ms.style,
1967
1968
  children: ms.text
1968
1969
  }, ms.key))
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,13 @@ var LayersContext = (0, import_react.createContext)(
503
503
  {}
504
504
  );
505
505
  var LayersProvider = ({ mp: _mp, children }) => {
506
+ var _a;
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
513
  const [selectionStyle, setSelectionStyle] = (0, import_react.useState)(
514
514
  SELECTION_STYLE.TOP
515
515
  );
@@ -523,12 +523,12 @@ var LayersProvider = ({ mp: _mp, children }) => {
523
523
  const [hoverFeatures, setHoverFeatures] = (0, import_react.useState)();
524
524
  const [selectedFeatures, setSelectedFeatures] = (0, import_react.useState)();
525
525
  const selectedFeaturesId = (0, import_react.useMemo)(() => {
526
- var _a;
526
+ var _a2;
527
527
  const meta = {};
528
528
  for (const qr of selectedFeatures || []) {
529
529
  meta[qr.sourceLayer] = [
530
530
  ...meta[qr.sourceLayer] || [],
531
- (_a = qr == null ? void 0 : qr.properties) == null ? void 0 : _a[PROPERTY_ID]
531
+ (_a2 = qr == null ? void 0 : qr.properties) == null ? void 0 : _a2[PROPERTY_ID]
532
532
  ];
533
533
  }
534
534
  return Object.keys(meta).length ? meta : void 0;
@@ -570,7 +570,7 @@ var LayersProvider = ({ mp: _mp, children }) => {
570
570
  toggleVectorLayer(layerIndex, styleIndex, false);
571
571
  });
572
572
  const onMapHover = (e) => __async(void 0, null, function* () {
573
- var _a, _b, _c, _d;
573
+ var _a2, _b, _c, _d;
574
574
  if (!selectedLayerIds.length || !mapl)
575
575
  return;
576
576
  try {
@@ -579,14 +579,14 @@ var LayersProvider = ({ mp: _mp, children }) => {
579
579
  layers: [lastLayerId]
580
580
  });
581
581
  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]);
582
+ const fId = ((_a2 = feats[0]) == null ? void 0 : _a2.id) || ((_c = (_b = feats[0]) == null ? void 0 : _b.properties) == null ? void 0 : _c[PROPERTY_ID]);
583
583
  if (fId === (hoverFeatures == null ? void 0 : hoverFeatures.id))
584
584
  return;
585
585
  const layer = layers[getLayerIndexById(lastLayerId)];
586
586
  const hoverProperties = (_d = layer == null ? void 0 : layer.data) == null ? void 0 : _d.summaryColumn.map((sc) => {
587
- var _a2, _b2, _c2;
587
+ var _a3, _b2, _c2;
588
588
  return [
589
- ((_b2 = (_a2 = layer.data) == null ? void 0 : _a2.propertyMap) == null ? void 0 : _b2[sc]) || sc,
589
+ ((_b2 = (_a3 = layer.data) == null ? void 0 : _a3.propertyMap) == null ? void 0 : _b2[sc]) || sc,
590
590
  (_c2 = feats[0].properties) == null ? void 0 : _c2[sc]
591
591
  ];
592
592
  });
@@ -607,7 +607,7 @@ var LayersProvider = ({ mp: _mp, children }) => {
607
607
  styleIndex = 0,
608
608
  focus = true
609
609
  }) {
610
- var _a;
610
+ var _a2;
611
611
  if (!add) {
612
612
  setSelectedLayerIds(
613
613
  selectedLayerIds.filter((_lyrId) => layerId !== _lyrId)
@@ -615,7 +615,7 @@ var LayersProvider = ({ mp: _mp, children }) => {
615
615
  return;
616
616
  }
617
617
  const layerIndex = getLayerIndexById(layerId);
618
- const sourceType = (_a = layers[layerIndex]) == null ? void 0 : _a.source.type;
618
+ const sourceType = (_a2 = layers[layerIndex]) == null ? void 0 : _a2.source.type;
619
619
  yield toggleVectorLayer(layerIndex, styleIndex, focus);
620
620
  setSelectedLayerIds((_slIds) => [
621
621
  layerId,
@@ -710,6 +710,7 @@ var LayersProvider = ({ mp: _mp, children }) => {
710
710
  mapStyle,
711
711
  featuresAtLatLng,
712
712
  setMapStyle,
713
+ mapStyles: styles,
713
714
  all: layers,
714
715
  setAll: setLayers,
715
716
  selectedIds: selectedLayerIds,
@@ -1983,7 +1984,7 @@ function SettingsTabPanel() {
1983
1984
  label: t("base_style"),
1984
1985
  defaultValue: layer.mapStyle,
1985
1986
  onChange: handleOnStyleChange,
1986
- children: import_naksha_commons11.defaultMapStyles.map((ms) => /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("option", {
1987
+ children: layer.mapStyles.map((ms) => /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("option", {
1987
1988
  value: ms.style,
1988
1989
  children: ms.text
1989
1990
  }, ms.key))
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.2",
4
4
  "author": "harshzalavadiya",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/esm/index.js",