代码迁移

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,191 @@
/**
* @name: index
* @author: Administrator
* @date: 2023-03-04 10:39
* @descriptionindex
* @update: 2023-03-04 10:39
*/
import { getHost, getToken } from "../../../on";
import Base from '../index'
import Tools from '../../../Tools'
import { setActiveViewer, closeRotateAround, closeViewFollow} from '../../../Global/global'
class GeoJson extends Base {
/**
* @constructor
* @param sdk
* @param options {object} 参数
* @param options.id {string} id
* @param options.url {string} geojson地址
* @param [options.color=#ef0606] {string} 线条颜色
* @param [options.width=1] {number} 线条宽度
* @example new YJ.Obj.GeoJson(earth,{id:"123",url:""})
* */
constructor(sdk, options = {}) {
super(sdk, options)
this.primitive = undefined
this.positions = []
this.loading = true
}
setDefaultValue() {
super.setDefaultValue()
this.options.host = this.options.host || getHost()
// let url = this.options.url
// if (this.options.host) {
// let o = new URL(this.options.url, this.options.host)
// url = o.href
// }
// this.options.url = url
this.options.color = this.options.color || 'rgb(239, 6, 6, 1)'
this.options.width = this.options.width || 1
}
get show() {
return this.options.show
}
set show(status) {
this.options.show = status
if (this.entity) {
for (let i = 0; i < this.entity.entities.values.length; i++) {
this.entity.entities.values[i].show = status
}
}
}
async on() {
let url = ""
if (this.options.host.endsWith("yjearth4.0"))
url = this.options.host + '/data/service/getFile'
else
url = this.options.host + '/yjearth4.0/data/service/getFile'
url = url + '?path=' + encodeURIComponent(this.options.url)
let rsp = await fetch(url, {
method: 'get',
headers: {
'Content-Type': 'application/json',
"token": getToken(),
"Authorization": "Bearer " + getToken(),
}
})
let json = await rsp.json()
this.geojson = json
return GeoJson.addDataToGlobe(this, json.features)
}
/*geojosn暂时只用线的形式*/
static addDataToGlobe(that) {
const geoJsonDataSource = new Cesium.GeoJsonDataSource();
let geojson = that.deepCopyObj(that.geojson)
for (let i = 0; i < geojson.features.length; i++) {
if (!geojson.features[i].id) {
geojson.features[i].id = that.options.id + '_' + i
}
}
// console.log(geojson)
let promise = geoJsonDataSource.load(geojson, {
clampToGround: true,
});
return promise.then(datasource => {
that.entity = datasource
datasource.entities.values.forEach(enetity => {
// console.log(enetity)
let color = Cesium.Color.fromCssColorString(that.options.color)
let colorPolygon = color.withAlpha(0.2)
enetity.show = that.options.show
that.sdk.viewer.entities.add(enetity)
if (enetity.billboard) {
enetity.billboard.heightReference = Cesium.HeightReference.CLAMP_TO_GROUND
enetity.point = new Cesium.PointGraphics({
show: true,
color: color, // 点的颜色
pixelSize: 10, // 点的大小
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
disableDepthTestDistance: Number.POSITIVE_INFINITY // 不应用深度测试
})
}
if (enetity.polyline) {
enetity.polyline.material = color
enetity.polyline.zIndex = that.sdk._entityZIndex
that.sdk._entityZIndex++
}
if (enetity.polygon) {
enetity.polygon.perPositionHeight = false
enetity.polygon.material = colorPolygon
enetity.polygon.zIndex = that.sdk._entityZIndex
enetity.polyline = new Cesium.PolylineGraphics({
positions: enetity.polygon.hierarchy._value.positions,
width: 1,
clampToGround: true,
material: color,
zIndex: that.sdk._entityZIndex
})
that.sdk._entityZIndex++
}
})
that.loading = false
})
}
remove() {
if (this.entity) {
this.entity.entities.values.forEach(enetity => {
this.sdk.viewer.entities.remove(enetity)
})
this.entity = null
this.geojson = {}
}
}
async flyTo() {
if (!this.loading) {
if (this.geojson) {
setActiveViewer(0)
closeRotateAround(this.sdk)
closeViewFollow(this.sdk)
let range = turf.bbox(this.geojson);
if (this.options.customView && this.options.customView.relativePosition && this.options.customView.orientation) {
let orientation = {
heading: Cesium.Math.toRadians(this.options.customView.orientation.heading || 0.0),
pitch: Cesium.Math.toRadians(this.options.customView.orientation.pitch || -60.0),
roll: Cesium.Math.toRadians(this.options.customView.orientation.roll || 0.0)
}
let lng = this.options.customView.relativePosition.lng
let lat = this.options.customView.relativePosition.lat
let alt = this.options.customView.relativePosition.alt
let destination = Cesium.Cartesian3.fromDegrees(lng, lat, alt)
let position = { lng: range[0], lat: range[1] }
// 如果没有高度值,则获取紧贴高度计算
position.alt = await this.getClampToHeight(position)
lng = this.options.customView.relativePosition.lng + position.lng
lat = this.options.customView.relativePosition.lat + position.lat
alt = this.options.customView.relativePosition.alt + position.alt
destination = Cesium.Cartesian3.fromDegrees(lng, lat, alt)
this.sdk.viewer.camera.flyTo({
destination: destination,
orientation: orientation
})
}
else {
this.viewer.camera.flyTo({
destination: Cesium.Rectangle.fromDegrees(...range)
});
}
}
}
}
flicker() { }
}
export default GeoJson

View File

@ -0,0 +1,145 @@
/**
* @name: index
* @author: Administrator
* @date: 2023-03-04 10:39
* @descriptionindex
* @update: 2023-03-04 10:39
*/
import { getHost } from "../../../on";
import Base from '../index'
import Tools from '../../../Tools'
class GeoJson extends Base {
/**
* @constructor
* @param sdk
* @param options {object} 参数
* @param options.id {string} id
* @param options.url {string} geojson地址
* @param [options.color=#ef0606] {string} 线条颜色
* @param [options.width=1] {number} 线条宽度
* @example new YJ.Obj.GeoJson(earth,{id:"123",url:""})
* */
constructor(sdk, options = {}) {
super(sdk, options)
this.primitive = undefined
this.positions = []
this.loading = true
}
setDefaultValue() {
super.setDefaultValue()
this.options.host = this.options.host || getHost()
let url = this.options.url
if(this.options.host) {
let o = new URL(this.options.url, this.options.host)
url = o.href
}
this.options.url = url
this.options.color = this.options.color || '#ef0606'
this.options.width = this.options.width || 1
}
get show() {
if (this.primitive) return this.primitive.show
return undefined
}
set show(status) {
if (this.primitive) {
this.primitive.show = status
}
}
async on() {
let rsp = await fetch(this.options.url)
let json = await rsp.json()
return GeoJson.addDataToGlobe(this, json.features)
}
/*geojosn暂时只用线的形式*/
static addDataToGlobe(that, features) {
const instances = []
for (let i = 0; i < features.length; i++) {
let positions = []
if ('LineString' === features[i].geometry.type) {
features[i].geometry.coordinates.forEach(c => {
that.positions.push({ lng: c[0], lat: c[1] })
positions.push(c[0], c[1])
})
}
if ('Polygon' === features[i].geometry.type) {
features[i].geometry.coordinates.forEach(polygon => {
polygon.forEach(c => {
that.positions.push({ lng: c[0], lat: c[1] })
positions.push(c[0], c[1])
})
})
}
const polyline = new Cesium.GroundPolylineGeometry({
positions: Cesium.Cartesian3.fromDegreesArray(positions),
width: that.options.width //线宽
// vertexFormat: Cesium.PolylineColorAppearance.VERTEX_FORMAT
})
// let geometry = Cesium.PolylineGeometry.createGeometry(polyline)
instances.push(
new Cesium.GeometryInstance({
geometry: polyline
// attributes: {
// color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.BLUE),
// },
})
)
}
that.primitive = new Cesium.GroundPolylinePrimitive({
geometryInstances: instances,
// appearance: new Cesium.PerInstanceColorAppearance({ // 为每个instance着色
// translucent: true,
// closed: false
// }),
appearance: new Cesium.PolylineMaterialAppearance({
material: Cesium.Material.fromType('Color', {
color: Cesium.Color.fromCssColorString(that.options.color)
})
}),
asynchronous: false, // 确定基元是异步创建还是阻塞直到准备就绪
show: that.options.show ?? true
})
that.viewer.scene.primitives.add(that.primitive)
that.loading = false
}
remove() {
if (this.primitive) {
super.remove()
this.viewer.scene.primitives.remove(this.primitive)
this.primitive = null
}
}
flyTo() {
if (!this.loading) {
if (this.positions) {
let arr = new Tools().cal_envelope(this.positions)
var rectangle = new Cesium.Rectangle.fromDegrees(
arr[0][0],
arr[0][1],
arr[2][0],
arr[2][1]
)
this.viewer.camera.flyTo({
destination: rectangle
})
}
}
}
flicker() {}
}
export default GeoJson

View File

@ -0,0 +1,185 @@
/**
* @name: index
* @author: Administrator
* @date: 2023-03-04 10:39
* @descriptionindex
* @update: 2023-03-04 10:39
*/
import { getHost } from "../../../on";
import Base from '../index'
import Tools from '../../../Tools'
class GeoJson extends Base {
/**
* @constructor
* @param sdk
* @param options {object} 参数
* @param options.id {string} id
* @param options.url {string} geojson地址
* @param [options.color=#ef0606] {string} 线条颜色
* @param [options.width=1] {number} 线条宽度
* @example new YJ.Obj.GeoJson(earth,{id:"123",url:""})
* */
constructor(sdk, options = {}) {
super(sdk, options)
this.primitive = undefined
this.positions = []
this.loading = true
}
setDefaultValue() {
super.setDefaultValue()
this.options.host = this.options.host || getHost()
let url = this.options.url
if (this.options.host) {
let o = new URL(this.options.url, this.options.host)
url = o.href
}
this.options.url = url
this.options.color = this.options.color || 'rgb(239, 6, 6, 0.2)'
this.options.width = this.options.width || 1
}
get show() {
if (this.primitive) return this.primitive.show
return undefined
}
set show(status) {
if (this.primitive) {
this.primitive.show = status
}
}
async on() {
let rsp = await fetch(this.options.url)
let json = await rsp.json()
this.geojson = json
return GeoJson.addDataToGlobe(this, json.features)
}
/*geojosn暂时只用线的形式*/
static addDataToGlobe(that, features) {
const instancesList = []
const instancesPolygon = []
for (let i = 0; i < features.length; i++) {
let color = Cesium.Color.fromRandom().withAlpha(0.2)
if(features[i].geometry.type === 'LineString' || features[i].geometry.type === 'MultiLineString') {
let coordinates = features[i].geometry.coordinates
if(features[i].geometry.type === 'LineString') {
coordinates = [features[i].geometry.coordinates]
}
for (let m = 0; m < coordinates.length; m++) {
let item = coordinates[i]
let positions = []
item.forEach(c => {
positions.push(c[0], c[1])
})
const polyline = new Cesium.GroundPolylineGeometry({
positions: Cesium.Cartesian3.fromDegreesArray(positions),
width: that.options.width //线宽
})
instancesList.push(
new Cesium.GeometryInstance({
geometry: polyline
})
)
}
}
if(features[i].geometry.type === 'Polygon' || features[i].geometry.type === 'MultiPolygon') {
let coordinates = features[i].geometry.coordinates
if(features[i].geometry.type === 'Polygon') {
coordinates = [features[i].geometry.coordinates]
}
for (let m = 0; m < coordinates.length; m++) {
let item = coordinates[m]
item.forEach(p => {
let positions = []
p.forEach(c => {
positions.push(c[0], c[1])
})
let polygon = new Cesium.PolygonGeometry({
polygonHierarchy: new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArray(positions)),
});
instancesPolygon.push(
new Cesium.GeometryInstance({
geometry: polygon,
attributes: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(
Cesium.Color.fromRandom().withAlpha(0.2)
),
show: new Cesium.ShowGeometryInstanceAttribute(that.options.show ?? true), //显示或者隐藏
},
})
)
const polyline = new Cesium.GroundPolylineGeometry({
positions: Cesium.Cartesian3.fromDegreesArray(positions),
width: 2
})
instancesList.push(
new Cesium.GeometryInstance({
geometry: polyline
})
)
})
}
}
}
if (instancesList.length > 0) {
that.primitive = new Cesium.GroundPolylinePrimitive({
geometryInstances: instancesList,
appearance: new Cesium.PolylineMaterialAppearance({
material: Cesium.Material.fromType('Color', {
color: Cesium.Color.fromCssColorString(that.options.color)
})
}),
asynchronous: false, // 确定基元是异步创建还是阻塞直到准备就绪
show: that.options.show ?? true
})
that.viewer.scene.primitives.add(that.primitive)
}
if (instancesPolygon.length > 0) {
that.primitive = new Cesium.GroundPrimitive({
geometryInstances: instancesPolygon,
appearance: new Cesium.PerInstanceColorAppearance({
translucent: true, //false时透明度无效
closed: false,
}),
asynchronous: false, // 确定基元是异步创建还是阻塞直到准备就绪
show: that.options.show ?? true
})
that.viewer.scene.primitives.add(that.primitive)
}
that.loading = false
}
remove() {
if (this.primitive) {
super.remove()
this.viewer.scene.primitives.remove(this.primitive)
this.primitive = null
}
}
flyTo() {
if (!this.loading) {
if(this.geojson) {
let range = turf.bbox(this.geojson);
this.viewer.camera.flyTo({
destination: Cesium.Rectangle.fromDegrees(...range)
});
}
}
}
flicker() { }
}
export default GeoJson