88 lines
3.2 KiB
JavaScript
Raw Normal View History

2025-11-19 13:41:02 +08:00
import { getBaseMap, getBusinessMap } from '@/views/cockpit/api/commonHttp.js'
import * as Cesium from 'cesium'
2025-11-18 17:53:04 +08:00
// 当前页面的最基础地图服务
// 主要是加载地图底图
export const useMapBase = (mapStore) => {
2025-11-19 13:41:02 +08:00
// 加载当前业务的底图, 类似于天地图,但是没有使用天地图作为底图,有大的地块的地形纹理,但是缩小范围很小,属于比较粗的图
const loadBaseMap = async () => {
2025-11-18 17:53:04 +08:00
const layerService = mapStore.services().layer
2025-11-19 13:41:02 +08:00
const res = await getBaseMap()
const data = [...res.data]
2025-11-18 17:53:04 +08:00
mapStore.baseMapGroups = data
for (const item of data) {
const layers = mapStore.getBaseMapLayersForGroup(item.Attribute?.rid || item.Rid)
for (const layerConfig of layers) {
const layer = {
id: layerConfig.id,
type: layerConfig.type,
url: layerConfig.url,
meta: layerConfig.meta,
2025-11-18 19:19:30 +08:00
options: {
2025-11-19 13:41:02 +08:00
// 瓦片方案必传由于cesium版本较老必传
tilingScheme: new Cesium.WebMercatorTilingScheme(),
maximumLevel: 18, // 限制最大级别以匹配 GWC 缓存尺度,避免分辨率不匹配错误
extraParameters: {
2025-11-18 19:19:30 +08:00
srs: 'EPSG:3857',
}
}
2025-11-18 17:53:04 +08:00
}
await layerService.addLayer(layer)
}
}
2025-11-18 19:19:30 +08:00
}
2025-11-18 17:53:04 +08:00
2025-11-19 13:41:02 +08:00
// 处理启动加载的图层
const collectBootLoadLayers = (nodes, layers = [], parent = null) => {
nodes.forEach(node => {
if (node.Attribute?.servicePath && node.Attribute.bootLoad === 1) {
// 确保 bootLoad 图层包含正确的 parentSortIndex
const layerWithParentSort = {
...node,
parentSortIndex: parent?.Attribute?.sortValue
};
layers.push(layerWithParentSort);
}
if (node.Children) {
collectBootLoadLayers(node.Children, layers, node);
}
});
return layers;
};
// 加载业务地图,业务地图主要是高亮当前业务下的地区的区县,边界都会有高亮线条
const loadBusinessMap = async () => {
2025-11-18 19:19:30 +08:00
const layerService = mapStore.services().layer
2025-11-19 13:41:02 +08:00
const res = await getBusinessMap()
const resData = res.data
const data = collectBootLoadLayers(resData)
resData[0].Children = data
mapStore.baseMapGroups = resData
for (const item of resData) {
2025-11-18 19:19:30 +08:00
const layers = mapStore.getBaseMapLayersForGroup(item.Attribute?.rid || item.Rid)
for (const layerConfig of layers) {
const layer = {
id: layerConfig.id,
type: layerConfig.type,
url: layerConfig.url,
meta: layerConfig.meta,
}
await layerService.addLayer(layer)
}
}
2025-11-18 17:53:04 +08:00
}
const loadBaseData = () => {
setTimeout(() => {
2025-11-19 13:41:02 +08:00
loadBaseMap()
loadBusinessMap()
2025-11-18 17:53:04 +08:00
}, 0)
}
return {
loadBaseData
}
}