修改文本框同步问题
This commit is contained in:
@ -30,6 +30,7 @@ class TextBox extends Base {
|
|||||||
this.textDom = undefined
|
this.textDom = undefined
|
||||||
this.create(this)
|
this.create(this)
|
||||||
this.sdk.addIncetance(this.options.id, this)
|
this.sdk.addIncetance(this.options.id, this)
|
||||||
|
|
||||||
this.callback = callback
|
this.callback = callback
|
||||||
|
|
||||||
// syncData(this.sdk, this.options.id)
|
// syncData(this.sdk, this.options.id)
|
||||||
@ -46,6 +47,7 @@ class TextBox extends Base {
|
|||||||
let dom = document.createElement('span');
|
let dom = document.createElement('span');
|
||||||
dom.id = that.options.id
|
dom.id = that.options.id
|
||||||
dom.className = 'popup-textarea'
|
dom.className = 'popup-textarea'
|
||||||
|
dom.style.zIndex = 1
|
||||||
// 创建textarea元素
|
// 创建textarea元素
|
||||||
var textarea = document.createElement('textarea');
|
var textarea = document.createElement('textarea');
|
||||||
textarea.className = 'textarea'
|
textarea.className = 'textarea'
|
||||||
@ -134,17 +136,45 @@ class TextBox extends Base {
|
|||||||
this.options.text = words
|
this.options.text = words
|
||||||
this.callback(this.options)
|
this.callback(this.options)
|
||||||
let { sdkP } = getSdk()
|
let { sdkP } = getSdk()
|
||||||
if(this.sdk === sdkP) {
|
if (this.sdk === sdkP && sdkP) {//三维
|
||||||
console.log(3)
|
|
||||||
syncData(this.sdk, this.options.id)
|
syncData(this.sdk, this.options.id)
|
||||||
}
|
}
|
||||||
else {
|
else if (sdkP) {//二维
|
||||||
console.log(2)
|
sdkP.entityMap.get(this.options.id).text = words
|
||||||
|
sdkP.entityMap.get(this.options.id).twoToThree(this.options.position)
|
||||||
|
} else if (!sdkP) {
|
||||||
|
syncData(this.sdk, this.options.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
async twoToThree(position) {
|
||||||
|
let that = this
|
||||||
|
that.sdk.viewer.scene.postRender.removeEventListener(that.handler);
|
||||||
|
let posi = Cesium.Cartesian3.fromDegrees(position.lng, position.lat, position.alt)
|
||||||
|
|
||||||
|
that.handler = function () {
|
||||||
|
const position = Cesium.SceneTransforms.wgs84ToWindowCoordinates(
|
||||||
|
that.sdk.viewer.scene, posi
|
||||||
|
);
|
||||||
|
if (position) {
|
||||||
|
let width = that.textDom.clientWidth * 1
|
||||||
|
let height = that.textDom.clientHeight * 1
|
||||||
|
that.textDom.style.left = `${position.x - width / 2}px`;
|
||||||
|
that.textDom.style.top = `${position.y - height}px`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
that.sdk.viewer.scene.postRender.addEventListener(that.handler);
|
||||||
|
}
|
||||||
async returnFun() {
|
async returnFun() {
|
||||||
return this.handler
|
return this.handler
|
||||||
}
|
}
|
||||||
|
get text() {
|
||||||
|
return this.options.text
|
||||||
|
}
|
||||||
|
set text(val) {
|
||||||
|
this.options.text = val
|
||||||
|
this.textDom.querySelector('textarea').value = val
|
||||||
|
this.callback(this.options)
|
||||||
|
}
|
||||||
get onClick() {
|
get onClick() {
|
||||||
return this.clickCallBack
|
return this.clickCallBack
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import AModelLoader from '../Obj/Base/LoadObjModel/AModelLoader'
|
|||||||
import { setSvg } from '../Obj/Element/svg'
|
import { setSvg } from '../Obj/Element/svg'
|
||||||
import Tools from '../Tools'
|
import Tools from '../Tools'
|
||||||
import { Proj } from '../Tools/proj'
|
import { Proj } from '../Tools/proj'
|
||||||
|
import { syncData, getSdk } from '../Global/MultiViewportMode'
|
||||||
import {
|
import {
|
||||||
unRegLeftClickCallback,
|
unRegLeftClickCallback,
|
||||||
unRegRightClickCallback,
|
unRegRightClickCallback,
|
||||||
@ -432,6 +433,8 @@ class YJEarth {
|
|||||||
if (x > left && x < left + width && y > top && y < top + height) {
|
if (x > left && x < left + width && y > top && y < top + height) {
|
||||||
if (_this.clickTextDom) {
|
if (_this.clickTextDom) {
|
||||||
_this.clickTextDom.style['pointer-events'] = 'none'
|
_this.clickTextDom.style['pointer-events'] = 'none'
|
||||||
|
_this.entityMap.get(_this.clickTextDom.id).getwords(_this.clickTextDom.getElementsByTagName('textarea')[0].value)
|
||||||
|
// _this.entityMap.get(_this.clickTextDom.id).isClick(movement.position, _this.clickTextDom.id)
|
||||||
}
|
}
|
||||||
_this.clickTextDom = textList[i]
|
_this.clickTextDom = textList[i]
|
||||||
textList[i].style['pointer-events'] = 'all'
|
textList[i].style['pointer-events'] = 'all'
|
||||||
@ -468,6 +471,11 @@ class YJEarth {
|
|||||||
x: e.clientX - layerX + width / 2,
|
x: e.clientX - layerX + width / 2,
|
||||||
y: e.clientY - layerY + height,
|
y: e.clientY - layerY + height,
|
||||||
}
|
}
|
||||||
|
let { sdkP } = getSdk()
|
||||||
|
if (_this != sdkP && sdkP) {//二维
|
||||||
|
let num = sdkP.viewer._element.clientWidth
|
||||||
|
param.x = param.x - num
|
||||||
|
}
|
||||||
_this.entityMap.get(_this.clickTextDom.id).setHandeler(param)
|
_this.entityMap.get(_this.clickTextDom.id).setHandeler(param)
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -479,14 +487,14 @@ class YJEarth {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_this.clickTextDom.addEventListener('mousedown', mousedown);
|
_this.clickTextDom.addEventListener('mousedown', mousedown);
|
||||||
document.addEventListener('mousemove', mousemove);
|
_this.viewer._element.addEventListener('mousemove', mousemove);
|
||||||
document.addEventListener('mouseup', mouseup);
|
_this.viewer._element.addEventListener('mouseup', mouseup);
|
||||||
}
|
}
|
||||||
// 点击其他地方取消
|
// 点击其他地方取消
|
||||||
if (!_this.isLeftClick && _this.clickTextDom) {
|
if (!_this.isLeftClick && _this.clickTextDom) {
|
||||||
_this.clickTextDom.removeEventListener('mousedown', mousedown);
|
_this.clickTextDom.removeEventListener('mousedown', mousedown);
|
||||||
document.removeEventListener('mousemove', mousemove);
|
_this.viewer._element.removeEventListener('mousemove', mousemove);
|
||||||
document.removeEventListener('mouseup', mouseup);
|
_this.viewer._element.removeEventListener('mouseup', mouseup);
|
||||||
_this.entityMap.get(_this.clickTextDom.id).getwords(_this.clickTextDom.getElementsByTagName('textarea')[0].value)
|
_this.entityMap.get(_this.clickTextDom.id).getwords(_this.clickTextDom.getElementsByTagName('textarea')[0].value)
|
||||||
|
|
||||||
_this.clickTextDom.style['pointer-events'] = 'none'
|
_this.clickTextDom.style['pointer-events'] = 'none'
|
||||||
|
Reference in New Issue
Block a user