代码迁移
This commit is contained in:
123
src/MouseTip/index.js
Normal file
123
src/MouseTip/index.js
Normal file
@ -0,0 +1,123 @@
|
||||
/**
|
||||
* @name: index
|
||||
* @author: Administrator
|
||||
* @date: 2022-06-14 14:37
|
||||
* @description:index
|
||||
* @update: 2022-06-14 14:37
|
||||
*/
|
||||
import Tools from "../Tools";
|
||||
|
||||
//鼠标tip
|
||||
export default class MouseTip {
|
||||
constructor(text = '左键开始,右键结束', sdk) {
|
||||
this.point = undefined
|
||||
this.text = text
|
||||
this.div = undefined
|
||||
this.mouse_type = 0
|
||||
this.position = new Cesium.Cartesian3()
|
||||
|
||||
this.viewer = sdk.viewer
|
||||
this.create_tip(this.viewer)
|
||||
}
|
||||
|
||||
set_text(text) {
|
||||
let textElm = this.div.getElementsByTagName('p')[0]
|
||||
textElm.innerText = text
|
||||
}
|
||||
|
||||
get_mouse_style(type) {
|
||||
let url = 'lib/img/'
|
||||
let style = '' //默认的鼠标箭头样式
|
||||
switch (type) {
|
||||
case 1:
|
||||
style = 'move.png' //移动样式
|
||||
break
|
||||
|
||||
default:
|
||||
style = 'arrow.png'
|
||||
break
|
||||
}
|
||||
return 'url(' + url + style + '),auto'
|
||||
}
|
||||
|
||||
create_tip(viewer) {
|
||||
// let tool = new Tools()
|
||||
// this.point = viewer.entities.add(
|
||||
// new Cesium.Entity({
|
||||
// position: new Cesium.CallbackProperty(() => {
|
||||
// return this.position
|
||||
// }, false),
|
||||
// billboard: {
|
||||
// image: tool.getSourceRootPath() + '/img/point.png',
|
||||
// verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
||||
// disableDepthTestDistance: 100000000
|
||||
// }
|
||||
// })
|
||||
// )
|
||||
// tool = null
|
||||
// this.style_tip(viewer, this.mouse_type)
|
||||
this.create_tooltip()
|
||||
}
|
||||
|
||||
setPosition(position, x, y) {
|
||||
this.position = position
|
||||
this.move_tooltip(x, y)
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.viewer.entities.remove(this.point)
|
||||
this.remove_tooltip()
|
||||
// this.style_tip(viewer)
|
||||
}
|
||||
|
||||
create_tooltip() {
|
||||
let tool = new Tools()
|
||||
this.div = document.createElement('div')
|
||||
let c = "#ec131a"
|
||||
this.div.setAttribute(
|
||||
'style',
|
||||
'position: absolute;z-index: 777;color: ' + c + ';left:10px;top:0px;pointer-events: none;'
|
||||
)
|
||||
let textElm = document.createElement('p')
|
||||
textElm.style.margin = '0px'
|
||||
textElm.style.padding = '0px'
|
||||
textElm.innerText = this.text
|
||||
this.div.appendChild(textElm)
|
||||
let imgElm = document.createElement('div')
|
||||
imgElm.style.width = '12px'
|
||||
imgElm.style.height = '12px'
|
||||
imgElm.style.background = `url(${tool.getSourceRootPath() + '/img/point.png'}) 100% 100% no-repeat`
|
||||
imgElm.style.backgroundSize = '100% 100%'
|
||||
imgElm.style.position = 'absolute'
|
||||
imgElm.style.left = '-36px'
|
||||
imgElm.style.top = '-4px'
|
||||
this.div.style.display = 'none'
|
||||
this.div.appendChild(imgElm)
|
||||
tool = null
|
||||
document.querySelector('body').appendChild(this.div)
|
||||
}
|
||||
|
||||
/*移动时的鼠标样式*/
|
||||
style_tip(viewer, type = 0) {
|
||||
viewer._element.style.cursor = this.get_mouse_style(type)
|
||||
}
|
||||
|
||||
remove_tooltip() {
|
||||
document.querySelector('body').contains(this.div) && document.querySelector('body').removeChild(this.div)
|
||||
}
|
||||
|
||||
move_tooltip(x, y) {
|
||||
let top = 0
|
||||
let left = 0
|
||||
this.div.style.display = 'block'
|
||||
|
||||
if (this.viewer && this.viewer._element) {
|
||||
let element = this.viewer._element.getElementsByClassName('cesium-widget')[0].getElementsByTagName('canvas')[0]
|
||||
top = element.getBoundingClientRect().top + window.scrollY
|
||||
left = element.getBoundingClientRect().left + window.scrollX
|
||||
}
|
||||
|
||||
this.div.style.left = x + 30 + left + 'px'
|
||||
this.div.style.top = y + top + 'px'
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user