fix(map): convert actual demand display units
This commit is contained in:
@@ -32,9 +32,23 @@ import {
|
||||
} from "./styleEditorTypes";
|
||||
import { LegendStyleConfig } from "./StyleLegend";
|
||||
import { calculateClassification } from "@utils/breaksClassification";
|
||||
import { isLpsFlowProperty, toM3h } from "@utils/units";
|
||||
|
||||
const UNIT_HEADLOSS_RANGE: [number, number] = [0, 5];
|
||||
|
||||
const normalizeComputedStyleValue = (property: string, value: unknown) => {
|
||||
const numericValue = Number(value);
|
||||
if (!Number.isFinite(numericValue)) {
|
||||
return Number.NaN;
|
||||
}
|
||||
|
||||
const displayValue = isLpsFlowProperty(property)
|
||||
? toM3h(numericValue, "lps")
|
||||
: numericValue;
|
||||
|
||||
return property === "flow" ? Math.abs(displayValue) : displayValue;
|
||||
};
|
||||
|
||||
export const useStyleEditor = ({
|
||||
layerStyleStates,
|
||||
setLayerStyleStates,
|
||||
@@ -337,12 +351,20 @@ export const useStyleEditor = ({
|
||||
layerType === "junctions"
|
||||
? isElevation && elevationRange
|
||||
? [elevationRange[0], elevationRange[1]]
|
||||
: currentJunctionCalData?.map((item: any) => item.value) || []
|
||||
: currentJunctionCalData
|
||||
?.map((item: any) =>
|
||||
normalizeComputedStyleValue(effectiveStyleConfig.property, item.value)
|
||||
)
|
||||
.filter(Number.isFinite) || []
|
||||
: isDiameter && diameterRange
|
||||
? [diameterRange[0], diameterRange[1]]
|
||||
: isUnitHeadloss
|
||||
? [UNIT_HEADLOSS_RANGE[0], UNIT_HEADLOSS_RANGE[1]]
|
||||
: currentPipeCalData?.map((item: any) => item.value) || [];
|
||||
: currentPipeCalData
|
||||
?.map((item: any) =>
|
||||
normalizeComputedStyleValue(effectiveStyleConfig.property, item.value)
|
||||
)
|
||||
.filter(Number.isFinite) || [];
|
||||
|
||||
const canApply =
|
||||
layerType === "junctions"
|
||||
@@ -416,7 +438,7 @@ export const useStyleEditor = ({
|
||||
|
||||
const dataMap = new Map<string, number>();
|
||||
records.forEach((record: any) => {
|
||||
dataMap.set(record.ID, record.value || 0);
|
||||
dataMap.set(record.ID, normalizeComputedStyleValue(property, record.value || 0));
|
||||
});
|
||||
|
||||
vectorTileSources.forEach((vectorTileSource) => {
|
||||
@@ -434,8 +456,7 @@ export const useStyleEditor = ({
|
||||
return;
|
||||
}
|
||||
|
||||
renderFeature.properties_[property] =
|
||||
property === "flow" ? Math.abs(value) : value;
|
||||
renderFeature.properties_[property] = value;
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -457,7 +478,7 @@ export const useStyleEditor = ({
|
||||
|
||||
const dataMap = new Map<string, number>();
|
||||
records.forEach((record: any) => {
|
||||
dataMap.set(record.ID, record.value || 0);
|
||||
dataMap.set(record.ID, normalizeComputedStyleValue(property, record.value || 0));
|
||||
});
|
||||
|
||||
const listener = (event: any) => {
|
||||
@@ -478,8 +499,7 @@ export const useStyleEditor = ({
|
||||
return;
|
||||
}
|
||||
|
||||
renderFeature.properties_[property] =
|
||||
property === "flow" ? Math.abs(value) : value;
|
||||
renderFeature.properties_[property] = value;
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error processing tile load event:", error);
|
||||
|
||||
Reference in New Issue
Block a user