修改地图加载细节
This commit is contained in:
@@ -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],
|
||||
|
||||
@@ -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 // 颜色(默认:红色)
|
||||
|
||||
@@ -11,7 +11,7 @@ export type CustomizeGeoJsonDataSource = string | object;
|
||||
// 唯一配置项接口
|
||||
export interface GeoJsonOptions {
|
||||
showName?: boolean;
|
||||
default: boolean;
|
||||
isDefault?: boolean;
|
||||
labelStyle?: LabelConfig;
|
||||
polygonStyle?: {
|
||||
fill?: boolean;
|
||||
|
||||
@@ -6,7 +6,7 @@ export interface LayerConfig {
|
||||
url: string // 图层地址
|
||||
layers: string // 图层名称
|
||||
|
||||
default?: boolean // 是否是默认图层,默认值false
|
||||
isDefault?: boolean // 是否为默认图层,默认值false
|
||||
|
||||
/**
|
||||
* WMTS 图层参数
|
||||
|
||||
@@ -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 // 线宽
|
||||
|
||||
@@ -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<void> {
|
||||
this.#checkManager(this.#geoJsonManager, 'GeoJsonManager')
|
||||
await this.#geoJsonManager!.batchAddGeoJsonLayers(layerIds, geojsonDatas, isDefaults, options)
|
||||
await this.#geoJsonManager!.batchAddGeoJsonLayers(layerIds, geojsonDatas, options)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 为必填项')
|
||||
|
||||
@@ -32,7 +32,7 @@ export class GeoJsonManager {
|
||||
// 默认配置
|
||||
static readonly DEFAULT_OPTIONS: Required<GeoJsonOptions> = {
|
||||
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<void> {
|
||||
await Promise.all(
|
||||
layerIds.map((id, index) =>
|
||||
this.addGeoJsonLayer(id, geojsonDatas?.[index], isDefaults?.[index], options?.[index])
|
||||
this.addGeoJsonLayer(id, geojsonDatas?.[index], false, options?.[index])
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user