This commit is contained in:
zh
2025-09-05 18:42:50 +08:00
parent 29629b9d43
commit ae48dbd700
14 changed files with 1753 additions and 4875 deletions

View File

@ -17,6 +17,7 @@ class GroundText extends Base {
* @param options.id {string} 唯一标识
* @param options.show=true {boolean} 显示/隐藏
* @param options.text {string} 文字
* @param options.color=#FFC107 {string} 颜色
* @param options.angle=0 {number} 旋转角度
* @param options.scale=1 {number} 缩放比例
* @param options.speed=1 {number} 文字滚动速度
@ -49,20 +50,21 @@ class GroundText extends Base {
textArray.splice(70 - textArray.length)
}
this.options.text = textArray.join('\n')
this.options.name = this.options.text
this.options.show =
options.show || options.show === false ? options.show : true
this.options.angle = options.angle || 0
this.options.scale =
options.scale || options.scale === 0 ? options.scale : 1
this.options.fontSize = options.fontSize || 20
this.options.duration =
options.duration || options.duration === 0 ? options.duration : 50000
// this.options.fontSize = options.fontSize || 20
// this.options.duration =
// options.duration || options.duration === 0 ? options.duration : 50000
this.options.speed =
options.speed || options.speed === 0 ? options.speed : 1
this.options.color = options.color || '#FFC107'
this.options.position = options.position
delete this.options.name
if (!this.options.position && this.options.positions) {
this.options.position = { lng: (this.options.positions[0].lng + this.options.positions[1].lng) / 2, lat: (this.options.positions[0].lat + this.options.positions[1].lat) / 2 }
let point1 = turf.point([this.options.positions[0].lng, this.options.positions[0].lat]);
@ -70,7 +72,7 @@ class GroundText extends Base {
let options = { units: 'miles' };
let distance1 = turf.rhumbDistance(point1, point2, options);
// 计算两点与x轴正方向的夹角弧度
function calculateAngle(pointA, pointB) {
@ -80,7 +82,7 @@ class GroundText extends Base {
}
let angleRadians = calculateAngle([this.options.positions[0].lng, this.options.positions[0].lat], [this.options.positions[1].lng, this.options.positions[1].lat]);
this.options.angle = (360+Cesium.Math.toDegrees(angleRadians))%360
this.options.angle = (360 + Cesium.Math.toDegrees(angleRadians)) % 360
let gap =
Math.abs(Math.cos((Math.PI / 180) * this.options.position.lat)) *
@ -98,10 +100,11 @@ class GroundText extends Base {
let to = turf.point([lng2, lat]);
let distance2 = turf.rhumbDistance(from, to, options);
let latRadians = Cesium.Math.toRadians(this.options.position.lat)
distance2 = distance2 * (1+(Math.abs(Math.sin(angleRadians)*Math.tan(latRadians)*Math.sin(latRadians)*Math.sin(latRadians))))
distance2 = distance2 * (1 + (Math.abs(Math.sin(angleRadians) * Math.tan(latRadians) * Math.sin(latRadians) * Math.sin(latRadians))))
this.options.scale = distance1 / distance2
}
this.duration = 50000
this.entity
this._positionEditing = false
this.Dialog = _Dialog
@ -137,6 +140,9 @@ class GroundText extends Base {
})
}
get name() {
return
}
get text() {
return this.options.text
}
@ -172,7 +178,7 @@ class GroundText extends Base {
image: canvas.toDataURL('image/png'),
color: this.options.color,
repeat: new Cesium.Cartesian2(1.0, 1.0),
duration: this.options.duration / this.options.speed,
duration: this.duration / this.options.speed,
fltr: false,
is2D: this.sdk.viewer.scene.mode === Cesium.SceneMode.SCENE2D ? true : false
})
@ -219,26 +225,26 @@ class GroundText extends Base {
})
}
get duration() {
return this.options.duration
}
// get duration() {
// return this.options.duration
// }
set duration(v) {
this.options.duration = v
let canvas = this.getcanvas()
this.entity.rectangle.material = new Cesium.CustomMaterialSource({
image: canvas.toDataURL('image/png'),
color: this.options.color,
repeat: new Cesium.Cartesian2(1.0, 1.0),
duration: this.options.duration / this.options.speed,
fltr: false,
is2D: this.sdk.viewer.scene.mode === Cesium.SceneMode.SCENE2D ? true : false
})
this._elms.duration &&
this._elms.duration.forEach(item => {
item.value = v
})
}
// set duration(v) {
// this.options.duration = v
// let canvas = this.getcanvas()
// this.entity.rectangle.material = new Cesium.CustomMaterialSource({
// image: canvas.toDataURL('image/png'),
// color: this.options.color,
// repeat: new Cesium.Cartesian2(1.0, 1.0),
// duration: this.options.duration / this.options.speed,
// fltr: false,
// is2D: this.sdk.viewer.scene.mode === Cesium.SceneMode.SCENE2D ? true : false
// })
// this._elms.duration &&
// this._elms.duration.forEach(item => {
// item.value = v
// })
// }
get speed() {
return this.options.speed
}
@ -250,7 +256,7 @@ class GroundText extends Base {
image: canvas.toDataURL('image/png'),
color: this.options.color,
repeat: new Cesium.Cartesian2(1.0, 1.0),
duration: this.options.duration / this.options.speed,
duration: this.duration / this.options.speed,
fltr: false,
is2D: this.sdk.viewer.scene.mode === Cesium.SceneMode.SCENE2D ? true : false
})
@ -270,7 +276,7 @@ class GroundText extends Base {
image: canvas.toDataURL('image/png'),
color: this.options.color,
repeat: new Cesium.Cartesian2(1.0, 1.0),
duration: this.options.duration / this.options.speed,
duration: this.duration / this.options.speed,
fltr: false,
is2D: this.sdk.viewer.scene.mode === Cesium.SceneMode.SCENE2D ? true : false
})
@ -328,7 +334,7 @@ class GroundText extends Base {
image: canvas.toDataURL('image/png'),
color: this.options.color,
repeat: new Cesium.Cartesian2(1.0, 1.0),
duration: this.options.duration / this.options.speed,
duration: this.duration / this.options.speed,
fltr: false,
is2D: this.sdk.viewer.scene.mode === Cesium.SceneMode.SCENE2D ? true : false
}),
@ -505,6 +511,10 @@ class GroundText extends Base {
})
})
} else {
if (this._positionEditingCallback) {
this._positionEditingCallback()
this._positionEditingCallback = null
}
if (this.event) {
this.event.mouse_move(() => { })
this.event.mouse_left(() => { })
@ -520,6 +530,11 @@ class GroundText extends Base {
return this._positionEditing
}
openPositionEditing(cd) {
this.positionEditing = true
this._positionEditingCallback = cd
}
/**
* 飞到
*/

View File

@ -56,13 +56,9 @@ class StandText extends Base {
this.options.show = (options.show || options.show === false) ? options.show : true
this.nodePoints = []
this.entity
this.options.instruct = options.instruct || ""
this.options.operatingPoint = options.operatingPoint || ""
this.options.attribute = options.attribute || {}
this.options.attribute.link = this.options.attribute.link || {}
this.options.attribute.link.content = this.options.attribute.link.content || []
this.options.attribute.camera = this.options.attribute.camera || []
this.options.attributeType = options.attributeType || 'richText'
delete this.options.name
this.extrudedHeight
this._EventBinding = new EventBinding()
this.Dialog = _Dialog
@ -71,6 +67,9 @@ class StandText extends Base {
StandText.create(this)
}
get name() {
return
}
get text() {
return this.options.text
}
@ -297,14 +296,6 @@ class StandText extends Base {
// }
get attributeCamera() {
return this.options.attribute.camera
}
set attributeCamera(v) {
this.options.attribute.camera = v
}
//创建
static async create(that) {
@ -397,15 +388,13 @@ class StandText extends Base {
this.Dialog.showCallBack && this.Dialog.showCallBack()
},
secondaryEditCallBack: () => {
StandText.nodeEdit(this)
this.nodeEdit()
}
})
this._DialogObject._element.body.className = this._DialogObject._element.body.className + ' stand-text'
let contentElm = document.createElement('div');
contentElm.innerHTML = html(this)
this._DialogObject.contentAppChild(contentElm)
this.attributeType = this.options.attributeType
this.attributeCamera = this.options.attribute.camera
// setTimeout(() => {
// this.attributeLink = this.options.attribute.link.content
// this.cameraSelect()
@ -538,23 +527,24 @@ class StandText extends Base {
}
}
static nodeEdit(that, cb = () => { }) {
nodeEdit(cb = () => { }) {
if (YJ.Measure.GetMeasureStatus()) {
cb('上一次测量未结束')
} else {
YJ.Measure.SetMeasureStatus(true)
that.tip = new MouseTip('请选择一个顶点,右键取消', that.sdk)
that.event = new MouseEvent(that.sdk)
that.nodePoints = []
this._nodeEditCallback = cb
this.tip = new MouseTip('请选择一个顶点,右键取消', this.sdk)
this.event = new MouseEvent(this.sdk)
this.nodePoints = []
let selectPoint
let originalPosition
let positions = that.options.positions
let positions = this.options.positions
let fromDegreesArray = []
let minimumHeights = []
let maximumHeights = []
let width = that.computeDistance2(positions)
let extrudedHeight = that.aspectRatio ? (width / that.aspectRatio) : 0
let width = this.computeDistance2(positions)
let extrudedHeight = this.aspectRatio ? (width / this.aspectRatio) : 0
for (let i = 0; i < positions.length; i++) {
fromDegreesArray.push(positions[i].lng, positions[i].lat)
minimumHeights.push(positions[i].alt)
@ -565,55 +555,55 @@ class StandText extends Base {
let leftEvent = (movement, cartesian) => {
if (selectPoint) {
isAdd = true
let pos3 = that.sdk.viewer.scene.clampToHeight(cartesian, [that.entity])
that.options.positions[selectPoint.index] = that.cartesian3Towgs84(pos3, that.sdk.viewer)
originalPosition = that.options.positions[selectPoint.index]
let entity = that.sdk.viewer.entities.add({
let pos3 = this.sdk.viewer.scene.clampToHeight(cartesian, [this.entity])
this.options.positions[selectPoint.index] = this.cartesian3Towgs84(pos3, this.sdk.viewer)
originalPosition = this.options.positions[selectPoint.index]
let entity = this.sdk.viewer.entities.add({
name: 'node-secondary-edit-point',
position: Cesium.Cartesian3.fromDegrees(that.options.positions[selectPoint.index].lng, that.options.positions[selectPoint.index].lat, that.options.positions[selectPoint.index].alt),
position: Cesium.Cartesian3.fromDegrees(this.options.positions[selectPoint.index].lng, this.options.positions[selectPoint.index].lat, this.options.positions[selectPoint.index].alt),
billboard: {
image: that.getSourceRootPath() + '/img/point.png',
image: this.getSourceRootPath() + '/img/point.png',
width: 15,
height: 15,
disableDepthTestDistance: Number.POSITIVE_INFINITY,
color: Cesium.Color.WHITE.withAlpha(0.99)
},
})
that.nodePoints.splice(selectPoint.index, 0, entity)
that.options.positions.splice(selectPoint.index, 0, that.options.positions[selectPoint.index])
this.nodePoints.splice(selectPoint.index, 0, entity)
this.options.positions.splice(selectPoint.index, 0, this.options.positions[selectPoint.index])
let positions = that.options.positions
let positions = this.options.positions
fromDegreesArray = []
minimumHeights = []
maximumHeights = []
width = that.computeDistance2(positions)
extrudedHeight = that.aspectRatio ? (width / that.aspectRatio) : 0
width = this.computeDistance2(positions)
extrudedHeight = this.aspectRatio ? (width / this.aspectRatio) : 0
for (let i = 0; i < positions.length; i++) {
fromDegreesArray.push(positions[i].lng, positions[i].lat)
minimumHeights.push(positions[i].alt)
maximumHeights.push(positions[i].alt + extrudedHeight)
}
that.tip.setPosition(
this.tip.setPosition(
cartesian,
movement.position.x,
movement.position.y
)
}
else {
var pick = that.sdk.viewer.scene.pick(movement.position);
var pick = this.sdk.viewer.scene.pick(movement.position);
if (pick && pick.id && pick.id.name && pick.id.name === 'node-secondary-edit-point') {
selectPoint = pick.id
that.nodePoints.splice(pick.id.index, 1)
that.sdk.viewer.entities.remove(pick.id)
that.tip.set_text('左键开始右键结束CTRL+右键撤销')
originalPosition = that.cartesian3Towgs84(cartesian, that.sdk.viewer)
that.entity.wall.positions = new Cesium.CallbackProperty(function () {
this.nodePoints.splice(pick.id.index, 1)
this.sdk.viewer.entities.remove(pick.id)
this.tip.set_text('左键开始右键结束CTRL+右键撤销')
originalPosition = this.cartesian3Towgs84(cartesian, this.sdk.viewer)
this.entity.wall.positions = new Cesium.CallbackProperty(function () {
return Cesium.Cartesian3.fromDegreesArray(fromDegreesArray)
}, false)
that.entity.wall.maximumHeights = new Cesium.CallbackProperty(function () {
this.entity.wall.maximumHeights = new Cesium.CallbackProperty(function () {
return maximumHeights
}, false)
that.entity.wall.minimumHeights = new Cesium.CallbackProperty(function () {
this.entity.wall.minimumHeights = new Cesium.CallbackProperty(function () {
return minimumHeights
}, false)
}
@ -621,69 +611,69 @@ class StandText extends Base {
}
let rightEvent = (movement, cartesian) => {
if (selectPoint) {
that.options.positions[selectPoint.index] = originalPosition
this.options.positions[selectPoint.index] = originalPosition
if(isAdd) {
that.options.positions.splice(selectPoint.index, 1)
this.options.positions.splice(selectPoint.index, 1)
}
cb(null, that.options.positions)
cb(null, this.options.positions)
}
let positions = that.options.positions
let positions = this.options.positions
fromDegreesArray = []
minimumHeights = []
maximumHeights = []
width = that.computeDistance2(positions)
extrudedHeight = that.aspectRatio ? (width / that.aspectRatio) : 0
width = this.computeDistance2(positions)
extrudedHeight = this.aspectRatio ? (width / this.aspectRatio) : 0
for (let i = 0; i < positions.length; i++) {
fromDegreesArray.push(positions[i].lng, positions[i].lat)
minimumHeights.push(positions[i].alt)
maximumHeights.push(positions[i].alt + extrudedHeight)
}
that.entity.wall.positions = Cesium.Cartesian3.fromDegreesArray(fromDegreesArray)
this.entity.wall.positions = Cesium.Cartesian3.fromDegreesArray(fromDegreesArray)
for (let i = 0; i < that.nodePoints.length; i++) {
that.sdk.viewer.entities.remove(that.nodePoints[i])
for (let i = 0; i < this.nodePoints.length; i++) {
this.sdk.viewer.entities.remove(this.nodePoints[i])
}
that.nodePoints = []
this.nodePoints = []
YJ.Measure.SetMeasureStatus(false)
that.event.destroy()
that.tip.destroy()
this.event.destroy()
this.tip.destroy()
}
that.event.mouse_left(leftEvent)
this.event.mouse_left(leftEvent)
that.event.mouse_right(rightEvent)
this.event.mouse_right(rightEvent)
that.event.mouse_move((movement, cartesian) => {
this.event.mouse_move((movement, cartesian) => {
if (selectPoint) {
let pos3 = that.sdk.viewer.scene.clampToHeight(cartesian, [that.entity])
that.options.positions[selectPoint.index] = that.cartesian3Towgs84(pos3, that.sdk.viewer)
let positions = that.options.positions
let pos3 = this.sdk.viewer.scene.clampToHeight(cartesian, [this.entity])
this.options.positions[selectPoint.index] = this.cartesian3Towgs84(pos3, this.sdk.viewer)
let positions = this.options.positions
fromDegreesArray = []
minimumHeights = []
maximumHeights = []
width = that.computeDistance2(positions)
extrudedHeight = that.aspectRatio ? (width / that.aspectRatio) : 0
width = this.computeDistance2(positions)
extrudedHeight = this.aspectRatio ? (width / this.aspectRatio) : 0
for (let i = 0; i < positions.length; i++) {
fromDegreesArray.push(positions[i].lng, positions[i].lat)
minimumHeights.push(positions[i].alt)
maximumHeights.push(positions[i].alt + extrudedHeight)
}
}
that.tip.setPosition(
this.tip.setPosition(
cartesian,
movement.endPosition.x,
movement.endPosition.y
)
})
that.event.mouse_right_keyboard_ctrl((movement, cartesian) => {
this.event.mouse_right_keyboard_ctrl((movement, cartesian) => {
if (selectPoint) {
that.options.positions.pop()
that.sdk.viewer.entities.remove(that.nodePoints[that.nodePoints.length - 1])
that.nodePoints.pop()
if (selectPoint.index === that.options.positions.length) {
if (that.nodePoints[selectPoint.index - 1]) {
selectPoint = that.nodePoints[selectPoint.index - 1]
this.options.positions.pop()
this.sdk.viewer.entities.remove(this.nodePoints[this.nodePoints.length - 1])
this.nodePoints.pop()
if (selectPoint.index === this.options.positions.length) {
if (this.nodePoints[selectPoint.index - 1]) {
selectPoint = this.nodePoints[selectPoint.index - 1]
}
else {
selectPoint.index = 0
@ -692,7 +682,7 @@ class StandText extends Base {
}
})
that.event.gesture_pinck_start((movement, cartesian) => {
this.event.gesture_pinck_start((movement, cartesian) => {
let startTime = new Date()
let pos = {
position: {
@ -700,7 +690,7 @@ class StandText extends Base {
y: (movement.position1.y + movement.position2.y) / 2
}
}
that.event.gesture_pinck_end(() => {
this.event.gesture_pinck_end(() => {
let endTime = new Date()
if (endTime - startTime >= 500) {
// 长按取消
@ -712,20 +702,20 @@ class StandText extends Base {
})
})
for (let i = 0; i < that.options.positions.length; i++) {
let entity = that.sdk.viewer.entities.add({
for (let i = 0; i < this.options.positions.length; i++) {
let entity = this.sdk.viewer.entities.add({
name: 'node-secondary-edit-point',
index: i,
position: Cesium.Cartesian3.fromDegrees(that.options.positions[i].lng, that.options.positions[i].lat, that.options.positions[i].alt),
position: Cesium.Cartesian3.fromDegrees(this.options.positions[i].lng, this.options.positions[i].lat, this.options.positions[i].alt),
billboard: {
image: that.getSourceRootPath() + '/img/point.png',
image: this.getSourceRootPath() + '/img/point.png',
width: 15,
height: 15,
disableDepthTestDistance: Number.POSITIVE_INFINITY,
color: Cesium.Color.WHITE.withAlpha(0.99)
},
})
that.nodePoints.push(entity)
this.nodePoints.push(entity)
}
}
}