@evergis/react 4.0.37 → 4.0.39

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.
@@ -1,4 +1,5 @@
1
1
  export * from './map';
2
+ export * from './project';
2
3
  export * from './serverNotifications';
3
4
  export * from './task';
4
5
  export * from './useAppHeight';
@@ -0,0 +1,5 @@
1
+ export * from './useMaxZoomTo';
2
+ export * from './useCustomFeatureSelect';
3
+ export * from './useCurrentPageLayers';
4
+ export * from './useLayerHiddenAttributes';
5
+ export * from './useVisibleProjectItems';
@@ -0,0 +1 @@
1
+ export declare const useCurrentPageLayers: () => import('../..').ConfigLayer[];
@@ -0,0 +1,2 @@
1
+ import { CustomFeatureSelect } from '../../components/Dashboard/types';
2
+ export declare const useCustomFeatureSelect: () => ((layerName?: string) => [CustomFeatureSelect | undefined, CustomFeatureSelect | undefined]);
@@ -0,0 +1 @@
1
+ export declare const useLayerHiddenAttributes: (layerName: string) => [string[], (updatedAttributes: string[]) => void];
@@ -0,0 +1 @@
1
+ export declare const useMaxZoomTo: () => ((layerName?: string) => [number | undefined, number | undefined]);
@@ -0,0 +1 @@
1
+ export declare const useVisibleProjectItems: (applyMinMaxScale?: boolean) => import('../..').ConfigLayer[];
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ var charts = require('@evergis/charts');
8
8
  var api = require('@evergis/api');
9
9
  var Gradient = require('javascript-color-gradient');
10
10
  var color$1 = require('@evergis/color');
11
+ var turf = require('@turf/turf');
11
12
  var dateFns = require('date-fns');
12
13
  var lodash = require('lodash');
13
14
  var ru = require('date-fns/locale/ru');
@@ -17,7 +18,6 @@ var findAnd = require('find-and');
17
18
  var jspdf = require('jspdf');
18
19
  var html2canvas = require('html2canvas');
19
20
  var MapboxDraw = require('@mapbox/mapbox-gl-draw');
20
- var turf = require('@turf/turf');
21
21
  var MapGL = require('react-map-gl/maplibre');
22
22
  require('@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css');
23
23
  require('mapbox-gl/dist/mapbox-gl.css');
@@ -3630,6 +3630,27 @@ const adjustColor = (color, lightnessAdjustment = 5) => {
3630
3630
  return `#${toHex(rNew)}${toHex(gNew)}${toHex(bNew)}`;
3631
3631
  };
3632
3632
 
3633
+ const convertSpToTurfFeature = (geometry) => {
3634
+ if (!geometry) {
3635
+ return;
3636
+ }
3637
+ const { type, coordinates } = geometry;
3638
+ switch (type) {
3639
+ case api.OgcGeometryType.Point:
3640
+ return turf.point(coordinates);
3641
+ case api.OgcGeometryType.MultiPoint:
3642
+ return turf.multiPoint(coordinates);
3643
+ case api.OgcGeometryType.LineString:
3644
+ return turf.lineString(coordinates);
3645
+ case api.OgcGeometryType.MultiLineString:
3646
+ return turf.multiLineString(coordinates);
3647
+ case api.OgcGeometryType.Polygon:
3648
+ return turf.polygon(coordinates);
3649
+ case api.OgcGeometryType.MultiPolygon:
3650
+ return turf.multiPolygon(coordinates);
3651
+ }
3652
+ };
3653
+
3633
3654
  const NO_CONTENT_VALUE = "—";
3634
3655
  exports.DateFormat = void 0;
3635
3656
  (function (DateFormat) {
@@ -5341,17 +5362,25 @@ const useRedrawLayer = () => {
5341
5362
  }, [map]);
5342
5363
  };
5343
5364
 
5365
+ const SINGLE_FEATURE_FALLBACK_ZOOM = 17;
5344
5366
  const useZoomToFeatures = () => {
5345
5367
  const { map } = useMapContext();
5346
5368
  return React.useCallback((features, options) => {
5347
5369
  if (!features) {
5348
5370
  return;
5349
5371
  }
5350
- const currentFeatureCenter = turf.bbox({
5372
+ const [minX, minY, maxX, maxY] = turf.bbox({
5351
5373
  type: "FeatureCollection",
5352
- features: features,
5374
+ features: features.map(feature => convertSpToTurfFeature(feature.geometry)),
5375
+ });
5376
+ if (minX === maxX && minY === maxY) {
5377
+ map.current.flyTo({ center: [minX, minY], zoom: options?.maxZoom ?? SINGLE_FEATURE_FALLBACK_ZOOM });
5378
+ return;
5379
+ }
5380
+ map.current.fitBounds([minX, minY, maxX, maxY], {
5381
+ ...options,
5382
+ padding: options?.padding ?? 150,
5353
5383
  });
5354
- map.current.fitBounds(currentFeatureCenter, { ...options, padding: options?.padding ?? 150 });
5355
5384
  }, [map]);
5356
5385
  };
5357
5386
 
@@ -5387,6 +5416,70 @@ const useLayerParams = (layer) => {
5387
5416
  return layerParams;
5388
5417
  };
5389
5418
 
5419
+ const useMaxZoomTo = () => {
5420
+ const { currentPage } = useWidgetPage();
5421
+ return React.useCallback((layerName) => {
5422
+ if (!layerName) {
5423
+ return [currentPage?.options?.maxZoomTo, undefined];
5424
+ }
5425
+ return [currentPage?.options?.maxZoomTo, currentPage?.layers?.find(item => item.name === layerName)?.maxZoomTo];
5426
+ }, [currentPage?.layers, currentPage?.options?.maxZoomTo]);
5427
+ };
5428
+
5429
+ const useCustomFeatureSelect = () => {
5430
+ const { currentPage } = useWidgetPage();
5431
+ return React.useCallback((layerName) => {
5432
+ if (!layerName) {
5433
+ return [currentPage?.options?.customFeatureSelect, undefined];
5434
+ }
5435
+ return [
5436
+ currentPage?.options?.customFeatureSelect,
5437
+ currentPage?.layers?.find(item => item.name === layerName)?.customFeatureSelect,
5438
+ ];
5439
+ }, [currentPage?.layers, currentPage?.options?.customFeatureSelect]);
5440
+ };
5441
+
5442
+ const useCurrentPageLayers = () => {
5443
+ const { currentPage } = useWidgetPage();
5444
+ return React.useMemo(() => currentPage?.layers || [], [currentPage?.layers]);
5445
+ };
5446
+
5447
+ const useLayerHiddenAttributes = (layerName) => {
5448
+ const { currentPage, updateConfigPage } = useWidgetPage();
5449
+ const layerHiddenAttributes = React.useMemo(() => {
5450
+ return currentPage?.layers?.find(item => item.name === layerName)?.hiddenAttributes ?? [];
5451
+ }, [currentPage?.layers, layerName]);
5452
+ const updateLayerHiddenAttributes = React.useCallback((updatedHiddenAttributes) => {
5453
+ updateConfigPage({
5454
+ ...currentPage,
5455
+ layers: currentPage?.layers?.map(item => {
5456
+ return item.name === layerName
5457
+ ? {
5458
+ ...item,
5459
+ hiddenAttributes: updatedHiddenAttributes,
5460
+ }
5461
+ : item;
5462
+ }),
5463
+ });
5464
+ }, [currentPage, layerName, updateConfigPage]);
5465
+ return [layerHiddenAttributes, updateLayerHiddenAttributes];
5466
+ };
5467
+
5468
+ const useVisibleProjectItems = (applyMinMaxScale) => {
5469
+ const { map } = useMapContext();
5470
+ const projectItems = useCurrentPageLayers();
5471
+ const zoomChange = React.useMemo(() => (applyMinMaxScale && map.current?.getZoom() !== undefined ? Math.round(map.current?.getZoom()) : undefined), [applyMinMaxScale, map.current?.getZoom()]);
5472
+ return React.useMemo(() => {
5473
+ if (map.current?.getZoom() === undefined) {
5474
+ return [];
5475
+ }
5476
+ return (projectItems?.filter(item => item.isVisible &&
5477
+ (!applyMinMaxScale ||
5478
+ (Math.round(map.current.getZoom()) >= (item.minScale ?? 0) &&
5479
+ Math.round(map.current.getZoom()) <= (item.maxScale ?? 30)))) ?? []);
5480
+ }, [projectItems, zoomChange, applyMinMaxScale]);
5481
+ };
5482
+
5390
5483
  const useServerNotificationsContext = () => {
5391
5484
  return React.useContext(ServerNotificationsContext);
5392
5485
  };
@@ -8226,11 +8319,13 @@ const FeatureCardIconHeader = ({ isRow }) => {
8226
8319
  const { layerInfo, feature } = useWidgetContext(exports.WidgetType.FeatureCard);
8227
8320
  const { config } = useWidgetConfig(exports.WidgetType.FeatureCard);
8228
8321
  const zoomToFeatures = useZoomToFeatures();
8322
+ const getMaxZoomTo = useMaxZoomTo();
8323
+ const [optionsMaxZoomTo, layerMaxZoomTo] = React.useMemo(() => getMaxZoomTo(layerInfo?.name), [layerInfo?.name, getMaxZoomTo]);
8229
8324
  const { header } = config || {};
8230
8325
  const { options } = header || {};
8231
8326
  const { fontColor, bgColor, bigIcon } = options || {};
8232
8327
  const renderElement = useHeaderRender(header);
8233
- const handleIconClick = React.useCallback(() => zoomToFeatures([feature]), [zoomToFeatures, feature]);
8328
+ const handleIconClick = React.useCallback(() => zoomToFeatures([feature], { maxZoom: layerMaxZoomTo ?? optionsMaxZoomTo }), [zoomToFeatures, feature, layerMaxZoomTo, optionsMaxZoomTo]);
8234
8329
  return (jsxRuntime.jsx(IconHeaderWrapper, { "$fontColor": fontColor, "$bgColor": bgColor, "$bigIcon": bigIcon, children: jsxRuntime.jsx(uilibGl.ThemeProvider, { theme: uilibGl.defaultTheme, children: jsxRuntime.jsxs(Header, { "$isRow": isRow, children: [jsxRuntime.jsxs(HeaderFrontView, { children: [jsxRuntime.jsxs(HeaderContainer, { children: [jsxRuntime.jsx(uilibGl.Tooltip, { arrow: true, placement: "top", content: t("zoomToFeature", { ns: "dashboard", defaultValue: "Приблизить к объекту" }), delay: [600, 0], children: ref => (jsxRuntime.jsx(LayerIconClickable, { ref: ref, onClick: handleIconClick, children: jsxRuntime.jsx(LayerIcon, { layerInfo: layerInfo }) })) }), jsxRuntime.jsx(FeatureCardTitle, { title: renderElement({
8235
8330
  id: "title",
8236
8331
  wrap: false,
@@ -12495,6 +12590,7 @@ exports.applyQueryFilters = applyQueryFilters;
12495
12590
  exports.applyVarsToCondition = applyVarsToCondition;
12496
12591
  exports.checkEqualOrIncludes = checkEqualOrIncludes;
12497
12592
  exports.checkIsLoading = checkIsLoading;
12593
+ exports.convertSpToTurfFeature = convertSpToTurfFeature;
12498
12594
  exports.createConfigLayer = createConfigLayer;
12499
12595
  exports.createConfigPage = createConfigPage;
12500
12596
  exports.createNewPageId = createNewPageId;
@@ -12587,6 +12683,8 @@ exports.useAppHeight = useAppHeight;
12587
12683
  exports.useAutoCompleteControl = useAutoCompleteControl;
12588
12684
  exports.useChartChange = useChartChange;
12589
12685
  exports.useChartData = useChartData;
12686
+ exports.useCurrentPageLayers = useCurrentPageLayers;
12687
+ exports.useCustomFeatureSelect = useCustomFeatureSelect;
12590
12688
  exports.useDashboardHeader = useDashboardHeader;
12591
12689
  exports.useDataSources = useDataSources;
12592
12690
  exports.useDebouncedCallback = useDebouncedCallback;
@@ -12600,10 +12698,12 @@ exports.useGlobalContext = useGlobalContext;
12600
12698
  exports.useHeaderRender = useHeaderRender;
12601
12699
  exports.useHideIfEmptyDataSource = useHideIfEmptyDataSource;
12602
12700
  exports.useIconsFromLayers = useIconsFromLayers;
12701
+ exports.useLayerHiddenAttributes = useLayerHiddenAttributes;
12603
12702
  exports.useLayerParams = useLayerParams;
12604
12703
  exports.useMapContext = useMapContext;
12605
12704
  exports.useMapDraw = useMapDraw;
12606
12705
  exports.useMapImages = useMapImages;
12706
+ exports.useMaxZoomTo = useMaxZoomTo;
12607
12707
  exports.useProjectDashboardInit = useProjectDashboardInit;
12608
12708
  exports.usePythonSandbox = usePythonSandbox;
12609
12709
  exports.usePythonTask = usePythonTask;
@@ -12614,6 +12714,7 @@ exports.useServerNotificationsContext = useServerNotificationsContext;
12614
12714
  exports.useShownOtherItems = useShownOtherItems;
12615
12715
  exports.useToggle = useToggle;
12616
12716
  exports.useUpdateDataSource = useUpdateDataSource;
12717
+ exports.useVisibleProjectItems = useVisibleProjectItems;
12617
12718
  exports.useWidgetConfig = useWidgetConfig;
12618
12719
  exports.useWidgetContext = useWidgetContext;
12619
12720
  exports.useWidgetFilters = useWidgetFilters;