From ced2ead6c13d00fa25efbb24112b260456217422 Mon Sep 17 00:00:00 2001 From: wzy-warehouse <18135009705@163.com> Date: Thu, 9 Apr 2026 10:51:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9C=B0=E5=9B=BE=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E7=BB=86=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/component/map/AdministrativeDivision.vue | 4 +--- src/types/cesium/EntityOptions.ts | 2 +- src/types/cesium/GeoJsonOptions.ts | 2 +- src/types/cesium/LayerConfig.ts | 2 +- src/types/cesium/PrimitiveOptions.ts | 2 +- src/utils/cesium/CesiumUtils.ts | 6 ++---- src/utils/cesium/EntityManager.ts | 2 +- src/utils/cesium/GeoJsonManager.ts | 11 ++++------- src/utils/cesium/LayerManager.ts | 2 +- src/utils/cesium/PrimitiveManager.ts | 2 +- 10 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/component/map/AdministrativeDivision.vue b/src/component/map/AdministrativeDivision.vue index 787f13b..0596d20 100644 --- a/src/component/map/AdministrativeDivision.vue +++ b/src/component/map/AdministrativeDivision.vue @@ -45,13 +45,11 @@ onMounted(() => { CesiumUtilsSingleton.batchAddGeoJsonLayers( areasId, areas, - new Array(areas.length).fill(true), areas.map((area, index) => { const areaName = area.features[0].properties.name; - console.log(areaName); return { showName: true, - default: true, + isDefault: true, labelStyle: { labelText: areaName, center: [area.features[0].properties.center[0], area.features[0].properties.center[1], 0], diff --git a/src/types/cesium/EntityOptions.ts b/src/types/cesium/EntityOptions.ts index 0c1dc43..6f6c85a 100644 --- a/src/types/cesium/EntityOptions.ts +++ b/src/types/cesium/EntityOptions.ts @@ -9,7 +9,7 @@ export interface EntityOptions { id: string // 实体唯一标识(必填,用于后续查询/删除) position: Cartesian3 | [number, number, number] // 位置(经纬度高程数组 或 Cartesian3) type: 'point' | 'polyline' | 'billboard' | 'polygon' // 实体类型 - default?: boolean // 是否是默认的实体,默认值false + isDefault?: boolean // 是否为默认实体,默认值false // 点配置(type='point' 时必填) pointOptions?: { color?: Color // 颜色(默认:红色) diff --git a/src/types/cesium/GeoJsonOptions.ts b/src/types/cesium/GeoJsonOptions.ts index 7834878..0a0f1f0 100644 --- a/src/types/cesium/GeoJsonOptions.ts +++ b/src/types/cesium/GeoJsonOptions.ts @@ -11,7 +11,7 @@ export type CustomizeGeoJsonDataSource = string | object; // 唯一配置项接口 export interface GeoJsonOptions { showName?: boolean; - default: boolean; + isDefault?: boolean; labelStyle?: LabelConfig; polygonStyle?: { fill?: boolean; diff --git a/src/types/cesium/LayerConfig.ts b/src/types/cesium/LayerConfig.ts index 3822c75..ec999b2 100644 --- a/src/types/cesium/LayerConfig.ts +++ b/src/types/cesium/LayerConfig.ts @@ -6,7 +6,7 @@ export interface LayerConfig { url: string // 图层地址 layers: string // 图层名称 - default?: boolean // 是否是默认图层,默认值false + isDefault?: boolean // 是否为默认图层,默认值false /** * WMTS 图层参数 diff --git a/src/types/cesium/PrimitiveOptions.ts b/src/types/cesium/PrimitiveOptions.ts index 6017188..be6fa42 100644 --- a/src/types/cesium/PrimitiveOptions.ts +++ b/src/types/cesium/PrimitiveOptions.ts @@ -4,7 +4,7 @@ export interface PrimitiveOptions { id: string type: 'point' | 'polyline' | 'polygon' | 'billboard' positions: [number, number, number][] | Cartesian3[] // 点集合,线和面需要多个点 - default?: boolean // 是否是默认的图元,默认值false + isDefault?: boolean // 是否为默认图元,默认值false color?: Color pixelSize?: number // 点大小 width?: number // 线宽 diff --git a/src/utils/cesium/CesiumUtils.ts b/src/utils/cesium/CesiumUtils.ts index 0877d8f..6b7c272 100644 --- a/src/utils/cesium/CesiumUtils.ts +++ b/src/utils/cesium/CesiumUtils.ts @@ -270,17 +270,15 @@ export class CesiumUtils { * 批量添加GeoJSON图层 * @param layerIds - 图层 ID 数组 * @param geojsonDatas - GeoJSON 数据数组 - * @param isDefaults - 是否为默认图层数组 - * @param options - 配置选项数组 + * @param options - 配置选项数组(包含 isDefault) */ async batchAddGeoJsonLayers( layerIds: string[], geojsonDatas: CustomizeGeoJsonDataSource[], - isDefaults: boolean[], options?: GeoJsonOptions[] ): Promise { this.#checkManager(this.#geoJsonManager, 'GeoJsonManager') - await this.#geoJsonManager!.batchAddGeoJsonLayers(layerIds, geojsonDatas, isDefaults, options) + await this.#geoJsonManager!.batchAddGeoJsonLayers(layerIds, geojsonDatas, options) } /** diff --git a/src/utils/cesium/EntityManager.ts b/src/utils/cesium/EntityManager.ts index 3123bd1..804b89e 100644 --- a/src/utils/cesium/EntityManager.ts +++ b/src/utils/cesium/EntityManager.ts @@ -35,7 +35,7 @@ export class EntityManager { * @returns 创建的 Entity 实例 */ addCesiumEntity(entityOptions: EntityOptions): Entity { - const { id, position, attributes = {}, default: isDefault = false } = entityOptions + const { id, position, attributes = {}, isDefault = false } = entityOptions if (!id) throw new Error('实体 id 为必填项') if (!position) throw new Error('实体 position 为必填项') diff --git a/src/utils/cesium/GeoJsonManager.ts b/src/utils/cesium/GeoJsonManager.ts index 65fbb9c..62665b1 100644 --- a/src/utils/cesium/GeoJsonManager.ts +++ b/src/utils/cesium/GeoJsonManager.ts @@ -32,7 +32,7 @@ export class GeoJsonManager { // 默认配置 static readonly DEFAULT_OPTIONS: Required = { showName: false, - default: false, + isDefault: false, labelStyle: { labelFont: '16px "微软雅黑"', labelColor: Color.RED, @@ -84,8 +84,7 @@ export class GeoJsonManager { if (this.#exists(layerId)) throw new Error(`图层 ${layerId} 已存在`) const opt = this.#mergeOptions(options) - // 优先使用 isDefault 参数,其次使用 options.default - const finalIsDefault = isDefault || opt.default + const finalIsDefault = isDefault || opt.isDefault // 加载并应用样式 const dataSource = await GeoJsonDataSource.load(geojsonData) @@ -146,18 +145,16 @@ export class GeoJsonManager { * 批量添加GeoJSON图层 * @param layerIds - 图层 ID 数组 * @param geojsonDatas - GeoJSON 数据数组 - * @param isDefaults - 是否为默认图层数组 - * @param options - 配置选项数组 + * @param options - 配置选项数组(包含 isDefault) */ async batchAddGeoJsonLayers( layerIds: string[], geojsonDatas: CustomizeGeoJsonDataSource[], - isDefaults: boolean[], options?: GeoJsonOptions[], ): Promise { await Promise.all( layerIds.map((id, index) => - this.addGeoJsonLayer(id, geojsonDatas?.[index], isDefaults?.[index], options?.[index]) + this.addGeoJsonLayer(id, geojsonDatas?.[index], false, options?.[index]) ) ) } diff --git a/src/utils/cesium/LayerManager.ts b/src/utils/cesium/LayerManager.ts index a697cf3..62b734c 100644 --- a/src/utils/cesium/LayerManager.ts +++ b/src/utils/cesium/LayerManager.ts @@ -26,7 +26,7 @@ export class LayerManager { * @returns 创建的 ImageryLayer 实例,失败则返回 null */ createLayer(layerConfig: LayerConfig): ImageryLayer | null { - const { layers: layerKey, default: isDefault = false } = layerConfig + const { layers: layerKey, isDefault = false } = layerConfig if (!layerKey) throw new Error('layers 参数未定义') this.#validateUniqueLayerKey(layerKey) diff --git a/src/utils/cesium/PrimitiveManager.ts b/src/utils/cesium/PrimitiveManager.ts index e42beaa..3c0288c 100644 --- a/src/utils/cesium/PrimitiveManager.ts +++ b/src/utils/cesium/PrimitiveManager.ts @@ -251,7 +251,7 @@ export class PrimitiveManager { #storePrimitives(options: PrimitiveOptions[], primitive: Primitive | BillboardCollection): void { options.forEach((option) => { - if (option.default) { + if (option.isDefault) { this.#defaultPrimitiveMap.set(option.id, primitive) } else { this.#customPrimitiveMap.set(option.id, primitive)