優化坐標數據解析邏輯,增加對 device_coordinate 的數值比對以避免精度問題

This commit is contained in:
koko 2025-09-23 17:22:16 +08:00
parent 96fcd24546
commit a0b5085a7c

View File

@ -36,14 +36,25 @@ const defaultOption = (map, data = []) => {
//
const formattedData = data.map((coordinate) => {
const coordString = JSON.stringify(coordinate);
// device_coordinate
let isSelected = false;
if (formState.value.device_coordinate) {
try {
const deviceCoord = JSON.parse(formState.value.device_coordinate);
//
isSelected = coordinate.length === deviceCoord.length &&
coordinate.every((val, index) => Math.abs(val - deviceCoord[index]) < 0.001);
} catch (e) {
console.warn('解析 device_coordinate 失敗:', e);
}
}
return {
name: coordString,
value: coordinate,
itemStyle: {
color:
coordString === formState.value.device_coordinate
? "#0000FF"
: "#b02a02",
color: isSelected ? "#0000FF" : "#b02a02",
},
};
});