9 changed files with 13109 additions and 12765 deletions
File diff suppressed because one or more lines are too long
@ -0,0 +1,225 @@ |
|||||
|
const createXyzLayer = (data) => |
||||
|
new sycim.XyzLayer(data.id, { |
||||
|
...data, |
||||
|
maximumLevel: data.maximumLevel || 22 |
||||
|
}); |
||||
|
|
||||
|
const layerTypeEnum = { |
||||
|
'011100': 'BAIDU', |
||||
|
'012000': 'PRIMITIVE', |
||||
|
'013000': 'TILESET', |
||||
|
'014000': 'XYZ', |
||||
|
'030100': 'WMTS', |
||||
|
'030200': 'WMS', |
||||
|
'030300': 'WFS', |
||||
|
'030400': 'GEOJSON', |
||||
|
'050100': 'TDTWMTS', |
||||
|
'060100': 'XYZ', |
||||
|
'070100': 'BINGMAP', |
||||
|
'040003': 'WFS', |
||||
|
'021102': 'ARCGIS_DYNAMIC', |
||||
|
113200: 'S3M' |
||||
|
}; |
||||
|
|
||||
|
// 图层响应动作
|
||||
|
const layerActions = { |
||||
|
'030200': (data) => |
||||
|
new sycim.WmsLayer(data.id, { |
||||
|
...data, |
||||
|
url: data.url, |
||||
|
layer: data.layerTable, |
||||
|
parameters: { |
||||
|
version: '1.3.0' |
||||
|
} |
||||
|
}), |
||||
|
'030300': async (data) => { |
||||
|
const options = {}; |
||||
|
if (data.relationStyleId) { |
||||
|
const res = await getLayerStyle(data.relationStyleId); |
||||
|
options.styleConfig = res.information ? JSON.parse(res.information) : ''; |
||||
|
} |
||||
|
return new sycim.WfsLayer(data.id, data.url, data.layerTable, options); |
||||
|
}, |
||||
|
'030100': (data) => |
||||
|
new sycim.WmtsLayer(data.id, { |
||||
|
...data, |
||||
|
url: data.url, |
||||
|
layer: data.layerTable, |
||||
|
tileMatrixSetID: data.tileMatrixSet, |
||||
|
style: data.style || '' |
||||
|
}), |
||||
|
'030400': async (data) => { |
||||
|
const options = {}; |
||||
|
if (data.relationStyleId) { |
||||
|
const res = await getLayerStyle(data.relationStyleId); |
||||
|
options.styleConfig = res.information ? JSON.parse(res.information) : ''; |
||||
|
} |
||||
|
return new sycim.GeoJsonLayer(data.id, data.url, options); |
||||
|
}, |
||||
|
'011100': (data) => |
||||
|
new sycim.BaiduLayer(data.id, { |
||||
|
...data, |
||||
|
style: data.layerTable, |
||||
|
crs: 'WGS84' |
||||
|
}), |
||||
|
'050100': (data) => { |
||||
|
let url = `${data.proxyUrl}${data.url}`; |
||||
|
if (!url.includes('?tk=') && data.serviceToken) { |
||||
|
url = `${url}?tk=${data.serviceToken}`; |
||||
|
} |
||||
|
return new sycim.TdtWmtsLayer(data.id, { |
||||
|
...data, |
||||
|
url, |
||||
|
layer: data.layerTable, |
||||
|
tileMatrixSetID: data.tileMatrixSet, |
||||
|
spatialReference: { |
||||
|
wkid: data.epsg |
||||
|
} |
||||
|
}); |
||||
|
}, |
||||
|
'070100': (data) => |
||||
|
new sycim.BingMapLayer(data.id, { |
||||
|
...data |
||||
|
}), |
||||
|
'060100': createXyzLayer, |
||||
|
'014000': createXyzLayer, |
||||
|
'013000': (data) => new sycim.TilesetLayer(data.id), |
||||
|
'012000': (data) => new sycim.PrimitiveLayer(data.id), |
||||
|
'040003': (data) => |
||||
|
new sycim.WfsLayer(data.id, data.url, data.layerTable, { |
||||
|
cql_filter: data.filter, |
||||
|
propertyName: '*' |
||||
|
}), |
||||
|
'021102': (data) => |
||||
|
new sycim.ArcgisDynamicLayer(data.id, { |
||||
|
url: data.url |
||||
|
}) |
||||
|
}; |
||||
|
|
||||
|
//图层缩放
|
||||
|
function defaultZoomToLayer(data) { |
||||
|
const { mapParam } = data; |
||||
|
if (!mapParam?.tileCenter) return; |
||||
|
const p = mapParam.tileCenter.split(','); |
||||
|
window.viewer.flyToPosition(new sycim.Position(+p[0], +p[1], 500, 0, -90, 0)); |
||||
|
} |
||||
|
|
||||
|
// 根据图层类型缩放
|
||||
|
function zoomToLayerByType(data) { |
||||
|
const { id, layerType } = data; |
||||
|
if (!layerType) return; |
||||
|
const type = sycim.LayerType[layerTypeEnum[layerType]]; |
||||
|
const layer = window.viewer._layerCache[type][id]; |
||||
|
if (layer?.zoomToLayer) { |
||||
|
layer.zoomToLayer(); |
||||
|
} else { |
||||
|
defaultZoomToLayer(data); |
||||
|
} |
||||
|
} |
||||
|
const supermapTileLayer = {}; |
||||
|
function zoomToS3MLayer(data) { |
||||
|
if (supermapTileLayer[data.id]) { |
||||
|
Cesium.Resource.fetchJson(data.url + '/scenes.json').then(function (scenes) { |
||||
|
let sname = scenes && scenes[0].name; |
||||
|
Cesium.Resource.fetchJson(data.url + '/scenes/' + sname + '.json').then(function (jsonData) { |
||||
|
var cameraPosition = jsonData.camera; |
||||
|
var tilt = Cesium.Math.toRadians(cameraPosition.tilt - 90); |
||||
|
//设置相机位置、视角,便于观察场景
|
||||
|
window.viewer.scene.camera.setView({ |
||||
|
destination: new Cesium.Cartesian3.fromDegrees( |
||||
|
cameraPosition.longitude, |
||||
|
cameraPosition.latitude, |
||||
|
cameraPosition.altitude |
||||
|
), |
||||
|
orientation: { |
||||
|
heading: cameraPosition.heading, |
||||
|
pitch: tilt, |
||||
|
roll: 0 |
||||
|
} |
||||
|
}); |
||||
|
}); |
||||
|
}); |
||||
|
} else { |
||||
|
alert('请先加载s3m图层'); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 图层缩放响应动作
|
||||
|
const zoomToLayerActions = { |
||||
|
'030200': zoomToLayerByType, |
||||
|
'030300': zoomToLayerByType, |
||||
|
'030100': zoomToLayerByType, |
||||
|
'030400': zoomToLayerByType, |
||||
|
'011100': zoomToLayerByType, |
||||
|
'050100': zoomToLayerByType, |
||||
|
'070100': zoomToLayerByType, |
||||
|
'060100': zoomToLayerByType, |
||||
|
'014000': zoomToLayerByType, |
||||
|
'013000': zoomToLayerByType, |
||||
|
'012000': (data) => { |
||||
|
// modal
|
||||
|
const { modelInitPosition } = data; |
||||
|
if (!modelInitPosition) return; |
||||
|
const p = JSON.parse(modelInitPosition); |
||||
|
window.viewer.flyToPosition(new sycim.Position(p.lng, p.lat, p.alt + 500, 0, -90, 0)); |
||||
|
}, |
||||
|
'040003': zoomToLayerByType, |
||||
|
'021102': zoomToLayerByType, |
||||
|
113200: zoomToS3MLayer |
||||
|
}; |
||||
|
|
||||
|
// 添加图层
|
||||
|
export async function addLayer(layerData) { |
||||
|
const { layerType, url, id } = layerData; |
||||
|
let action = null; |
||||
|
if (layerType === '113200') { |
||||
|
if (supermapTileLayer[id]) { |
||||
|
supermapTileLayer[id].show = true; |
||||
|
} else { |
||||
|
const layerPromise = window.viewer.scene.open(url, { |
||||
|
autoSetView: false //不自动定位
|
||||
|
}); |
||||
|
layerPromise.then((layer) => { |
||||
|
supermapTileLayer[id] = layer?.[0]; |
||||
|
}); |
||||
|
} |
||||
|
return; |
||||
|
} |
||||
|
if (!layerType || !(action = layerActions[layerType])) return; |
||||
|
const layer = await action(layerData); |
||||
|
layer && window.viewer.addLayer(layer); |
||||
|
if (['013000'].includes(layerType)) { |
||||
|
// 3d tiles
|
||||
|
const tileset = new sycim.Tileset(url); |
||||
|
tileset.id = layerData.id; |
||||
|
layer.addGraphic(tileset); |
||||
|
} else if (['012000'].includes(layerType)) { |
||||
|
// modal
|
||||
|
if (!layerData.modelInitPosition) return; |
||||
|
const p = JSON.parse(layerData.modelInitPosition); |
||||
|
const model = new sycim.ModelPrimitive(new sycim.Position(p.lng, p.lat, p.alt, p.heading, p.pitch, p.roll), url); |
||||
|
model.id = layerData.id; |
||||
|
layer.addGraphic(model); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export function removeLayer(layerData) { |
||||
|
const { id, layerType } = layerData; |
||||
|
if (!layerType) return; |
||||
|
const type = layerTypeEnum[layerType]; |
||||
|
if (layerType === '113200') { |
||||
|
if (supermapTileLayer[id]) { |
||||
|
supermapTileLayer[id].show = false; |
||||
|
} |
||||
|
} else { |
||||
|
window.viewer.removeLayer({ |
||||
|
id, |
||||
|
type: sycim.LayerType[type] |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export function zoomToLayer(data) { |
||||
|
const { layerType } = data; |
||||
|
zoomToLayerActions[layerType]?.(data); |
||||
|
} |
Loading…
Reference in new issue