From 39daced9e9da1009a624e47468120f6d85900272 Mon Sep 17 00:00:00 2001 From: zxyroyy <1442470094@qq.com> Date: Sat, 9 May 2026 16:47:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E4=BD=93=E5=B1=9E=E6=80=A7=E7=94=9F?= =?UTF-8?q?=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/cesium/EntityManager.ts | 45 +++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/utils/cesium/EntityManager.ts b/src/utils/cesium/EntityManager.ts index c03ea14..ad05ab5 100644 --- a/src/utils/cesium/EntityManager.ts +++ b/src/utils/cesium/EntityManager.ts @@ -55,10 +55,12 @@ export class EntityManager { const entity = new Entity({ id, position: this.#convertPosition(position), - ...attributes, }); this.#configureEntityGraphics(entity, entityOptions); + + this.#applyAttributesToEntity(entity, attributes, entityOptions.type); + this.#viewer.entities.add(entity); this.#storeEntityId(id, isDefault); entities.push(entity); @@ -82,11 +84,12 @@ export class EntityManager { const entity = new Entity({ id, position: this.#convertPosition(position), - ...attributes, }); this.#configureEntityGraphics(entity, entityOptions); + this.#applyAttributesToEntity(entity, attributes, entityOptions.type); + this.#viewer.entities.add(entity); this.#storeEntityId(id, isDefault); return entity; @@ -251,6 +254,44 @@ export class EntityManager { } } + /** + * 将属性应用到实体 + * @param entity 实体实例 + * @param attributes 属性对象 + * @private + */ + #applyAttributesToEntity(entity: Entity, attributes: Record, entityType?: string): void { + if (!attributes || Object.keys(attributes).length === 0) { + return; + } + + let targetGraphics: any = null; + + if (entityType === 'point' && entity.point) { + targetGraphics = entity.point; + } else if (entityType === 'billboard' && entity.billboard) { + targetGraphics = entity.billboard; + } else if (entityType === 'polyline' && entity.polyline) { + targetGraphics = entity.polyline; + } else if (entityType === 'polygon' && entity.polygon) { + targetGraphics = entity.polygon; + } + + if (targetGraphics) { + Object.entries(attributes).forEach(([key, value]) => { + if (value !== undefined && value !== null) { + (targetGraphics as any)[key] = value; + } + }); + } else { + Object.entries(attributes).forEach(([key, value]) => { + if (value !== undefined && value !== null) { + (entity as any)[key] = value; + } + }); + } + } + #processHierarchy( hier: | PolygonHierarchy