基础功能设置,添加相应查询方法

This commit is contained in:
wzy-warehouse
2026-04-08 22:20:42 +08:00
parent c285c752fc
commit ece181e5a3
7 changed files with 120 additions and 18 deletions
+9 -9
View File
@@ -9,7 +9,6 @@
"preview": "vite preview"
},
"dependencies": {
"vue": "^3.5.32",
"@element-plus/icons-vue": "^2.3.2",
"@types/spark-md5": "^3.0.5",
"axios": "^1.12.2",
@@ -18,26 +17,27 @@
"gm-crypto": "^0.1.12",
"pinia": "^3.0.3",
"spark-md5": "^3.0.2",
"vue-router": "^4.6.3",
"vite-plugin-cesium": "^1.2.22"
"vite-plugin-cesium": "^1.2.22",
"vue": "^3.5.32",
"vue-router": "^4.6.3"
},
"devDependencies": {
"@tsconfig/node22": "^22.0.2",
"@types/node": "^24.12.2",
"@vitejs/plugin-vue": "^6.0.5",
"@vue/tsconfig": "^0.9.1",
"typescript": "~6.0.2",
"vite": "^8.0.4",
"vue-tsc": "^3.2.6",
"@tsconfig/node22": "^22.0.2",
"@vue/eslint-config-prettier": "^10.2.0",
"@vue/eslint-config-typescript": "^14.6.0",
"@vue/tsconfig": "^0.9.1",
"eslint": "^9.37.0",
"eslint-plugin-vue": "~10.5.0",
"jiti": "^2.6.1",
"npm-run-all2": "^8.0.4",
"prettier": "3.6.2",
"typescript": "~6.0.2",
"unplugin-auto-import": "^20.2.0",
"unplugin-vue-components": "^30.0.0",
"vite-plugin-vue-devtools": "^8.0.3"
"vite": "^8.0.4",
"vite-plugin-vue-devtools": "^8.0.3",
"vue-tsc": "^3.2.6"
}
}
+1
View File
@@ -39,6 +39,7 @@ onMounted(() => {
const areaName = area.features[0].properties.name;
return {
showName: true,
default: true,
labelStyle: {
labelText: areaName,
center: [area.features[0].properties.center[0], area.features[0].properties.center[1], 0],
+1
View File
@@ -11,6 +11,7 @@ export type CustomizeGeoJsonDataSource = string | object;
// 唯一配置项接口
export interface GeoJsonOptions {
showName?: boolean;
default: boolean;
labelStyle?: LabelConfig;
polygonStyle?: {
fill?: boolean;
+43 -3
View File
@@ -106,6 +106,16 @@ export class CesiumUtils {
this.#entityManager!.clearAllEntities(clearType)
}
/**
* 获取所有实体ID
* @param clearType - 类型:'default'=默认实体,'custom'=自定义实体,'all'=所有实体(默认 'all'
* @returns 实体 ID 集合
*/
getEntityIds(clearType: ClearType = 'all'): Set<string> {
this.#checkManager(this.#entityManager, 'EntityManager')
return this.#entityManager!.getEntityIds(clearType)
}
// ===================== Primitive 管理 =====================
/**
@@ -146,6 +156,16 @@ export class CesiumUtils {
this.#primitiveManager!.clearAllPrimitives(clearType)
}
/**
* 获取所有Primitive ID
* @param clearType - 类型:'default'=默认 Primitive'custom'=自定义 Primitive'all'=所有 Primitive(默认 'all'
* @returns Primitive ID 集合
*/
getPrimitiveIds(clearType: ClearType = 'all'): Set<string> {
this.#checkManager(this.#primitiveManager, 'PrimitiveManager')
return this.#primitiveManager!.getPrimitiveIds(clearType)
}
// ===================== 图层管理 =====================
/**
@@ -196,6 +216,16 @@ export class CesiumUtils {
this.#layerManager!.clearAllLayers(clearType)
}
/**
* 获取所有图层 Key
* @param clearType - 类型:'default'=默认图层,'custom'=自定义图层,'all'=所有图层(默认 'all'
* @returns 图层 Key 集合
*/
getLayerKeys(clearType: ClearType = 'all'): Set<string> {
this.#checkManager(this.#layerManager, 'LayerManager')
return this.#layerManager!.getLayerKeys(clearType)
}
// ===================== GeoJSON 图层管理 =====================
/**
@@ -243,14 +273,14 @@ export class CesiumUtils {
* @param isDefaults - 是否为默认图层数组
* @param options - 配置选项数组
*/
batchAddGeoJsonLayers(
async batchAddGeoJsonLayers(
layerIds: string[],
geojsonDatas: CustomizeGeoJsonDataSource[],
isDefaults: boolean[],
options?: GeoJsonOptions[]
): void {
): Promise<void> {
this.#checkManager(this.#geoJsonManager, 'GeoJsonManager')
this.#geoJsonManager!.batchAddGeoJsonLayers(layerIds, geojsonDatas, isDefaults, options)
await this.#geoJsonManager!.batchAddGeoJsonLayers(layerIds, geojsonDatas, isDefaults, options)
}
/**
@@ -331,6 +361,16 @@ export class CesiumUtils {
return this.#geoJsonManager!.getGeoJsonLayerVisibility(layerId)
}
/**
* 获取所有 GeoJSON 图层 ID
* @param clearType - 类型:'default'=默认图层,'custom'=自定义图层,'all'=所有图层(默认 'all'
* @returns GeoJSON 图层 ID 集合
*/
getGeoJsonLayerIds(clearType: ClearType = 'all'): Set<string> {
this.#checkManager(this.#geoJsonManager, 'GeoJsonManager')
return this.#geoJsonManager!.getGeoJsonLayerIds(clearType)
}
// ===================== 视角控制 =====================
/**
+30 -6
View File
@@ -32,6 +32,7 @@ export class GeoJsonManager {
// 默认配置
static readonly DEFAULT_OPTIONS: Required<GeoJsonOptions> = {
showName: false,
default: false,
labelStyle: {
labelFont: '16px "微软雅黑"',
labelColor: Color.RED,
@@ -70,7 +71,7 @@ export class GeoJsonManager {
* 添加 GeoJSON 图层
* @param layerId - 图层唯一标识
* @param geojsonData - GeoJSON 数据(路径、URL 或对象)
* @param isDefault - 是否为默认图层(默认 false)
* @param isDefault - 是否为默认图层(默认 false,优先级高于 options.default
* @param options - 配置选项(样式、标签等)
* @returns Promise<DataSource> 数据源实例
*/
@@ -82,6 +83,9 @@ export class GeoJsonManager {
): Promise<DataSource> {
if (this.#exists(layerId)) throw new Error(`图层 ${layerId} 已存在`)
const opt = this.#mergeOptions(options)
// 优先使用 isDefault 参数,其次使用 options.default
const finalIsDefault = isDefault || opt.default
// 加载并应用样式
const dataSource = await GeoJsonDataSource.load(geojsonData)
@@ -89,7 +93,7 @@ export class GeoJsonManager {
// 添加到地图
await this.#viewer.dataSources.add(dataSource)
isDefault
finalIsDefault
? this.#defaultGeoJsonMap.set(layerId, dataSource)
: this.#customGeoJsonMap.set(layerId, dataSource)
@@ -145,14 +149,16 @@ export class GeoJsonManager {
* @param isDefaults - 是否为默认图层数组
* @param options - 配置选项数组
*/
batchAddGeoJsonLayers(
async batchAddGeoJsonLayers(
layerIds: string[],
geojsonDatas: CustomizeGeoJsonDataSource[],
isDefaults: boolean[],
options?: GeoJsonOptions[],
): void {
layerIds.forEach((id, index) =>
this.addGeoJsonLayer(id, geojsonDatas?.[index], isDefaults?.[index], options?.[index]),
): Promise<void> {
await Promise.all(
layerIds.map((id, index) =>
this.addGeoJsonLayer(id, geojsonDatas?.[index], isDefaults?.[index], options?.[index])
)
)
}
@@ -255,6 +261,15 @@ export class GeoJsonManager {
return ds ? ds.show : null
}
/**
* 获取所有 GeoJSON 图层 ID
* @param clearType - 类型:'default'=默认图层,'custom'=自定义图层,'all'=所有图层(默认 'all'
* @returns GeoJSON 图层 ID 集合
*/
getGeoJsonLayerIds(clearType: ClearType = 'all'): Set<string> {
return this.#getTargetIdsByType(clearType)
}
// ===================== 私有方法 =====================
/** 图层是否存在 */
@@ -384,4 +399,13 @@ export class GeoJsonManager {
#convertPosition(pos: Cartesian3 | [number, number, number]): Cartesian3 {
return Array.isArray(pos) ? Cartesian3.fromDegrees(pos[0], pos[1], pos[2] || 0) : pos
}
#getTargetIdsByType(clearType: ClearType): Set<string> {
const targetIds = new Set<string>()
if (clearType === 'default' || clearType === 'all')
this.#defaultGeoJsonMap.forEach((_, key) => targetIds.add(key))
if (clearType === 'custom' || clearType === 'all')
this.#customGeoJsonMap.forEach((_, key) => targetIds.add(key))
return targetIds
}
}
+18
View File
@@ -89,6 +89,15 @@ export class LayerManager {
this.#clearMapsByType(clearType)
}
/**
* 获取所有图层 Key
* @param clearType - 类型:'default'=默认图层,'custom'=自定义图层,'all'=所有图层(默认 'all'
* @returns 图层 Key 集合
*/
getLayerKeys(clearType: 'default' | 'custom' | 'all' = 'all'): Set<string> {
return this.#getTargetIdsByType(clearType)
}
// ===================== 私有方法 =====================
#validateUniqueLayerKey(key: string): void {
@@ -155,4 +164,13 @@ export class LayerManager {
if (clearType === 'default' || clearType === 'all') this.#defaultLayerMap.clear()
if (clearType === 'custom' || clearType === 'all') this.#customLayerMap.clear()
}
#getTargetIdsByType(clearType: 'default' | 'custom' | 'all'): Set<string> {
const targetIds = new Set<string>()
if (clearType === 'default' || clearType === 'all')
this.#defaultLayerMap.forEach((_, key) => targetIds.add(key))
if (clearType === 'custom' || clearType === 'all')
this.#customLayerMap.forEach((_, key) => targetIds.add(key))
return targetIds
}
}
+18
View File
@@ -83,6 +83,15 @@ export class PrimitiveManager {
this.#clearMapsByType(clearType)
}
/**
* 获取所有Primitive ID
* @param clearType - 类型:'default'=默认 Primitive'custom'=自定义 Primitive'all'=所有 Primitive(默认 'all'
* @returns Primitive ID 集合
*/
getPrimitiveIds(clearType: 'default' | 'custom' | 'all' = 'all'): Set<string> {
return this.#getTargetIdsByType(clearType)
}
// ===================== 私有方法 =====================
#groupPrimitivesByType(primitives: PrimitiveOptions[]) {
@@ -266,6 +275,15 @@ export class PrimitiveManager {
if (clearType === 'custom' || clearType === 'all') this.#customPrimitiveMap.clear()
}
#getTargetIdsByType(clearType: 'default' | 'custom' | 'all'): Set<string> {
const targetIds = new Set<string>()
if (clearType === 'default' || clearType === 'all')
this.#defaultPrimitiveMap.forEach((_, key) => targetIds.add(key))
if (clearType === 'custom' || clearType === 'all')
this.#customPrimitiveMap.forEach((_, key) => targetIds.add(key))
return targetIds
}
#convertPosition(pos: Cartesian3 | [number, number, number]): Cartesian3 {
return Array.isArray(pos) ? Cartesian3.fromDegrees(pos[0], pos[1], pos[2] || 0) : pos
}