修改地图加载细节
This commit is contained in:
@@ -45,13 +45,11 @@ onMounted(() => {
|
|||||||
CesiumUtilsSingleton.batchAddGeoJsonLayers(
|
CesiumUtilsSingleton.batchAddGeoJsonLayers(
|
||||||
areasId,
|
areasId,
|
||||||
areas,
|
areas,
|
||||||
new Array(areas.length).fill(true),
|
|
||||||
areas.map((area, index) => {
|
areas.map((area, index) => {
|
||||||
const areaName = area.features[0].properties.name;
|
const areaName = area.features[0].properties.name;
|
||||||
console.log(areaName);
|
|
||||||
return {
|
return {
|
||||||
showName: true,
|
showName: true,
|
||||||
default: true,
|
isDefault: true,
|
||||||
labelStyle: {
|
labelStyle: {
|
||||||
labelText: areaName,
|
labelText: areaName,
|
||||||
center: [area.features[0].properties.center[0], area.features[0].properties.center[1], 0],
|
center: [area.features[0].properties.center[0], area.features[0].properties.center[1], 0],
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export interface EntityOptions {
|
|||||||
id: string // 实体唯一标识(必填,用于后续查询/删除)
|
id: string // 实体唯一标识(必填,用于后续查询/删除)
|
||||||
position: Cartesian3 | [number, number, number] // 位置(经纬度高程数组 或 Cartesian3)
|
position: Cartesian3 | [number, number, number] // 位置(经纬度高程数组 或 Cartesian3)
|
||||||
type: 'point' | 'polyline' | 'billboard' | 'polygon' // 实体类型
|
type: 'point' | 'polyline' | 'billboard' | 'polygon' // 实体类型
|
||||||
default?: boolean // 是否是默认的实体,默认值false
|
isDefault?: boolean // 是否为默认实体,默认值false
|
||||||
// 点配置(type='point' 时必填)
|
// 点配置(type='point' 时必填)
|
||||||
pointOptions?: {
|
pointOptions?: {
|
||||||
color?: Color // 颜色(默认:红色)
|
color?: Color // 颜色(默认:红色)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export type CustomizeGeoJsonDataSource = string | object;
|
|||||||
// 唯一配置项接口
|
// 唯一配置项接口
|
||||||
export interface GeoJsonOptions {
|
export interface GeoJsonOptions {
|
||||||
showName?: boolean;
|
showName?: boolean;
|
||||||
default: boolean;
|
isDefault?: boolean;
|
||||||
labelStyle?: LabelConfig;
|
labelStyle?: LabelConfig;
|
||||||
polygonStyle?: {
|
polygonStyle?: {
|
||||||
fill?: boolean;
|
fill?: boolean;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export interface LayerConfig {
|
|||||||
url: string // 图层地址
|
url: string // 图层地址
|
||||||
layers: string // 图层名称
|
layers: string // 图层名称
|
||||||
|
|
||||||
default?: boolean // 是否是默认图层,默认值false
|
isDefault?: boolean // 是否为默认图层,默认值false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WMTS 图层参数
|
* WMTS 图层参数
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ export interface PrimitiveOptions {
|
|||||||
id: string
|
id: string
|
||||||
type: 'point' | 'polyline' | 'polygon' | 'billboard'
|
type: 'point' | 'polyline' | 'polygon' | 'billboard'
|
||||||
positions: [number, number, number][] | Cartesian3[] // 点集合,线和面需要多个点
|
positions: [number, number, number][] | Cartesian3[] // 点集合,线和面需要多个点
|
||||||
default?: boolean // 是否是默认的图元,默认值false
|
isDefault?: boolean // 是否为默认图元,默认值false
|
||||||
color?: Color
|
color?: Color
|
||||||
pixelSize?: number // 点大小
|
pixelSize?: number // 点大小
|
||||||
width?: number // 线宽
|
width?: number // 线宽
|
||||||
|
|||||||
@@ -270,17 +270,15 @@ export class CesiumUtils {
|
|||||||
* 批量添加GeoJSON图层
|
* 批量添加GeoJSON图层
|
||||||
* @param layerIds - 图层 ID 数组
|
* @param layerIds - 图层 ID 数组
|
||||||
* @param geojsonDatas - GeoJSON 数据数组
|
* @param geojsonDatas - GeoJSON 数据数组
|
||||||
* @param isDefaults - 是否为默认图层数组
|
* @param options - 配置选项数组(包含 isDefault)
|
||||||
* @param options - 配置选项数组
|
|
||||||
*/
|
*/
|
||||||
async batchAddGeoJsonLayers(
|
async batchAddGeoJsonLayers(
|
||||||
layerIds: string[],
|
layerIds: string[],
|
||||||
geojsonDatas: CustomizeGeoJsonDataSource[],
|
geojsonDatas: CustomizeGeoJsonDataSource[],
|
||||||
isDefaults: boolean[],
|
|
||||||
options?: GeoJsonOptions[]
|
options?: GeoJsonOptions[]
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
this.#checkManager(this.#geoJsonManager, 'GeoJsonManager')
|
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 实例
|
* @returns 创建的 Entity 实例
|
||||||
*/
|
*/
|
||||||
addCesiumEntity(entityOptions: EntityOptions): 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 (!id) throw new Error('实体 id 为必填项')
|
||||||
if (!position) throw new Error('实体 position 为必填项')
|
if (!position) throw new Error('实体 position 为必填项')
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export class GeoJsonManager {
|
|||||||
// 默认配置
|
// 默认配置
|
||||||
static readonly DEFAULT_OPTIONS: Required<GeoJsonOptions> = {
|
static readonly DEFAULT_OPTIONS: Required<GeoJsonOptions> = {
|
||||||
showName: false,
|
showName: false,
|
||||||
default: false,
|
isDefault: false,
|
||||||
labelStyle: {
|
labelStyle: {
|
||||||
labelFont: '16px "微软雅黑"',
|
labelFont: '16px "微软雅黑"',
|
||||||
labelColor: Color.RED,
|
labelColor: Color.RED,
|
||||||
@@ -84,8 +84,7 @@ export class GeoJsonManager {
|
|||||||
if (this.#exists(layerId)) throw new Error(`图层 ${layerId} 已存在`)
|
if (this.#exists(layerId)) throw new Error(`图层 ${layerId} 已存在`)
|
||||||
const opt = this.#mergeOptions(options)
|
const opt = this.#mergeOptions(options)
|
||||||
|
|
||||||
// 优先使用 isDefault 参数,其次使用 options.default
|
const finalIsDefault = isDefault || opt.isDefault
|
||||||
const finalIsDefault = isDefault || opt.default
|
|
||||||
|
|
||||||
// 加载并应用样式
|
// 加载并应用样式
|
||||||
const dataSource = await GeoJsonDataSource.load(geojsonData)
|
const dataSource = await GeoJsonDataSource.load(geojsonData)
|
||||||
@@ -146,18 +145,16 @@ export class GeoJsonManager {
|
|||||||
* 批量添加GeoJSON图层
|
* 批量添加GeoJSON图层
|
||||||
* @param layerIds - 图层 ID 数组
|
* @param layerIds - 图层 ID 数组
|
||||||
* @param geojsonDatas - GeoJSON 数据数组
|
* @param geojsonDatas - GeoJSON 数据数组
|
||||||
* @param isDefaults - 是否为默认图层数组
|
* @param options - 配置选项数组(包含 isDefault)
|
||||||
* @param options - 配置选项数组
|
|
||||||
*/
|
*/
|
||||||
async batchAddGeoJsonLayers(
|
async batchAddGeoJsonLayers(
|
||||||
layerIds: string[],
|
layerIds: string[],
|
||||||
geojsonDatas: CustomizeGeoJsonDataSource[],
|
geojsonDatas: CustomizeGeoJsonDataSource[],
|
||||||
isDefaults: boolean[],
|
|
||||||
options?: GeoJsonOptions[],
|
options?: GeoJsonOptions[],
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
layerIds.map((id, index) =>
|
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
|
* @returns 创建的 ImageryLayer 实例,失败则返回 null
|
||||||
*/
|
*/
|
||||||
createLayer(layerConfig: LayerConfig): 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 参数未定义')
|
if (!layerKey) throw new Error('layers 参数未定义')
|
||||||
this.#validateUniqueLayerKey(layerKey)
|
this.#validateUniqueLayerKey(layerKey)
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ export class PrimitiveManager {
|
|||||||
|
|
||||||
#storePrimitives(options: PrimitiveOptions[], primitive: Primitive | BillboardCollection): void {
|
#storePrimitives(options: PrimitiveOptions[], primitive: Primitive | BillboardCollection): void {
|
||||||
options.forEach((option) => {
|
options.forEach((option) => {
|
||||||
if (option.default) {
|
if (option.isDefault) {
|
||||||
this.#defaultPrimitiveMap.set(option.id, primitive)
|
this.#defaultPrimitiveMap.set(option.id, primitive)
|
||||||
} else {
|
} else {
|
||||||
this.#customPrimitiveMap.set(option.id, primitive)
|
this.#customPrimitiveMap.set(option.id, primitive)
|
||||||
|
|||||||
Reference in New Issue
Block a user