tcctyn-ui/src/views/systemTemplate/forestFire/DialogPropertyGrid/property.js

124 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import * as Cesium from 'cesium'
// 定义水源地的属性
export const watersource = [
{
key: "type",
name: "要素类型",
type: "text",
value: "水源地",
disabled: true,
},
{
key: "name",
name: "名称",
type: "text",
value: "",
disabled: false,
},
{
key: "area",
name: "占地面积",
type: "text",
value: "0",
disabled: true,
},
{
key: "longitude",
name: "经度",
type: "text",
value: "0",
disabled: true,
},
{
key: "latitude",
name: "纬度",
type: "text",
value: "0",
disabled: true,
},
{
key: "volume",
name: "储水量",
type: "text",
value: "0",
disabled: false,
},
];
// 定义仓库的属性
export const warehouse = [
{
key: "type",
name: "要素类型",
type: "text",
value: "仓库",
disabled: true,
},
{
key: "name",
name: "名称",
type: "text",
value: "",
disabled: false,
},
{
key: "longitude",
name: "经度",
type: "text",
value: "0",
disabled: true,
},
{
key: "latitude",
name: "纬度",
type: "text",
value: "0",
disabled: true,
},
];
const getClone = (config) => {
return config.map(item => ({ ...item }))
}
export const getPropertyData = (entity) => {
let data = []
if(!entity || !entity.properties) {
return data // 如果没有实体或属性,返回空数组
}
const properties = entity.properties.getValue()
if (properties.__type === "watersource") {
data = getClone(watersource)
} else if (properties.__type === "warehouse") {
data = getClone(warehouse)
}
// 遍历数据数组将properties有的属性赋给对应的属性
// 注意地图要素属性主要参考这里的数据结构就算properties没有值也会显示出来
data.forEach(item => {
const value = properties[item.key]
if (value !== undefined) {
item.value = value
}
});
return data
};
export const setPropertyData = (data, entity) => {
if (!entity || !entity.properties) {
console.warn("Entity or properties not found")
return
}
const newProperties = entity.properties.getValue()
data.forEach(item => {
if (item.key && item.value !== undefined) {
newProperties[item.key] = item.value
}
})
// 替换 properties
entity.properties = new Cesium.PropertyBag(newProperties)
}