@evergis/react 2.0.180 → 2.0.181

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,8 +1,9 @@
1
1
  import { ReactNode, RefObject } from "react";
2
- import { AttributeType, PointLabelSymbolDc, SvgPointSymbolDc, StyleDc, FeatureLayerServiceInfoDc } from "@evergis/api";
2
+ import { AttributeType, PointLabelSymbolDc, SvgPointSymbolDc, StyleDc, FeatureLayerServiceInfoDc, AttributeFormatDc, FeatureDc } from "@evergis/api";
3
3
  import { MaskedImage } from "@evergis/sgis/es/symbols/point/MaskedImage";
4
4
  import { H3Symbol } from "@evergis/sgis/es/symbols/H3Symbol";
5
- import { ClassificationParameterExtended, LegendValueType, ParameterByAttribute, ParameterValue, StyleSymbolType, SvgPointSymbol } from "../../core";
5
+ import { Coordinates } from "@evergis/sgis/es/baseTypes";
6
+ import { ClassificationParameterExtended, LayerAttribute, LegendValueType, ParameterByAttribute, ParameterValue, StyleSymbolType, SvgPointSymbol } from "../../core";
6
7
  import { SGisBrushFill, SGisImageFill, SGisPolygonSymbol, SGisPolylineSymbol } from "../../symbols";
7
8
  export declare type ClassifyParameter = "fill.color" | "fill.hatchColor" | "stroke.width" | "stroke.color" | "textBackground.fill.color" | "background.fillColor" | "background.strokeColor" | "background.strokeWidth" | "figure.fillColor" | "fillColor" | "strokeColor" | "strokeWidth" | "fontColor" | "haloColor" | "size" | "symbol" | "angle" | "maskedColor" | "endingSize" | "beginningSize" | "maxObjectCount" | "gridSize" | "selectionObjectsLimit";
8
9
  export interface ParameterInfo {
@@ -19,20 +20,23 @@ export declare const enum Units {
19
20
  Count = "pcs",
20
21
  Degrees = "\u00B0"
21
22
  }
23
+ export declare type Positions = Coordinates | Coordinates[] | Coordinates[][];
24
+ export declare type FeaturedDcExtendedGeometry = Omit<FeatureDc["geometry"], "coordinates"> & {
25
+ coordinates?: Positions;
26
+ };
22
27
  export declare type LegendProps = {
23
28
  layerInfo: FeatureLayerServiceInfoDc;
29
+ formatValue?: (type: AttributeType, value: string | number | Date | FeaturedDcExtendedGeometry, stringFormat?: AttributeFormatDc) => string;
24
30
  hiddenLegends?: Record<string, string[]>;
25
31
  toggleHiddenLegend?: (layerName: string, hiddenCondition: string) => void;
26
32
  };
27
- export declare type LegendSectionProps = Pick<LegendProps, "hiddenLegends" | "toggleHiddenLegend"> & {
33
+ export declare type LegendSectionProps = Pick<LegendProps, "hiddenLegends" | "toggleHiddenLegend" | "formatValue"> & {
28
34
  layerName: string;
29
35
  symbol: StyleDc["symbol"];
30
36
  parameter: ClassificationParameterExtended;
31
37
  parameters: ClassificationParameterExtended[];
32
38
  classified: ParameterByAttribute<ParameterValue>;
33
- attributeName: string;
34
- attributeTitle: string;
35
- attributeType: AttributeType;
39
+ attribute: LayerAttribute;
36
40
  index: number;
37
41
  };
38
42
  export declare type LegendSectionItem = Pick<LegendProps, "hiddenLegends" | "toggleHiddenLegend"> & {
@@ -1398,7 +1398,7 @@ const formatDate = function formatDate(date, _temp) {
1398
1398
  return dateFns.format(dateValue, dateFormat);
1399
1399
  }
1400
1400
 
1401
- return "" + defaultValue;
1401
+ return defaultValue.toString();
1402
1402
  };
1403
1403
 
1404
1404
  function numberWithSpaces(x, fractionDigits, delim) {
@@ -2544,39 +2544,25 @@ const isRangeCondition = condition => condition.includes("(");
2544
2544
  const getSymbolParameterInfo = parameter => {
2545
2545
  return PARAMETER_INFOS[parameter] || DEFAULT_PARAMETER_INFO;
2546
2546
  };
2547
- const formatValue$1 = (value, type, calculatedParameter) => {
2548
- var _ref;
2549
-
2550
- if (type === api.AttributeType.DateTime) {
2551
- return formatDate(value, {
2552
- dateFormat: exports.DateFormat.DateTime
2553
- });
2554
- }
2555
-
2556
- const {
2557
- serialize
2558
- } = getSymbolParameterInfo(calculatedParameter);
2559
- return (_ref = value && typeof value === "number" ? serialize(value) : value) == null ? void 0 : _ref.toString();
2560
- };
2561
- const formatUniqueClassValue = value => {
2547
+ const formatUniqueClassValue = (value, formatValue) => {
2562
2548
  const {
2563
2549
  attribute,
2564
2550
  uniqueValue
2565
2551
  } = value;
2566
- return attribute ? formatValue$1(uniqueValue, attribute.type) : uniqueValue;
2552
+ return attribute && formatValue ? formatValue(attribute.type, uniqueValue, attribute.stringFormat) : uniqueValue;
2567
2553
  };
2568
- const getRangeValues$1 = (_ref2, isDouble, isDate, index) => {
2554
+ const getRangeValues$1 = (_ref, isDouble, isDate, index) => {
2569
2555
  let {
2570
2556
  from,
2571
2557
  to
2572
- } = _ref2;
2558
+ } = _ref;
2573
2559
  return {
2574
2560
  from: from !== null && index !== 0 ? isDate ? from : isDouble ? +from : +from + 1 : from,
2575
2561
  to
2576
2562
  };
2577
2563
  };
2578
- const formatRangeClassValue = (value, index) => {
2579
- var _value$attribute, _value$attribute2;
2564
+ const formatRangeClassValue = (value, formatValue, index) => {
2565
+ var _value$attribute, _value$attribute2, _value$attribute3, _value$attribute4, _value$attribute5, _value$attribute6;
2580
2566
 
2581
2567
  const isDouble = ((_value$attribute = value.attribute) == null ? void 0 : _value$attribute.type) === "Double";
2582
2568
  const isDate = ((_value$attribute2 = value.attribute) == null ? void 0 : _value$attribute2.type) === "DateTime";
@@ -2584,8 +2570,8 @@ const formatRangeClassValue = (value, index) => {
2584
2570
  from,
2585
2571
  to
2586
2572
  } = getRangeValues$1(value, isDouble, isDate, index);
2587
- const formattedFrom = isDate && from ? formatDate(from) : from;
2588
- const formattedTo = isDate && to ? formatDate(to) : to;
2573
+ const formattedFrom = formatValue ? formatValue((_value$attribute3 = value.attribute) == null ? void 0 : _value$attribute3.type, from, (_value$attribute4 = value.attribute) == null ? void 0 : _value$attribute4.stringFormat) : from;
2574
+ const formattedTo = formatValue ? formatValue((_value$attribute5 = value.attribute) == null ? void 0 : _value$attribute5.type, to, (_value$attribute6 = value.attribute) == null ? void 0 : _value$attribute6.stringFormat) : to;
2589
2575
 
2590
2576
  if (from === null) {
2591
2577
  return "" + formattedTo + (!isDate ? " и менее" : "");
@@ -2614,20 +2600,18 @@ const getTitleFromCondition = condition => {
2614
2600
  return (_parts$ = parts[1]) == null ? void 0 : _parts$.slice(1, -1);
2615
2601
  };
2616
2602
 
2617
- function createValueTitle$1(paramValue, attributeType, index) {
2603
+ function createValueTitle$1(paramValue, attribute, formatValue, index) {
2618
2604
  if (paramValue.title) return paramValue.title;
2619
2605
  const value = {
2620
2606
  parameterValue: getParameterValue(paramValue.value),
2621
- attribute: {
2622
- type: attributeType
2623
- }
2607
+ attribute
2624
2608
  };
2625
2609
  const sign = getSignFromConditionPart(paramValue.condition, 1);
2626
2610
  const isFirstFrom = sign.includes(">");
2627
2611
  value.from = isFirstFrom ? getValueFromConditionPart(paramValue.condition, 1) : null;
2628
2612
  value.to = paramValue.condition.includes(" && ") && isFirstFrom ? getValueFromConditionPart(paramValue.condition, 2) : !isFirstFrom ? getValueFromConditionPart(paramValue.condition, 1) : null;
2629
- if (isRangeClass(value)) return formatRangeClassValue(value, index);
2630
- if (isUniqueClass(value)) return formatUniqueClassValue(value);
2613
+ if (isRangeClass(value)) return formatRangeClassValue(value, formatValue, index);
2614
+ if (isUniqueClass(value)) return formatUniqueClassValue(value, formatValue);
2631
2615
  return "";
2632
2616
  } // Основывается на http://cf.everpoint.ru/pages/viewpage.action?pageId=45024217 ->
2633
2617
  // пункт "Настраиваемые значения параметров символики в системе"
@@ -2902,19 +2886,17 @@ const createOtherHiddenCondition = (values, attributeName, attributeType) => {
2902
2886
 
2903
2887
  return hiddenCondition;
2904
2888
  };
2905
- const getMinimizedLegendValues = (attributeName, attributeType, classified, index, otherTitle) => {
2889
+ const getMinimizedLegendValues = (attribute, classified, formatValue, index, otherTitle) => {
2906
2890
  const other = {
2907
2891
  title: otherTitle,
2908
2892
  parameterValue: classified.defaultValue,
2909
- hiddenCondition: createOtherHiddenCondition(classified.values.map(val => getClassificationValue(val.value, otherTitle, new ClassificationCondition(val.condition))), attributeName, attributeType)
2893
+ hiddenCondition: createOtherHiddenCondition(classified.values.map(val => getClassificationValue(val.value, otherTitle, new ClassificationCondition(val.condition))), attribute.name, attribute.type)
2910
2894
  };
2911
2895
  const items = classified.values.map(paramValue => {
2912
2896
  const parameterValue = getParameterValue(paramValue.value);
2913
2897
  const result = {
2914
2898
  parameterValue,
2915
- attribute: {
2916
- type: attributeType
2917
- }
2899
+ attribute
2918
2900
  };
2919
2901
 
2920
2902
  if (isRangeCondition(paramValue.condition)) {
@@ -2922,38 +2904,38 @@ const getMinimizedLegendValues = (attributeName, attributeType, classified, inde
2922
2904
  const to = getValueFromConditionPart(paramValue.condition, 2);
2923
2905
  result.from = from ? isNumeric(from) ? +from : formatDate(from) : null;
2924
2906
  result.to = to ? isNumeric(to) ? +to : formatDate(to) : null;
2925
- result.title = createValueTitle$1(paramValue, attributeType, index);
2907
+ result.title = createValueTitle$1(paramValue, attribute, formatValue, index);
2926
2908
  return result;
2927
2909
  }
2928
2910
 
2929
- result.uniqueValue = formatValue$1(paramValue.value);
2911
+ result.uniqueValue = formatValue ? formatValue(attribute.type, paramValue.value, attribute.stringFormat) : paramValue.value.toString();
2930
2912
  result.title = getTitleFromCondition(paramValue.condition);
2931
- result.hiddenCondition = createHiddenCondition(attributeName, attributeType, getClassificationValue(paramValue.value, result.title, new ClassificationCondition(paramValue.condition)));
2913
+ result.hiddenCondition = createHiddenCondition(attribute.name, attribute.type, getClassificationValue(paramValue.value, result.title, new ClassificationCondition(paramValue.condition)));
2932
2914
  return result;
2933
2915
  });
2934
2916
 
2935
- if (attributeType !== api.AttributeType.String) {
2917
+ if (attribute.type !== api.AttributeType.String) {
2936
2918
  items.reverse();
2937
2919
  }
2938
2920
 
2939
2921
  return [...items, other];
2940
2922
  };
2941
- const getMaximizedLegendValues = (attributeName, attributeType, param, params, classified, symbol, sectionIndex, otherTitle) => {
2923
+ const getMaximizedLegendValues = (attribute, param, params, classified, symbol, formatValue, sectionIndex, otherTitle) => {
2942
2924
  const other = {
2943
2925
  title: otherTitle,
2944
2926
  symbol: createLegendSymbol(classified.defaultValue, param, params, symbol),
2945
- hiddenCondition: createOtherHiddenCondition(classified.values.map(val => getClassificationValue(val.value, otherTitle, new ClassificationCondition(val.condition))), attributeName, attributeType)
2927
+ hiddenCondition: createOtherHiddenCondition(classified.values.map(val => getClassificationValue(val.value, otherTitle, new ClassificationCondition(val.condition))), attribute.name, attribute.type)
2946
2928
  };
2947
2929
  const items = classified.values.map((paramValue, index) => {
2948
2930
  const result = {
2949
- symbol: createLegendSymbol(classified.values[index].value, param, params, symbol)
2931
+ symbol: createLegendSymbol(paramValue.value, param, params, symbol)
2950
2932
  };
2951
- result.title = isRangeCondition(paramValue.condition) ? createValueTitle$1(paramValue, attributeType, sectionIndex) : getTitleFromCondition(paramValue.condition);
2952
- result.hiddenCondition = createHiddenCondition(attributeName, attributeType, getClassificationValue(classified.values[index].value, result.title, new ClassificationCondition(classified.values[index].condition)));
2933
+ result.title = isRangeCondition(paramValue.condition) ? createValueTitle$1(paramValue, attribute, formatValue, sectionIndex) : getTitleFromCondition(paramValue.condition);
2934
+ result.hiddenCondition = createHiddenCondition(attribute.name, attribute.type, getClassificationValue(paramValue.value, result.title, new ClassificationCondition(classified.values[index].condition)));
2953
2935
  return result;
2954
2936
  });
2955
2937
 
2956
- if (attributeType !== api.AttributeType.String) {
2938
+ if (attribute.type !== api.AttributeType.String) {
2957
2939
  items.reverse();
2958
2940
  }
2959
2941
 
@@ -6375,9 +6357,8 @@ const LegendSection = _ref => {
6375
6357
  classified,
6376
6358
  hiddenLegends,
6377
6359
  toggleHiddenLegend,
6378
- attributeName,
6379
- attributeTitle,
6380
- attributeType,
6360
+ attribute,
6361
+ formatValue,
6381
6362
  index
6382
6363
  } = _ref;
6383
6364
  const {
@@ -6386,7 +6367,7 @@ const LegendSection = _ref => {
6386
6367
  const [isExpanded, toggleExpanded] = useToggle();
6387
6368
  const [maxRef, maxNode] = useNode();
6388
6369
  const [minRef, minNode] = useNode();
6389
- return React__default.createElement(MapLegendSectionContainer, null, React__default.createElement(MapLegendHeader, null, attributeTitle), React__default.createElement(LegendParameterDescription, {
6370
+ return React__default.createElement(MapLegendSectionContainer, null, React__default.createElement(MapLegendHeader, null, attribute.alias || attribute.name), React__default.createElement(LegendParameterDescription, {
6390
6371
  parameter: parameter
6391
6372
  }), React__default.createElement(MapLegendSectionItems, {
6392
6373
  height: isExpanded ? ((maxNode == null ? void 0 : maxNode.offsetHeight) || 0) + 4 : minNode == null ? void 0 : minNode.offsetHeight
@@ -6398,15 +6379,15 @@ const LegendSection = _ref => {
6398
6379
  hiddenLegends: hiddenLegends == null ? void 0 : hiddenLegends[layerName],
6399
6380
  toggleHiddenLegend: toggleHiddenLegend,
6400
6381
  parameter: parameter,
6401
- attributeType: attributeType,
6382
+ attributeType: attribute.type,
6402
6383
  index: index,
6403
- values: getMaximizedLegendValues(attributeName, attributeType, parameter, parameters, classified, symbol, index, t("classification.other"))
6384
+ values: getMaximizedLegendValues(attribute, parameter, parameters, classified, symbol, formatValue, index, t("classification.other"))
6404
6385
  }), React__default.createElement(MinimizedLegend, {
6405
6386
  innerRef: minRef,
6406
6387
  isShown: !isExpanded,
6407
- values: getMinimizedLegendValues(attributeName, attributeType, classified, index, t("classification.other")),
6408
6388
  hiddenLegends: hiddenLegends == null ? void 0 : hiddenLegends[layerName],
6409
- parameter: parameter
6389
+ parameter: parameter,
6390
+ values: getMinimizedLegendValues(attribute, classified, formatValue, index, t("classification.other"))
6410
6391
  })), React__default.createElement(MapLegendExpandButton, {
6411
6392
  onClick: toggleExpanded
6412
6393
  }, t(isExpanded ? "toggleMenu" : "Развернуть")));
@@ -6424,21 +6405,19 @@ const Legend = /*#__PURE__*/React.memo(_ref => {
6424
6405
  const parameters = Object.keys(classified);
6425
6406
  const attributes = getLayerAttributes(layerInfo.layerDefinition);
6426
6407
  return React__default.createElement(MapLegendContainer, null, Object.keys(classified).map((param, index) => {
6427
- var _classified$param$val, _layerInfo$style, _attributes$find;
6408
+ var _classified$param$val, _layerInfo$style;
6428
6409
 
6429
6410
  const attributeName = getAttributeNameFromCondition((_classified$param$val = classified[param].values[0]) == null ? void 0 : _classified$param$val.condition);
6430
6411
  return React__default.createElement(LegendSection, Object.assign({
6431
6412
  key: index,
6432
6413
  layerName: layerInfo.name,
6433
6414
  symbol: (_layerInfo$style = layerInfo.style) == null ? void 0 : _layerInfo$style.symbol,
6434
- attributeName: attributeName,
6435
- attributeTitle: ((_attributes$find = attributes.find(_ref2 => {
6415
+ attribute: attributes.find(_ref2 => {
6436
6416
  let {
6437
6417
  name
6438
6418
  } = _ref2;
6439
6419
  return name === attributeName;
6440
- })) == null ? void 0 : _attributes$find.alias) || attributeName,
6441
- attributeType: getAttributeType(layerInfo, attributeName),
6420
+ }),
6442
6421
  classified: classified[param],
6443
6422
  parameter: param,
6444
6423
  parameters: parameters,
@@ -7017,7 +6996,6 @@ exports.formatLength = formatLength;
7017
6996
  exports.formatPolygonMeasure = formatPolygonMeasure;
7018
6997
  exports.formatRangeClassValue = formatRangeClassValue;
7019
6998
  exports.formatUniqueClassValue = formatUniqueClassValue;
7020
- exports.formatValue = formatValue$1;
7021
6999
  exports.getAttributeFromCondition = getAttributeFromCondition;
7022
7000
  exports.getAttributeNameFromClassified = getAttributeNameFromClassified;
7023
7001
  exports.getAttributeNameFromCondition = getAttributeNameFromCondition;