创建新仓库
This commit is contained in:
124
static/lib/testFun.js
Normal file
124
static/lib/testFun.js
Normal file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
class MouseEvent {
|
||||
constructor(earth) {
|
||||
this.earth = earth
|
||||
this.handler = new Cesium.ScreenSpaceEventHandler(
|
||||
this.earth.czm.viewer.canvas
|
||||
)
|
||||
}
|
||||
|
||||
/!*事件*!/
|
||||
mouse_left(cb) {
|
||||
// //左键点击事件
|
||||
this.handler.setInputAction((movement) => {
|
||||
let cartesian = this.getcartesian(movement)
|
||||
// cartesian = this.earth.czm.viewer.scene.pickPosition(movement.position)
|
||||
// if (!cartesian) {
|
||||
// cartesian = this.viewer.scene.camera.pickEllipsoid(
|
||||
// movement.position,
|
||||
// this.viewer.scene.globe.ellipsoid
|
||||
// )
|
||||
// }
|
||||
// if (cartesian) {
|
||||
// cb(movement, cartesian)
|
||||
// }
|
||||
if (cartesian) {
|
||||
cb(movement, cartesian)
|
||||
}
|
||||
}, Cesium.ScreenSpaceEventType.LEFT_CLICK)
|
||||
}
|
||||
|
||||
mouse_move(cb) {
|
||||
this.handler.setInputAction((movement) => {
|
||||
let cartesian = this.getcartesian(movement)
|
||||
|
||||
if (cartesian) {
|
||||
cb(movement, cartesian)
|
||||
}
|
||||
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE)
|
||||
}
|
||||
|
||||
mouse_right(cb) {
|
||||
this.handler.setInputAction((movement) => {
|
||||
let cartesian = this.getcartesian(movement)
|
||||
if (cartesian) {
|
||||
cb(movement, cartesian)
|
||||
}
|
||||
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK)
|
||||
}
|
||||
|
||||
getcartesian(movement) {
|
||||
if (movement.endPosition) {
|
||||
movement.endPosition.y -= 2
|
||||
}
|
||||
let position = movement.position || movement.endPosition
|
||||
|
||||
return this.earth.czm.viewer.scene.pickPosition(position)
|
||||
}
|
||||
|
||||
//鼠标右键+键盘ctrl
|
||||
mouse_right_keyboard_ctrl(cb) {
|
||||
// //左键点击事件
|
||||
this.handler.setInputAction(
|
||||
(movement) => {
|
||||
let cartesian = this.getcartesian(movement)
|
||||
if (cartesian) {
|
||||
cb(movement, cartesian)
|
||||
}
|
||||
},
|
||||
Cesium.ScreenSpaceEventType.RIGHT_CLICK,
|
||||
Cesium.KeyboardEventModifier.CTRL
|
||||
)
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.handler.destroy() //关闭事件句柄
|
||||
this.handler = null
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
class Text3d {
|
||||
constructor(earth,
|
||||
options = {
|
||||
text: "",
|
||||
id: '',
|
||||
positions: []
|
||||
}
|
||||
) {
|
||||
this.options = {...options}
|
||||
this.earth = earth
|
||||
Text3d.setDefaultValue(this)
|
||||
}
|
||||
|
||||
static setDefaultValue(that) {
|
||||
that.options.id = that.options.id ?? "wall"
|
||||
that.options.text = that.options.text ?? "立体文字"
|
||||
that.options.positions = that.options.positions ?? []
|
||||
}
|
||||
|
||||
start(cb) {
|
||||
console.log(this.options)
|
||||
let arr = []
|
||||
this.options.positions.forEach(item => {
|
||||
arr.push([turf.degreesToRadians(item.lng),
|
||||
turf.degreesToRadians(item.lat),
|
||||
item.alt])
|
||||
})
|
||||
console.log(arr)
|
||||
let czm = {
|
||||
"ref": this.options.id,
|
||||
"czmObject": {
|
||||
"xbsjType": "Wall",
|
||||
"positions": arr
|
||||
}
|
||||
}
|
||||
|
||||
this.earth.sceneTree.root.children.push(czm)
|
||||
cb(this.earth.sceneTree.$refs[this.options.id].czmObject)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
window.Text3d = Text3d
|
Reference in New Issue
Block a user