代码迁移

This commit is contained in:
zh
2025-07-03 13:54:01 +08:00
parent b04de8a084
commit 2a4da33e62
985 changed files with 358292 additions and 13 deletions

View File

@ -0,0 +1,88 @@
import { getHost, getToken } from "../../../on";
import BaseLoadObjModel from '../../../Obj/Base/LoadObjModel'
import LoadObjModel from '../LoadObjModel'
export default class BatchLoadObjModel {
constructor(sdk, options = {}) {
this.sdk = sdk
this.options = { ...options }
this.options.show = (options.show || options.show === false) ? options.show : true
this.options.host = this.options.host || getHost()
this.objModelObject = []
this._loaded = false
this._loadEvent = void 0
this.on()
}
get show() {
return this.options.show
}
set show(v) {
if (typeof v === "boolean") {
this.options.show = v
for (let i = 0; i < this.objModelObject.length; i++) {
this.objModelObject[i].load(() => {
this.objModelObject[i].show = v
})
}
} else {
console.error("参数必须为boolean")
}
}
async on() {
let url = ""
if (this.options.host.endsWith("yjearth4.0"))
url = this.options.host + '/api/v1/source/obj'
else
url = this.options.host + '/yjearth4.0/api/v1/source/obj'
if (this.options.code) {
url = url + '?code=' + this.options.code
}
const res = await fetch(url, {
method: 'get',
headers: {
'Content-Type': 'application/json',
"token": getToken(),
"Authorization": "Bearer " + getToken(),
}
});
if (res.ok) {
this.objModelObject = []
this.list = (await res.json()).data;
if (this.options.count) {
this.list = this.list.splice(0, this.options.count)
}
for (let i = 0; i < this.list.length; i++) {
let options = JSON.parse(this.list[i].detail)
options.host = this.options.host
if (this.options.show || this.options.show === false) {
options.show = this.options.show
}
let object = new LoadObjModel(this.sdk, options);
this.objModelObject.push(object)
}
this._loaded = true
if (this._loadEvent) {
this._loadEvent()
}
}
}
remove() {
for (let i = 0; i < this.objModelObject.length; i++) {
this.objModelObject[i].load(() => {
this.objModelObject[i].remove()
})
}
}
load(callback) {
if (this._loaded) {
callback();
}
else {
this._loadEvent = callback
}
}
}

View File

@ -0,0 +1,180 @@
import AModelLoader from '../../../Obj/Base/LoadObjModel/AModelLoader'
import { getHost, getToken } from "../../../on";
import BaseLoadObjModel from '../../../Obj/Base/LoadObjModel'
export default class LoadObjModel extends BaseLoadObjModel {
constructor(sdk, options, CallBack) {
super(sdk, options, CallBack)
this._loadEvent = void 0
this._loaded = false
this.options.objId = options.objId
this.options.videoId = options.videoId
this.options.videoType = options.videoType || 'flv'
}
async addResource() {
let that = this
that.options.xmlURL = that.options.objUrl.replace('.obj', '.xml')
if (that.options.xmlURL !== '') {
const xml = await fetch(that.options.xmlURL)
if (xml.ok) {
const xmlString = await xml.text()
const parser = new DOMParser()
const xmlDoc = parser.parseFromString(xmlString, 'text/xml')
// console.log('xmlDocxmlDocxmlDoc', xmlDoc)
const position = xmlDoc
.getElementsByTagName('Position')[0]
.textContent.split(',')
// const bbox = xmlDoc.getElementsByTagName('bbox')[0]
const crs = xmlDoc.getElementsByTagName('Crs')[0].textContent
const result = that.convert(
[{ x: position[0], y: position[1], z: position[2] }],
crs,
'EPSG:4326'
)
that.options.position = that.options.position || { lng: result.points[0].x, lat: result.points[0].y, alt: result.points[0].z }
that.ControllerObject.position = that.options.position
const scene = that.viwer.scene
const origin = Cesium.Cartesian3.fromDegrees(
that.options.position.lng,
that.options.position.lat,
that.options.position.alt
)
const obj_modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(
origin,
new Cesium.HeadingPitchRoll(
Cesium.Math.toRadians(0.85),
Cesium.Math.toRadians(0),
Cesium.Math.toRadians(0)
)
)
let objLoader = new AModelLoader(that.viwer.scene.context)
let obj = await objLoader.Load(that.options.objUrl, that.options.videoId, that.options.host)
obj.modelMatrix = obj_modelMatrix
obj.show = that.options.show
obj.setFlvVideo(that.options.videoUrl)
scene.primitives.add(obj)
that.primitive = obj
that.controllerCallBack({
rotate: { x: that.options.roll, y: -that.options.pitch, z: -that.options.heading },
position: { ...that.options.position }
})
that.loaded = true
that._loaded = true
if (that._loadEvent) {
that._loadEvent()
}
}
} else {
return
}
if (that.options.objUrl === '') {
return
}
}
async requestResource() {
let that = this
if(!that._loaded) {
if(that.options.objId) {
that.options.objUrl = await that.requestObjResource()
}
if(that.options.videoId) {
that.options.videoUrl = await that.requestVideoResource()
}
await that.addResource()
}
}
requestObjResource() {
let host = ""
if (this.options.host.endsWith("yjearth4.0"))
host = this.options.host
else
host = this.options.host + '/yjearth4.0'
let url = host + '/obj/' + this.options.objId
return fetch(url, {
method: 'get',
headers: {
'Content-Type': 'application/json',
"token": getToken(),
"Authorization": "Bearer " + getToken(),
}
}).then(async (res) => {
let text = await res.text()
text = JSON.parse(text)
if ([0, 200].includes(text.code)) {
if (text.data.objPath.length)
return host + '/obj/wirte/file/' + text.data.objPath
else
console.warn('资源不存在')
return
} else {
console.warn(text.msg || text.message)
return
}
})
}
requestVideoResource() {
let host = ""
if (this.options.host.endsWith("yjearth4.0"))
host = this.options.host
else
host = this.options.host + '/yjearth4.0'
let url = host + '/videoFusion/' + this.options.videoId
return fetch(url, {
method: 'get',
headers: {
'Content-Type': 'application/json',
"token": getToken(),
"Authorization": "Bearer " + getToken(),
}
}).then(async (res) => {
let text = await res.text()
text = JSON.parse(text)
if ([0, 200].includes(text.code)) {
if (text.data.deviceCode.length) {
return fetch(host+'/videoFusion/vide/stream', {
method: 'post',
body: JSON.stringify({type: 'flv', deviceCode: text.data.deviceCode}),
headers: {
'Content-Type': 'application/json',
"token": getToken(),
"Authorization": "Bearer " + getToken(),
}
}).then(async (res2) => {
let text2 = await res2.text()
text2 = JSON.parse(text2)
if ([0, 200].includes(text2.code)) {
if (text2.data.flv && text2.data.flv.length) {
return text2.data.flv
}
else
console.warn('地址不存在')
return
} else {
console.warn(text2.msg || text2.message)
return
}
})
}
else
console.warn('设备不存在')
return
} else {
console.warn(text.msg || text.message)
return
}
})
}
load(callback) {
if (this._loaded) {
callback();
}
else {
this._loadEvent = callback
}
}
}