264 lines
8.5 KiB
JavaScript
264 lines
8.5 KiB
JavaScript
|
/**
|
|||
|
* @name: drawAttackArrow
|
|||
|
* @author: Administrator
|
|||
|
* @date: 2022-06-15 16:38
|
|||
|
* @description:drawAttackArrow
|
|||
|
* @update: 2022-06-15 16:38
|
|||
|
*/
|
|||
|
import Draw from './draw'
|
|||
|
import MouseTip from '../MouseTip'
|
|||
|
import MouseEvent from '../Event'
|
|||
|
|
|||
|
export default class DrawAttackArrow extends Draw {
|
|||
|
constructor(sdk, options = {}) {
|
|||
|
super(sdk, options)
|
|||
|
}
|
|||
|
|
|||
|
static create_arrow_polygon(that, viewer = that.viewer) {
|
|||
|
that.entityHasCreated = true
|
|||
|
let id = that.randomString()
|
|||
|
viewer.entities.add(
|
|||
|
new Cesium.Entity({
|
|||
|
id: id,
|
|||
|
polygon: {
|
|||
|
classificationType: Cesium.ClassificationType.BOTH,
|
|||
|
hierarchy: new Cesium.CallbackProperty((e) => {
|
|||
|
let arr = that.computeAttackArrow(that.positions)
|
|||
|
for (let i = 0; i < arr.length; i++) {
|
|||
|
if (isNaN(arr[i].x)) {
|
|||
|
arr = []
|
|||
|
break
|
|||
|
}
|
|||
|
}
|
|||
|
return new Cesium.PolygonHierarchy(arr)
|
|||
|
}, false),
|
|||
|
material: Cesium.Color.fromCssColorString(that.color),
|
|||
|
zIndex: 99999999
|
|||
|
},
|
|||
|
})
|
|||
|
)
|
|||
|
return id
|
|||
|
}
|
|||
|
|
|||
|
start(cb) {
|
|||
|
if (YJ.Measure.GetMeasureStatus()) {
|
|||
|
cb('上一次测量未结束')
|
|||
|
} else {
|
|||
|
super.start()
|
|||
|
|
|||
|
let into
|
|||
|
YJ.Measure.SetMeasureStatus(true)
|
|||
|
this.tip = new MouseTip('左键确定,右键结束;CTRL+右键撤销', this.sdk)
|
|||
|
this.event = new MouseEvent(this.sdk)
|
|||
|
this.positions = []
|
|||
|
this.points_ids = [] //存放左键点击时临时添加的point的id
|
|||
|
let cache_positions = []
|
|||
|
let isMove = false
|
|||
|
this.event.mouse_left((movement, cartesian) => {
|
|||
|
if(into === '2D') {
|
|||
|
return
|
|||
|
}
|
|||
|
into = '3D'
|
|||
|
if (!this.entityHasCreated) {
|
|||
|
let polyline_id = DrawAttackArrow.create_arrow_polygon(this)
|
|||
|
this.points_ids.push(polyline_id)
|
|||
|
}
|
|||
|
this.points_ids.push(this.create_point(cartesian))
|
|||
|
cache_positions.push(this.cartesian3Towgs84(cartesian, this.viewer))
|
|||
|
isMove = false
|
|||
|
})
|
|||
|
this.event.mouse_right((movement, cartesian) => {
|
|||
|
if(into === '2D') {
|
|||
|
return
|
|||
|
}
|
|||
|
let c = []
|
|||
|
if (this.points_ids.length > 2) {
|
|||
|
let positions = this.viewer.entities.getById(this.points_ids[0]).polygon.hierarchy.getValue().positions
|
|||
|
positions.forEach(it => {
|
|||
|
c.push(this.cartesian3Towgs84(it, this.viewer))
|
|||
|
})
|
|||
|
}
|
|||
|
this.end()
|
|||
|
if (isMove) {
|
|||
|
this.positions.pop()
|
|||
|
}
|
|||
|
cb(null, this.positions, c)
|
|||
|
})
|
|||
|
this.event.mouse_move((movement, cartesian) => {
|
|||
|
if(into === '2D') {
|
|||
|
return
|
|||
|
}
|
|||
|
isMove = true
|
|||
|
this.positions = cache_positions.concat(
|
|||
|
this.cartesian3Towgs84(cartesian, this.viewer)
|
|||
|
)
|
|||
|
this.tip.setPosition(
|
|||
|
cartesian,
|
|||
|
movement.endPosition.x,
|
|||
|
movement.endPosition.y
|
|||
|
)
|
|||
|
})
|
|||
|
this.event.mouse_right_keyboard_ctrl((movement, cartesian) => {
|
|||
|
if(into === '2D') {
|
|||
|
return
|
|||
|
}
|
|||
|
if (this.points_ids.length > 1) {
|
|||
|
this.remove_entity(this.points_ids.pop()) //移除point
|
|||
|
cache_positions.pop()
|
|||
|
}
|
|||
|
})
|
|||
|
|
|||
|
this.event.gesture_pinck_start_keyboard_ctrl(() => {
|
|||
|
if(into === '2D') {
|
|||
|
return
|
|||
|
}
|
|||
|
if (this.points_ids.length > 1) {
|
|||
|
this.remove_entity(this.points_ids.pop()) //移除point
|
|||
|
cache_positions.pop()
|
|||
|
}
|
|||
|
})
|
|||
|
|
|||
|
this.event.gesture_pinck_start((movement, cartesian) => {
|
|||
|
if(into === '2D') {
|
|||
|
return
|
|||
|
}
|
|||
|
let startTime = new Date()
|
|||
|
this.event.gesture_pinck_end(() => {
|
|||
|
let endTime = new Date()
|
|||
|
if (endTime - startTime >= 500) {
|
|||
|
let c = []
|
|||
|
if (this.points_ids.length > 2) {
|
|||
|
let positions = this.viewer.entities.getById(this.points_ids[0]).polygon.hierarchy.getValue().positions
|
|||
|
positions.forEach(it => {
|
|||
|
c.push(this.cartesian3Towgs84(it, this.viewer))
|
|||
|
})
|
|||
|
}
|
|||
|
this.end()
|
|||
|
cb(null, this.positions, c)
|
|||
|
}
|
|||
|
else {
|
|||
|
if (!this.entityHasCreated) {
|
|||
|
let polyline_id = DrawAttackArrow.create_arrow_polygon(this)
|
|||
|
this.points_ids.push(polyline_id)
|
|||
|
}
|
|||
|
this.points_ids.push(this.create_point(cartesian))
|
|||
|
cache_positions.push(this.cartesian3Towgs84(cartesian, this.viewer))
|
|||
|
this.positions = cache_positions.concat(
|
|||
|
this.cartesian3Towgs84(cartesian, this.viewer)
|
|||
|
)
|
|||
|
this.tip.setPosition(
|
|||
|
cartesian,
|
|||
|
(movement.position1.x + movement.position2.x) / 2,
|
|||
|
(movement.position1.y + movement.position2.y) / 2
|
|||
|
)
|
|||
|
}
|
|||
|
})
|
|||
|
})
|
|||
|
|
|||
|
if (!this._is2D && this._sdk2D) {
|
|||
|
this.event2D = new MouseEvent(this._sdk2D)
|
|||
|
this.event2D.mouse_left((movement, cartesian) => {
|
|||
|
if(into === '3D') {
|
|||
|
return
|
|||
|
}
|
|||
|
into = '2D'
|
|||
|
if (!this.entityHasCreated) {
|
|||
|
let polyline_id = DrawAttackArrow.create_arrow_polygon(this, this._sdk2D.viewer)
|
|||
|
this.points_ids.push(polyline_id)
|
|||
|
}
|
|||
|
this.points_ids.push(this.create_point(cartesian, this._sdk2D.viewer))
|
|||
|
cache_positions.push(this.cartesian3Towgs84(cartesian, this.viewer))
|
|||
|
isMove = false
|
|||
|
})
|
|||
|
this.event2D.mouse_right((movement, cartesian) => {
|
|||
|
if(into === '3D') {
|
|||
|
return
|
|||
|
}
|
|||
|
let c = []
|
|||
|
if (this.points_ids.length > 2) {
|
|||
|
let positions = this.event2D.viewer.entities.getById(this.points_ids[0]).polygon.hierarchy.getValue().positions
|
|||
|
positions.forEach(it => {
|
|||
|
c.push(this.cartesian3Towgs84(it, this.viewer))
|
|||
|
})
|
|||
|
}
|
|||
|
this.end()
|
|||
|
if (isMove) {
|
|||
|
this.positions.pop()
|
|||
|
}
|
|||
|
cb(null, this.positions, c)
|
|||
|
})
|
|||
|
this.event2D.mouse_move((movement, cartesian) => {
|
|||
|
if(into === '3D') {
|
|||
|
return
|
|||
|
}
|
|||
|
isMove = true
|
|||
|
this.positions = cache_positions.concat(
|
|||
|
this.cartesian3Towgs84(cartesian, this.viewer)
|
|||
|
)
|
|||
|
this.tip.setPosition(
|
|||
|
cartesian,
|
|||
|
movement.endPosition.x + this.viewer.canvas.width,
|
|||
|
movement.endPosition.y
|
|||
|
)
|
|||
|
})
|
|||
|
this.event2D.mouse_right_keyboard_ctrl((movement, cartesian) => {
|
|||
|
if(into === '3D') {
|
|||
|
return
|
|||
|
}
|
|||
|
if (this.points_ids.length > 1) {
|
|||
|
this.remove_entity(this.points_ids.pop()) //移除point
|
|||
|
cache_positions.pop()
|
|||
|
}
|
|||
|
})
|
|||
|
|
|||
|
this.event2D.gesture_pinck_start_keyboard_ctrl(() => {
|
|||
|
if(into === '3D') {
|
|||
|
return
|
|||
|
}
|
|||
|
if (this.points_ids.length > 1) {
|
|||
|
this.remove_entity(this.points_ids.pop()) //移除point
|
|||
|
cache_positions.pop()
|
|||
|
}
|
|||
|
})
|
|||
|
|
|||
|
this.event2D.gesture_pinck_start((movement, cartesian) => {
|
|||
|
if(into === '3D') {
|
|||
|
return
|
|||
|
}
|
|||
|
let startTime = new Date()
|
|||
|
this.event2D.gesture_pinck_end(() => {
|
|||
|
let endTime = new Date()
|
|||
|
if (endTime - startTime >= 500) {
|
|||
|
let c = []
|
|||
|
if (this.points_ids.length > 2) {
|
|||
|
let positions = this.viewer.entities.getById(this.points_ids[0]).polygon.hierarchy.getValue().positions
|
|||
|
positions.forEach(it => {
|
|||
|
c.push(this.cartesian3Towgs84(it, this.viewer))
|
|||
|
})
|
|||
|
}
|
|||
|
this.end()
|
|||
|
cb(null, this.positions, c)
|
|||
|
}
|
|||
|
else {
|
|||
|
if (!this.entityHasCreated) {
|
|||
|
let polyline_id = DrawAttackArrow.create_arrow_polygon(this, this._sdk2D.viewer)
|
|||
|
this.points_ids.push(polyline_id)
|
|||
|
}
|
|||
|
this.points_ids.push(this.create_point(cartesian, this._sdk2D.viewer))
|
|||
|
cache_positions.push(this.cartesian3Towgs84(cartesian, this.viewer))
|
|||
|
this.positions = cache_positions.concat(
|
|||
|
this.cartesian3Towgs84(cartesian, this.viewer)
|
|||
|
)
|
|||
|
this.tip.setPosition(
|
|||
|
cartesian,
|
|||
|
((movement.position1.x + movement.position2.x) / 2) + this.viewer.canvas.width,
|
|||
|
(movement.position1.y + movement.position2.y) / 2
|
|||
|
)
|
|||
|
}
|
|||
|
})
|
|||
|
})
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|