cesium 图层构建的那些事 (十七)
作者:互联网
根据基础聚合类,我们构建geojosn序列化的聚合使用类
首先是参数定义
interface ClassBreak {
minValue: number,
maxValue: number,
symbol: any
}
interface UniqueValue {
value: number,
symbol: any
}
export interface PRenderer {
type: “simple”|“uniqueValue”|“classBreaks”,
field?: string,//simple不需要该参数
symbol: any,
classBreakInfos?: Array,
uniqueValueInfos?:Array
}
renderer设置
import {PRenderer} from "./PRenderer";
import {ColorUtil} from "../utils/ColorUtil";
export class Renderer {
type = "Renderer";
private renderer: PRenderer;
constructor(renderer: PRenderer) {
this.renderer = renderer;
}
/**
* 获得symbol
* @param attributes 属性
* @param {boolean} isEntity 是否是Entity解析
* @returns {any} symbol
*/
public getSymbol(attributes: any, isEntity = false): any {
const {type, field, symbol, uniqueValueInfos, classBreakInfos} = this.renderer;
if (type === "simple") {
if (!symbol) {
throw new Error("缺少属性symbol");
}
return symbol;
}
let value = attributes[field || ""];
if (isEntity) {
value = value?._value
}
if (type === "uniqueValue") {
if (!uniqueValueInfos) {
throw new Error("缺少属性uniqueValueInfos");
}
for (const item of uniqueValueInfos) {
if (item.value == value) {
return item.symbol;
}
}
}
if (type === "classBreaks") {
if (!classBreakInfos) {
throw new Error("缺少属性classBreakInfos");
}
for (const item of classBreakInfos) {
if (value >= item.minValue && value < item.maxValue) {
return item.symbol;
}
}
}
return symbol;
}
public setEntitySymbol(entity: any, attributes: any) {
const symbol = this.getSymbol(attributes, true);
Renderer.setEntityProperties(entity, attributes, symbol);
}
public static setEntityProperties(obj: any, attributes: any, properties: any) {
for (const key in properties) {
const value = properties[key];
if (Object.prototype.toString.call(value) == "[object Object]") {
if (value instanceof Cesium.Color) {
obj[key] = value
} else if (value instanceof Cesium.LabelGraphics) {
const v = value.clone();
v.text = v.text._value.replace(/\${(\w+)+}/g, function (match, key) {
return attributes[key]._value;
});
更多参考 https://xiaozhuanlan.com/topic/4596712380
标签:十七,const,symbol,value,item,cesium,attributes,图层,any 来源: https://blog.csdn.net/haibalai2009/article/details/122730348