代码迁移

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,197 @@
/**
* @name: index
* @author: Administrator
* @date: 2022-07-22 17:15
* @descriptionindex
* @update: 2022-07-22 17:15
*/
import Measure from "../index";
class MeasureHeight extends Measure {
/**
* @constructor
* @param sdk
* @description 高度测量
* */
constructor(sdk) {
super(sdk, {text: "左键开始,右键取消"});
}
static create_polygon(that) {
let id = that.randomString()
let a = that.viewer.entities.add(new Cesium.Entity({
id,
billboard: {
image: that.getSourceRootPath() + '/img/point.png',
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
disableDepthTestDistance: Number.POSITIVE_INFINITY,
color: Cesium.Color.WHITE.withAlpha(0.99)
},
position: new Cesium.CallbackProperty(() => {
return that.position
}, false),
label: {
text: new Cesium.CallbackProperty(() => {
return that.text
}, false),
scale: 1,
// fillColor: Cesium.Color.RED,
font: 'normal 20px MicroSoft YaHei',
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
pixelOffset: new Cesium.Cartesian2(0, -15),
disableDepthTestDistance: Number.POSITIVE_INFINITY,
},
polyline: {
positions: new Cesium.CallbackProperty(e => {
return that.positions;
}, false),
width: 2,
material: Cesium.Color.YELLOW,
zIndex: 99999999
},
ellipse: {
height: new Cesium.CallbackProperty(() => {
return that.height + that.firstpoint.alt;
}, false),
semiMinorAxis: new Cesium.CallbackProperty(e => {
return that.circleRadius;
}, false),
semiMajorAxis: new Cesium.CallbackProperty(e => {
return that.circleRadius;
}, false),
material: new Cesium.Color.fromCssColorString(that.defaultColor)
},
}))
return id
}
static create_point(that, cartesian, option = {}) {
let id = that.randomString()
let p = that.cartesian3Towgs84(cartesian, that.viewer)
let params = {
id: id,
position: Cesium.Cartesian3.fromDegrees(p.lng, p.lat, p.alt),
billboard: {
image: that.getSourceRootPath() + '/img/point.png',
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
disableDepthTestDistance: Number.POSITIVE_INFINITY,
color: Cesium.Color.WHITE.withAlpha(0.99)
}
}
if (option.label) {
params.label = {
text: option.label.text,
scale: 1,
// fillColor: Cesium.Color.fromCssColorString("#06eee5"),
font: 'normal 20px MicroSoft YaHei',
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
pixelOffset: new Cesium.Cartesian2(0, -15),
}
}
that.viewer.entities.add(
new Cesium.Entity(params)
)
return id
}
/**
* 开始测量
*/
start() {
if (!YJ.Measure.GetMeasureStatus()) {
super.start()
this.positions = []
this.position = new Cesium.Cartesian3()
this.height = 0
this.text = ""
this.circleRadius = 0
let count = 0;
this.firstpoint = null
let leftEvent = (movement, cartesian) => {
if (this.firstpoint === null) {
this.positions.push(cartesian)
this.firstpoint = this.cartesian3Towgs84(cartesian, this.viewer)
this.ids.push(MeasureHeight.create_polygon(this))
this.ids.push(MeasureHeight.create_point(this, cartesian))
}
count++
this.tip.setPosition(cartesian, movement.position.x, movement.position.y)
if (count === 2) {
if (this.firstpoint) {
let cur_point = this.cartesian3Towgs84(cartesian, this.viewer)
this.positions[1] = Cesium.Cartesian3.fromDegrees(this.firstpoint.lng, this.firstpoint.lat, cur_point.alt)
this.positions[2] = cartesian
this.position = this.positions[1]
this.circleRadius = this.computeDistance([this.firstpoint, cur_point])
this.height = Number((cur_point.alt - this.firstpoint.alt).toFixed(2))
this.text = "相对高度:" + this.height + " 米"
this.tip.set_text("左键完成,右键取消;半径:" + this.circleRadius + " 米")
}
this.ids.push(MeasureHeight.create_point(this, cartesian, {label: {text: "半径:" + this.circleRadius + " 米"}}))
this.end()
}
}
this.event.mouse_left(leftEvent)
this.event.mouse_move((movement, cartesian) => {
this.tip.setPosition(cartesian, movement.endPosition.x, movement.endPosition.y)
if (this.firstpoint) {
let cur_point = this.cartesian3Towgs84(cartesian, this.viewer)
this.positions[1] = Cesium.Cartesian3.fromDegrees(this.firstpoint.lng, this.firstpoint.lat, cur_point.alt)
this.positions[2] = cartesian
this.position = this.positions[1]
this.circleRadius = this.computeDistance([this.firstpoint, cur_point])
this.height = Number((cur_point.alt - this.firstpoint.alt).toFixed(2))
this.text = "相对高度:" + this.height + " 米"
this.tip.set_text("左键完成,右键取消;半径:" + this.circleRadius + " 米")
}
})
this.event.mouse_right((movement, cartesian) => {
this.end()
this.destroy()
})
this.event.gesture_pinck_start((movement, cartesian) => {
let startTime = new Date()
let pos = {
position: {
x: (movement.position1.x + movement.position2.x) / 2,
y: (movement.position1.y + movement.position2.y) / 2
}
}
this.event.gesture_pinck_end(() => {
let endTime = new Date()
if (endTime - startTime >= 500) {
// 长按取消
this.end()
this.destroy()
}
else {
leftEvent(pos, cartesian)
}
})
})
}
}
/**
* 结束测量
*/
end() {
super.end()
}
/**
* 清除测量
*/
destroy() {
super.destroy()
}
}
export default MeasureHeight