文本框 拖拉拽功能
This commit is contained in:
@ -173,6 +173,9 @@ function MouseRightMenu(sdk, status, callBack) {
|
|||||||
// that.edit(true)
|
// that.edit(true)
|
||||||
// this.attribute(entityId)
|
// this.attribute(entityId)
|
||||||
break
|
break
|
||||||
|
case '文本框':
|
||||||
|
object.position = position
|
||||||
|
break
|
||||||
}
|
}
|
||||||
eventListener[sdk.div_id].callBack(key, object)
|
eventListener[sdk.div_id].callBack(key, object)
|
||||||
_element.removeChild(menuElm)
|
_element.removeChild(menuElm)
|
||||||
|
@ -185,6 +185,8 @@ import Frustum from '../Obj/AirLine/frustum'
|
|||||||
import DrawTakeOff from '../Obj/AirLine/DrawTakeOff'
|
import DrawTakeOff from '../Obj/AirLine/DrawTakeOff'
|
||||||
import FlowLine from '../Obj/Base/FlowLine'
|
import FlowLine from '../Obj/Base/FlowLine'
|
||||||
import Sunshine from '../Global/efflect/Sunshine'
|
import Sunshine from '../Global/efflect/Sunshine'
|
||||||
|
// import Road2 from '../Obj/Base/RoadObject'
|
||||||
|
import TextBox from '../Obj/Base/TextBox'
|
||||||
|
|
||||||
const YJEarthismeasuring = Symbol('测量状态')
|
const YJEarthismeasuring = Symbol('测量状态')
|
||||||
const screenRecord = Symbol('录屏对象')
|
const screenRecord = Symbol('录屏对象')
|
||||||
@ -256,7 +258,9 @@ if (!window.YJ) {
|
|||||||
FRUSTUN: Frustum,
|
FRUSTUN: Frustum,
|
||||||
// GenerateRoute
|
// GenerateRoute
|
||||||
Dialog,
|
Dialog,
|
||||||
FlowLine
|
FlowLine,
|
||||||
|
// Road2,
|
||||||
|
TextBox
|
||||||
},
|
},
|
||||||
YJEarth,
|
YJEarth,
|
||||||
Tools,
|
Tools,
|
||||||
|
109
src/Obj/Base/TextBox/index.js
Normal file
109
src/Obj/Base/TextBox/index.js
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
/**
|
||||||
|
* 文本框
|
||||||
|
*/
|
||||||
|
import Base from "../index";
|
||||||
|
class TextBox extends Base {
|
||||||
|
constructor(sdk, options = {}) {
|
||||||
|
// this.sdk = { ...sdk }
|
||||||
|
// this.options = { ...options }
|
||||||
|
super(sdk, options)
|
||||||
|
this.clickTextDom = undefined
|
||||||
|
this.handler = undefined
|
||||||
|
this.textDom = undefined
|
||||||
|
this.create(this)
|
||||||
|
this.sdk.addIncetance(this.options.id, this)
|
||||||
|
}
|
||||||
|
|
||||||
|
async create(that) {
|
||||||
|
let viewer = that.sdk.viewer
|
||||||
|
// 创建div元素
|
||||||
|
let dom = document.createElement('span');
|
||||||
|
dom.id = that.options.id
|
||||||
|
dom.className = 'popup-textarea'
|
||||||
|
// 创建textarea元素
|
||||||
|
var textarea = document.createElement('textarea');
|
||||||
|
textarea.className = 'textarea'
|
||||||
|
// 设置textarea的属性,例如行数和列数
|
||||||
|
textarea.rows = 6;
|
||||||
|
textarea.style.resize = 'none'
|
||||||
|
// 将textarea添加到div中
|
||||||
|
dom.appendChild(textarea);
|
||||||
|
// 将div添加到body中
|
||||||
|
// document.body.appendChild(dom);
|
||||||
|
|
||||||
|
// 配置CSS样式和内容结构
|
||||||
|
viewer.cesiumWidget.container.appendChild(dom);
|
||||||
|
let posi = Cesium.Cartesian3.fromDegrees(that.options.positions.lng, that.options.positions.lat, that.options.positions.alt)
|
||||||
|
|
||||||
|
that.handler = function () {
|
||||||
|
const position = Cesium.SceneTransforms.wgs84ToWindowCoordinates(
|
||||||
|
viewer.scene, posi
|
||||||
|
);
|
||||||
|
let width = dom.clientWidth * 1
|
||||||
|
let height = dom.clientHeight * 1
|
||||||
|
dom.style.left = `${position.x - width / 2}px`;
|
||||||
|
dom.style.top = `${position.y - height}px`;
|
||||||
|
}
|
||||||
|
viewer.scene.postRender.addEventListener(that.handler);
|
||||||
|
that.textDom = dom
|
||||||
|
}
|
||||||
|
async setHandeler(data) {
|
||||||
|
let that = this
|
||||||
|
const ray = this.sdk.viewer.camera.getPickRay(new Cesium.Cartesian2(data.x, data.y));
|
||||||
|
var cartesian = this.sdk.viewer.scene.globe.pick(ray, this.sdk.viewer.scene);
|
||||||
|
if (Cesium.defined(cartesian)) {
|
||||||
|
that.sdk.viewer.scene.postRender.removeEventListener(that.handler);
|
||||||
|
|
||||||
|
var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
|
||||||
|
var longitude = Cesium.Math.toDegrees(cartographic.longitude);
|
||||||
|
var latitude = Cesium.Math.toDegrees(cartographic.latitude);
|
||||||
|
that.positions = {
|
||||||
|
lng: longitude,
|
||||||
|
lat: latitude,
|
||||||
|
alt: cartographic.height
|
||||||
|
}
|
||||||
|
let posi = Cesium.Cartesian3.fromDegrees(longitude, latitude, cartographic.height)
|
||||||
|
|
||||||
|
that.handler = function () {
|
||||||
|
const position = Cesium.SceneTransforms.wgs84ToWindowCoordinates(
|
||||||
|
that.sdk.viewer.scene, posi
|
||||||
|
);
|
||||||
|
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() {
|
||||||
|
return this.handler
|
||||||
|
}
|
||||||
|
get show() {
|
||||||
|
return this.options.show
|
||||||
|
}
|
||||||
|
set show(v) {
|
||||||
|
this.options.show = v
|
||||||
|
this.textDom && (this.textDom.style.display = v ? 'block' : 'none');
|
||||||
|
}
|
||||||
|
get positions() {
|
||||||
|
return this.options.positions
|
||||||
|
}
|
||||||
|
set positions(v) {
|
||||||
|
this.options.positions = v
|
||||||
|
}
|
||||||
|
|
||||||
|
async remove() {
|
||||||
|
if (this.handler) {
|
||||||
|
this.sdk.viewer.scene.postRender.removeEventListener(this.handler);
|
||||||
|
this.handler = undefined
|
||||||
|
}
|
||||||
|
if (this.textDom && this.textDom.parentNode) {
|
||||||
|
this.sdk.viewer.cesiumWidget.container.removeChild(this.textDom);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
flicker() { }
|
||||||
|
}
|
||||||
|
|
||||||
|
export default TextBox
|
@ -46,16 +46,18 @@ class YJEarth {
|
|||||||
// setCesiumIndexedDBMaxSize(getCesiumIndexedDBMaxSize())
|
// setCesiumIndexedDBMaxSize(getCesiumIndexedDBMaxSize())
|
||||||
setCesiumManageIndexexDBState(getCesiumManageIndexexDBState())
|
setCesiumManageIndexexDBState(getCesiumManageIndexexDBState())
|
||||||
this.proj = new Proj()
|
this.proj = new Proj()
|
||||||
|
this.clickTextDom = undefined
|
||||||
|
this.isLeftClick = false
|
||||||
this.init()
|
this.init()
|
||||||
setSvg()
|
setSvg()
|
||||||
}
|
}
|
||||||
|
|
||||||
addIncetance(id, obj) {
|
addIncetance(id, obj) {
|
||||||
this.entityMap.set(id, obj)
|
this.entityMap.set(id + '', obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
getIncetance(id) {
|
getIncetance(id) {
|
||||||
return this.entityMap.get(id)
|
return this.entityMap.get(id + '')
|
||||||
}
|
}
|
||||||
|
|
||||||
removeIncetance(id) {
|
removeIncetance(id) {
|
||||||
@ -221,11 +223,11 @@ class YJEarth {
|
|||||||
|
|
||||||
document.fonts.ready.then(() => {
|
document.fonts.ready.then(() => {
|
||||||
for (let [id, obj] of this.entityMap) {
|
for (let [id, obj] of this.entityMap) {
|
||||||
if('labelFontFamily' in obj) {
|
if ('labelFontFamily' in obj) {
|
||||||
obj.labelFontFamily = obj.labelFontFamily
|
obj.labelFontFamily = obj.labelFontFamily
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// const font = new FontFace(
|
// const font = new FontFace(
|
||||||
@ -413,6 +415,94 @@ class YJEarth {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let ClickHandler = new Cesium.ScreenSpaceEventHandler(_this.viewer.canvas)
|
||||||
|
ClickHandler.setInputAction((movement) => {
|
||||||
|
let textList = document.getElementsByClassName('popup-textarea')
|
||||||
|
_this.isLeftClick = false
|
||||||
|
for (let i = textList.length - 1; i > -1; i--) {
|
||||||
|
let left = returnNumber(textList[i].style.left)
|
||||||
|
let top = returnNumber(textList[i].style.top)
|
||||||
|
let width = textList[i].clientWidth * 1
|
||||||
|
let height = textList[i].clientHeight * 1
|
||||||
|
let x = movement.position.x
|
||||||
|
let y = movement.position.y
|
||||||
|
if (x > left && x < left + width && y > top && y < top + height) {
|
||||||
|
if (_this.clickTextDom) {
|
||||||
|
_this.clickTextDom.style['pointer-events'] = 'none'
|
||||||
|
}
|
||||||
|
_this.clickTextDom = textList[i]
|
||||||
|
textList[i].style['pointer-events'] = 'all'
|
||||||
|
textList[i].querySelector('textarea').focus()
|
||||||
|
_this.isLeftClick = true
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mousedown = undefined
|
||||||
|
let mousemove = undefined
|
||||||
|
let mouseup = undefined
|
||||||
|
let fun = undefined
|
||||||
|
let handler = undefined
|
||||||
|
|
||||||
|
if (_this.isLeftClick) {
|
||||||
|
let click = false
|
||||||
|
let layerX = 0
|
||||||
|
let layerY = 0
|
||||||
|
|
||||||
|
mousedown = function (e) {
|
||||||
|
layerX = e.layerX
|
||||||
|
layerY = e.layerY
|
||||||
|
click = true
|
||||||
|
}
|
||||||
|
mousemove = function (e) {
|
||||||
|
if (!click) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let width = _this.clickTextDom.clientWidth * 1
|
||||||
|
let height = _this.clickTextDom.clientHeight * 1
|
||||||
|
let param = {
|
||||||
|
x: e.clientX - layerX + width / 2,
|
||||||
|
y: e.clientY - layerY + height,
|
||||||
|
}
|
||||||
|
_this.entityMap.get(_this.clickTextDom.id).setHandeler(param)
|
||||||
|
|
||||||
|
}
|
||||||
|
mouseup = function (e) {
|
||||||
|
if (!click) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
click = false
|
||||||
|
}
|
||||||
|
|
||||||
|
_this.clickTextDom.addEventListener('mousedown', mousedown);
|
||||||
|
document.addEventListener('mousemove', mousemove);
|
||||||
|
document.addEventListener('mouseup', mouseup);
|
||||||
|
}
|
||||||
|
// 点击其他地方取消
|
||||||
|
if (!_this.isLeftClick && _this.clickTextDom) {
|
||||||
|
_this.clickTextDom.removeEventListener('mousedown', mousedown);
|
||||||
|
document.removeEventListener('mousemove', mousemove);
|
||||||
|
document.removeEventListener('mouseup', mouseup);
|
||||||
|
|
||||||
|
_this.clickTextDom.style['pointer-events'] = 'none'
|
||||||
|
_this.clickTextDom = undefined
|
||||||
|
|
||||||
|
}
|
||||||
|
}, Cesium.ScreenSpaceEventType.LEFT_CLICK)
|
||||||
|
|
||||||
|
// ClickHandler.setInputAction((movement) => {
|
||||||
|
// if (_this.clickTextDom) {
|
||||||
|
// _this.clickTextDom.style['pointer-events'] = 'none'
|
||||||
|
// _this.clickTextDom = undefined
|
||||||
|
// }
|
||||||
|
// }, Cesium.ScreenSpaceEventType.LEFT_CLICK)
|
||||||
|
function returnNumber(str) {
|
||||||
|
let index = str.indexOf('px')
|
||||||
|
return Number(str.slice(0, index))
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
|
@ -3043,6 +3043,42 @@
|
|||||||
background-size: 100% 100%;
|
background-size: 100% 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 文本框 */
|
||||||
|
.popup-textarea{
|
||||||
|
/* width: 212px; */
|
||||||
|
width: 161.6px;
|
||||||
|
/* height: 154px; */
|
||||||
|
height: 119.2px;
|
||||||
|
display: block;
|
||||||
|
pointer-events: none;
|
||||||
|
position: absolute;
|
||||||
|
/* z-index: 99; */
|
||||||
|
background: url(../../img/pop.png) 100% 100% no-repeat;
|
||||||
|
background-size: 100% 100%;
|
||||||
|
padding: 5px 5px 0px 5px;
|
||||||
|
}
|
||||||
|
.popup-textarea textarea{
|
||||||
|
background-color: unset!important;
|
||||||
|
border: unset!important;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
.popup-textarea textarea::-webkit-scrollbar {
|
||||||
|
width: 8px!important;
|
||||||
|
/* height: 8px!important; */
|
||||||
|
}
|
||||||
|
|
||||||
|
.popup-textarea textarea::-webkit-scrollbar-thumb {
|
||||||
|
border-radius: 5px!important;
|
||||||
|
-webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2)!important;
|
||||||
|
background-color: rgba(var(--color-sdk-base-rgb))!important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.popup-textarea textarea::-webkit-scrollbar-track {
|
||||||
|
-webkit-box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2)!important;
|
||||||
|
border-radius: 5px!important;
|
||||||
|
background-color: rgba(var(--color-sdk-base-rgb), 0.1)!important;
|
||||||
|
}
|
||||||
|
|
||||||
/* 贴地图片 */
|
/* 贴地图片 */
|
||||||
.YJ-custom-base-dialog.ground-image>.content {
|
.YJ-custom-base-dialog.ground-image>.content {
|
||||||
width: 500px;
|
width: 500px;
|
||||||
|
BIN
static/img/pop.png
Normal file
BIN
static/img/pop.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 868 B |
Reference in New Issue
Block a user