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<ClassBreak>,

uniqueValueInfos?:Array<UniqueValue>

}

renderer设置

```javascript

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

首先是参数定义

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<ClassBreak>,

uniqueValueInfos?:Array<UniqueValue>

}

renderer设置

```javascript

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

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容