148 lines
4.4 KiB
JavaScript
148 lines
4.4 KiB
JavaScript
/**
|
||
* @name: index
|
||
* @author: Administrator
|
||
* @date: 2023-11-20 15:51
|
||
* @description:index
|
||
* @update: 2023-11-20 15:51
|
||
*/
|
||
import { getHost } from "../../../../../on";
|
||
import { syncData } from '../../../../../Global/MultiViewportMode'
|
||
import BaseLayer from "../index";
|
||
import { setSplitDirection, setActiveId } from '../../../../../Global/SplitScreen'
|
||
|
||
|
||
class Layer extends BaseLayer {
|
||
constructor(sdk, options = {}) {
|
||
super(sdk, options)
|
||
this.object = {}
|
||
this.options.host = this.options.host || getHost()
|
||
|
||
}
|
||
|
||
get type() {
|
||
return "layer"
|
||
}
|
||
|
||
on() {
|
||
return this.add()
|
||
}
|
||
|
||
|
||
async add() {
|
||
let res = await this.requestResource()
|
||
let text = await res.text()
|
||
text = JSON.parse(text)
|
||
if ([0, 200].includes(text.code)) {
|
||
return this.loadLayer(text.data)
|
||
} else {
|
||
return new Promise((res, reject) => {
|
||
reject(text.msg || text.message)
|
||
})
|
||
}
|
||
}
|
||
|
||
async loadLayer(data) {
|
||
this.object = { ...data }
|
||
let url = ""
|
||
if (this.object.url.startsWith("http"))
|
||
url = this.object.url
|
||
else {
|
||
if (this.options.host) {
|
||
let o = new URL(this.object.url, this.options.host)
|
||
url = o.href
|
||
} else
|
||
url = this.object.url
|
||
}
|
||
let params = {
|
||
url: url,
|
||
mimmumLevel: this.object.minimumLevel,
|
||
maximumLevel: this.object.maximumLevel,
|
||
rectangle: new Cesium.Rectangle(
|
||
Cesium.Math.toRadians(this.object.west),
|
||
Cesium.Math.toRadians(this.object.south),
|
||
Cesium.Math.toRadians(this.object.east),
|
||
Cesium.Math.toRadians(this.object.north)
|
||
),
|
||
}
|
||
// if (this.object.scheme_name === "GeographicTilingScheme") {
|
||
// console.log("添加GeographicTilingScheme")
|
||
// params.tilingScheme = new Cesium.GeographicTilingScheme()
|
||
// }
|
||
// if (this.object.scheme_name === "amapMercatorTilingScheme") {
|
||
// console.log("添加amapMercatorTilingScheme")
|
||
// params.tilingScheme = this.amapMercatorTilingScheme()
|
||
// }
|
||
|
||
let layer
|
||
// if (this.object.tiletrans === 'tms') {
|
||
// params.url = params.url.substr(0, params.url.indexOf('{'))
|
||
// tms = new Cesium.TileMapServiceImageryProvider(params)
|
||
// } else {
|
||
// tms = new Cesium.UrlTemplateImageryProvider(params)
|
||
// }
|
||
switch (this.object.scheme_name) {
|
||
case "amapMercatorTilingScheme":
|
||
params.tilingScheme = this.amapMercatorTilingScheme()
|
||
break;
|
||
case "":
|
||
break;
|
||
default:
|
||
params.tilingScheme = new Cesium[this.object.scheme_name]()
|
||
break;
|
||
}
|
||
switch (this.object.load_method) {
|
||
case "tms":
|
||
if(this.object.url.endsWith("tilemapresource.xml")){
|
||
let arr = this.object.url.split("/")
|
||
arr.pop()
|
||
let url = arr.join("/")
|
||
params.url = url
|
||
}
|
||
if (Number(Cesium.VERSION.split('.')[1]) >= 107) {
|
||
layer = await Cesium.TileMapServiceImageryProvider.fromUrl(params.url, params);
|
||
}
|
||
else {
|
||
layer = new Cesium.TileMapServiceImageryProvider(params)
|
||
}
|
||
break;
|
||
case "xyz":
|
||
layer = new Cesium.UrlTemplateImageryProvider(params)
|
||
break;
|
||
case "wmts":
|
||
layer = new Cesium.WebMapTileServiceImageryProvider(params)
|
||
break;
|
||
default:
|
||
layer = new Cesium.UrlTemplateImageryProvider(params)
|
||
break;
|
||
}
|
||
|
||
if(!this.sdk || !this.sdk.viewer) {
|
||
return
|
||
}
|
||
if (this.options.hasOwnProperty("layer_index")) {
|
||
this.entity =
|
||
this.sdk.viewer.scene.imageryLayers.addImageryProvider(layer, this.options.layer_index)
|
||
} else {
|
||
this.entity =
|
||
this.sdk.viewer.scene.imageryLayers.addImageryProvider(layer,)
|
||
}
|
||
this.entity._id = this.options.id
|
||
for (let i = 0; i < this.sdk.viewer.imageryLayers._layers.length; i++) {
|
||
if (this.sdk.viewer.imageryLayers._layers[i]._imageryProvider && this.sdk.viewer.imageryLayers._layers[i]._imageryProvider._type && (this.sdk.viewer.imageryLayers._layers[i]._imageryProvider._type === 'flw' || this.sdk.viewer.imageryLayers._layers[i]._imageryProvider._type === 'jww')) {
|
||
let layer = this.sdk.viewer.imageryLayers._layers[i]
|
||
this.sdk.viewer.imageryLayers.raiseToTop(layer)
|
||
}
|
||
}
|
||
this.show = this.options.show
|
||
this.alpha = this.options.alpha
|
||
this.brightness = this.options.brightness
|
||
|
||
if(this.options.show) {
|
||
setSplitDirection(0, this.options.id)
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
export default Layer
|