From b4f7e7ad8fc748925b319180701ff8dd6b86f05d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E5=A4=A7=E8=83=86?= <1101282782@qq.com> Date: Thu, 14 Aug 2025 11:53:06 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=96=87=E6=9C=AC=E6=A1=86=20=E6=8B=96?= =?UTF-8?q?=E6=8B=89=E6=8B=BD=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Global/mouseRightMenu/index.js | 3 + src/In/index.js | 6 +- src/Obj/Base/TextBox/index.js | 109 +++++++++++++++++++++++++++++ src/YJEarth/index.js | 98 ++++++++++++++++++++++++-- static/custom/css/index.css | 36 ++++++++++ static/img/pop.png | Bin 0 -> 868 bytes 6 files changed, 247 insertions(+), 5 deletions(-) create mode 100644 src/Obj/Base/TextBox/index.js create mode 100644 static/img/pop.png diff --git a/src/Global/mouseRightMenu/index.js b/src/Global/mouseRightMenu/index.js index 818271b..0fd350e 100644 --- a/src/Global/mouseRightMenu/index.js +++ b/src/Global/mouseRightMenu/index.js @@ -173,6 +173,9 @@ function MouseRightMenu(sdk, status, callBack) { // that.edit(true) // this.attribute(entityId) break + case '文本框': + object.position = position + break } eventListener[sdk.div_id].callBack(key, object) _element.removeChild(menuElm) diff --git a/src/In/index.js b/src/In/index.js index 8120864..3fae21c 100644 --- a/src/In/index.js +++ b/src/In/index.js @@ -185,6 +185,8 @@ import Frustum from '../Obj/AirLine/frustum' import DrawTakeOff from '../Obj/AirLine/DrawTakeOff' import FlowLine from '../Obj/Base/FlowLine' import Sunshine from '../Global/efflect/Sunshine' +// import Road2 from '../Obj/Base/RoadObject' +import TextBox from '../Obj/Base/TextBox' const YJEarthismeasuring = Symbol('测量状态') const screenRecord = Symbol('录屏对象') @@ -256,7 +258,9 @@ if (!window.YJ) { FRUSTUN: Frustum, // GenerateRoute Dialog, - FlowLine + FlowLine, + // Road2, + TextBox }, YJEarth, Tools, diff --git a/src/Obj/Base/TextBox/index.js b/src/Obj/Base/TextBox/index.js new file mode 100644 index 0000000..e78e9a9 --- /dev/null +++ b/src/Obj/Base/TextBox/index.js @@ -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 diff --git a/src/YJEarth/index.js b/src/YJEarth/index.js index 5a12707..27a1dad 100644 --- a/src/YJEarth/index.js +++ b/src/YJEarth/index.js @@ -46,16 +46,18 @@ class YJEarth { // setCesiumIndexedDBMaxSize(getCesiumIndexedDBMaxSize()) setCesiumManageIndexexDBState(getCesiumManageIndexexDBState()) this.proj = new Proj() + this.clickTextDom = undefined + this.isLeftClick = false this.init() setSvg() } addIncetance(id, obj) { - this.entityMap.set(id, obj) + this.entityMap.set(id + '', obj) } getIncetance(id) { - return this.entityMap.get(id) + return this.entityMap.get(id + '') } removeIncetance(id) { @@ -221,11 +223,11 @@ class YJEarth { document.fonts.ready.then(() => { for (let [id, obj] of this.entityMap) { - if('labelFontFamily' in obj) { + if ('labelFontFamily' in obj) { obj.labelFontFamily = obj.labelFontFamily } } - + }); // 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() { diff --git a/static/custom/css/index.css b/static/custom/css/index.css index fc4b55b..421e48e 100644 --- a/static/custom/css/index.css +++ b/static/custom/css/index.css @@ -3043,6 +3043,42 @@ 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 { width: 500px; diff --git a/static/img/pop.png b/static/img/pop.png new file mode 100644 index 0000000000000000000000000000000000000000..59f94d1680023d7bdb7b7d47348ea397d1ddd292 GIT binary patch literal 868 zcmeAS@N?(olHy`uVBq!ia0vp^SAcjH2OE&Q*ptQrq!^2X+?^QKos)S9Y69z4hk-FdLe9T%5w<80X~xvT1eJS#M5{jI%9GDnL_a1_(S^$^xd|FI4dG z6xgzA)w5~*N_(C*t2jDN@a6Q3Y5KtM^!Yi(p zRY#SVzkhCbVs&x-|8?ii@4xo;?e>%Q)tf7$k00lsT>s8{dt7~H@%)EZrILfMUzdOV z=FQn9fwsp=Dt;`C+CBG8aXhEv+00ifj(mB;V!D0hBB9GFEL&O5%TAr4ro3Wl#kv(o zOf(&JJ*~71ef{~KndY1m;UC4Bt@|} zzHPR5Rb6&e;L5%qu|NS4$G4N?7Yhm7T$Gr-YuBzdlP8}qEiH{q&Ut1h^k%!E+19)B ex-u*GF}J1OKl*yFS_3erFnGH9xvX Date: Thu, 14 Aug 2025 12:01:59 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BA=BF=E6=8A=A5?= =?UTF-8?q?=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Obj/Base/PolylineObject/index.js | 60 ++++++++++++++-------------- src/Tools/index.js | 54 ++++++++++++------------- 2 files changed, 58 insertions(+), 56 deletions(-) diff --git a/src/Obj/Base/PolylineObject/index.js b/src/Obj/Base/PolylineObject/index.js index cf58f8c..c1c148b 100644 --- a/src/Obj/Base/PolylineObject/index.js +++ b/src/Obj/Base/PolylineObject/index.js @@ -1460,39 +1460,41 @@ class PolylineObject extends Base { // let ray2 = this.sdk.viewer.camera.getPickRay(point2); // cartesian2 = this.sdk.viewer.scene.globe.pick(ray2, this.sdk.viewer.scene); // } - - var distance = Cesium.Cartesian3.distance(cartesian1, cartesian2); - - var repeatX = distance / entity.polyline.width.getValue(); - // 根据地图缩放程度调整repeatX - var cameraHeight = this.sdk.viewer.camera.positionCartographic.height; - var boundingSphere = new Cesium.BoundingSphere( - new Cesium.Cartesian3(-1000000, 0, 0), // 中心点坐标 - 500000 // 半径(距离) - ); + if (cartesian1 && cartesian2) { - // 获取绘图缓冲区的宽度和高度(通常是屏幕的分辨率) - var drawingBufferWidth = this.sdk.viewer.canvas.clientWidth; - var drawingBufferHeight = this.sdk.viewer.canvas.clientHeight; + var distance = Cesium.Cartesian3.distance(cartesian1, cartesian2); - // 使用 getPixelSize 方法获取包围球在屏幕上的像素大小 - var groundResolution = this.sdk.viewer.scene.camera.getPixelSize(boundingSphere, drawingBufferWidth, drawingBufferHeight) - // repeatX *= groundResolution / cameraHeight / ((myImg.width / myImg.height * 5) + 1); - if (groundResolution > 700) { - repeatX *= groundResolution / cameraHeight / (options.space * (canvasEle.width / canvasEle.height * 5) + 1); - } else { - repeatX = undefined; + var repeatX = distance / entity.polyline.width.getValue(); + // 根据地图缩放程度调整repeatX + var cameraHeight = this.sdk.viewer.camera.positionCartographic.height; + var boundingSphere = new Cesium.BoundingSphere( + new Cesium.Cartesian3(-1000000, 0, 0), // 中心点坐标 + 500000 // 半径(距离) + ); + + + // 获取绘图缓冲区的宽度和高度(通常是屏幕的分辨率) + var drawingBufferWidth = this.sdk.viewer.canvas.clientWidth; + var drawingBufferHeight = this.sdk.viewer.canvas.clientHeight; + + // 使用 getPixelSize 方法获取包围球在屏幕上的像素大小 + var groundResolution = this.sdk.viewer.scene.camera.getPixelSize(boundingSphere, drawingBufferWidth, drawingBufferHeight) + // repeatX *= groundResolution / cameraHeight / ((myImg.width / myImg.height * 5) + 1); + if (groundResolution > 700) { + repeatX *= groundResolution / cameraHeight / (options.space * (canvasEle.width / canvasEle.height * 5) + 1); + } else { + repeatX = undefined; + } + + if (this.sdk.viewer.scene.mode === Cesium.SceneMode.SCENE3D) { + return repeatX + } else { + let sdk3d = get3DView() + let sdk3dEntity = sdk3d.viewer.entities.getById(this.options.id) + return sdk3dEntity.polyline.oriRepeatX + } } - - if (this.sdk.viewer.scene.mode === Cesium.SceneMode.SCENE3D) { - return repeatX - } else { - let sdk3d = get3DView() - let sdk3dEntity = sdk3d.viewer.entities.getById(this.options.id) - return sdk3dEntity.polyline.oriRepeatX - } - } /** * 编辑框 diff --git a/src/Tools/index.js b/src/Tools/index.js index 0674a47..7716ae3 100644 --- a/src/Tools/index.js +++ b/src/Tools/index.js @@ -880,38 +880,38 @@ class Tools { let ray2 = this.sdk.viewer.camera.getPickRay(point2); let cartesian2 = this.sdk.viewer.scene.globe.pick(ray2, this.sdk.viewer.scene); + if (cartesian1 && cartesian2) { + var distance = Cesium.Cartesian3.distance(cartesian1, cartesian2); - var distance = Cesium.Cartesian3.distance(cartesian1, cartesian2); + var repeatX = distance / entity.polyline.width.getValue(); + // 根据地图缩放程度调整repeatX + var cameraHeight = this.sdk.viewer.camera.positionCartographic.height; + var boundingSphere = new Cesium.BoundingSphere( + new Cesium.Cartesian3(-1000000, 0, 0), // 中心点坐标 + 500000 // 半径(距离) + ); - var repeatX = distance / entity.polyline.width.getValue(); - // 根据地图缩放程度调整repeatX - var cameraHeight = this.sdk.viewer.camera.positionCartographic.height; - var boundingSphere = new Cesium.BoundingSphere( - new Cesium.Cartesian3(-1000000, 0, 0), // 中心点坐标 - 500000 // 半径(距离) - ); + // 获取绘图缓冲区的宽度和高度(通常是屏幕的分辨率) + var drawingBufferWidth = this.sdk.viewer.canvas.clientWidth; + var drawingBufferHeight = this.sdk.viewer.canvas.clientHeight; - // 获取绘图缓冲区的宽度和高度(通常是屏幕的分辨率) - var drawingBufferWidth = this.sdk.viewer.canvas.clientWidth; - var drawingBufferHeight = this.sdk.viewer.canvas.clientHeight; + // 使用 getPixelSize 方法获取包围球在屏幕上的像素大小 + var groundResolution = this.sdk.viewer.scene.camera.getPixelSize(boundingSphere, drawingBufferWidth, drawingBufferHeight) + // repeatX *= groundResolution / cameraHeight / ((myImg.width / myImg.height * 5) + 1); + if (groundResolution > 700) { + repeatX *= groundResolution / cameraHeight / (options.space * (canvasEle.width / canvasEle.height * 5) + 1); + } else { + repeatX = undefined; + } - // 使用 getPixelSize 方法获取包围球在屏幕上的像素大小 - var groundResolution = this.sdk.viewer.scene.camera.getPixelSize(boundingSphere, drawingBufferWidth, drawingBufferHeight) - // repeatX *= groundResolution / cameraHeight / ((myImg.width / myImg.height * 5) + 1); - if (groundResolution > 700) { - repeatX *= groundResolution / cameraHeight / (options.space * (canvasEle.width / canvasEle.height * 5) + 1); - } else { - repeatX = undefined; + if (this.sdk.viewer.scene.mode === Cesium.SceneMode.SCENE3D) { + return repeatX + } else { + let sdk3d = get3DView() + let sdk3dEntity = sdk3d.viewer.entities.getById(this.options.id) + return sdk3dEntity.polyline.oriRepeatX + } } - - if (this.sdk.viewer.scene.mode === Cesium.SceneMode.SCENE3D) { - return repeatX - } else { - let sdk3d = get3DView() - let sdk3dEntity = sdk3d.viewer.entities.getById(this.options.id) - return sdk3dEntity.polyline.oriRepeatX - } - } /*创建直箭头图片*/ From 713f03284bcbcf9c6e7b5a85d36f6a003f400c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E5=A4=A7=E8=83=86?= <1101282782@qq.com> Date: Fri, 15 Aug 2025 11:22:43 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=9B=B2=E7=BA=BF=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E6=8A=98=E7=BA=BF=E5=8A=A8=E6=80=81=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Obj/Base/CurvelineObject/_element.js | 34 +- src/Obj/Base/CurvelineObject/index.js | 384 ++++++++++++++++++++++- 2 files changed, 397 insertions(+), 21 deletions(-) diff --git a/src/Obj/Base/CurvelineObject/_element.js b/src/Obj/Base/CurvelineObject/_element.js index cc8b89a..24d6837 100644 --- a/src/Obj/Base/CurvelineObject/_element.js +++ b/src/Obj/Base/CurvelineObject/_element.js @@ -65,7 +65,7 @@ function html(that) { 线条颜色
-
+
线条宽度
@@ -73,7 +73,7 @@ function html(that) {
-
+
线条形式
@@ -83,7 +83,7 @@ function html(that) { 线段缓冲
-
+
缓冲宽度
@@ -91,21 +91,43 @@ function html(that) {
-
+
缓冲颜色
+
+
+ 动画顺向 + +
+
+ 流动速率 +
+ + +
+
+
+ 间距 +
+ + + +
+
+
首尾相连
-
+
-
+
+ ${labelStyleElm1()} diff --git a/src/Obj/Base/CurvelineObject/index.js b/src/Obj/Base/CurvelineObject/index.js index 0d61686..fc8b569 100644 --- a/src/Obj/Base/CurvelineObject/index.js +++ b/src/Obj/Base/CurvelineObject/index.js @@ -11,7 +11,7 @@ import LabelObject from '../LabelObject' import MouseEvent from '../../../Event/index' import MouseTip from '../../../MouseTip' import Controller from '../../../Controller/index' -import { syncData } from '../../../Global/MultiViewportMode' +import { syncData, get3DView } from '../../../Global/MultiViewportMode' import { legp } from '../../Element/datalist' import { getFontList, getFontFamilyName } from '../../Element/fontSelect' import { setSplitDirection, syncSplitData, setActiveId } from '../../../Global/SplitScreen' @@ -56,6 +56,10 @@ class CurvelineObject extends Base { this.options.type = options.type ? Number(options.type) : 0 this.options['nose-to-tail'] = options['nose-to-tail'] || false this.options.extend = options.extend || false + this.options.rotate = options.rotate || true + this.options.space = options.space || 1 + this.options.speed = options.speed || 10 + this.options.dashSize = options.dashSize || 0.03 this.options['length-unit'] = options['length-unit'] || '米' this.options['fit-length-unit'] = options['fit-length-unit'] || '米' this.options['words-name'] = options['words-name'] || '空间长度' @@ -146,7 +150,8 @@ class CurvelineObject extends Base { } set color(v) { this.options.color = v || '#ff0000' - this.entity.polyline.material = this.getMaterial(v, this.options.type) + // this.entity.polyline.material = this.getMaterial(v, this.options.type) + this.entity.polyline.material = this.getMaterial(this.options.color, this.options.type, this.entity, this.options) if (this._elms.color) { this._elms.color.forEach((item, i) => { let colorPicker = new YJColorPicker({ @@ -167,6 +172,48 @@ class CurvelineObject extends Base { }) } } + get speed() { + return this.options.speed + } + + set speed(v) { + // this.options.speed = v + this.options.speed = v !== 0 ? Math.pow(v, -1) * 100 : 0 + this.entity.polyline.material = this.getMaterial(this.options.color, this.options.type, this.entity, this.options) + } + get dashSize() { + return this.options.dashSize + } + + set dashSize(v) { + this.options.dashSize = v + this.entity.polyline.material = this.getMaterial(this.options.color, this.options.type, this.entity, this.options) + } + + get rotate() { + return this.options.rotate + } + + set rotate(v) { + this.options.rotate = v + CurvelineObject.closeNodeEdit(this) + this._elms.rotate && + this._elms.rotate.forEach(item => { + item.checked = v + }) + + this.options.rotate = v + this.entity.polyline.material = this.getMaterial(this.options.color, this.options.type, this.entity, this.options) + } + + get space() { + return this.options.space + } + + set space(v) { + this.options.space = v + this.entity.polyline.material = this.getMaterial(this.options.color, this.options.type, this.entity, this.options) + } get length() { return this.options.length @@ -299,19 +346,82 @@ class CurvelineObject extends Base { set lineType(v) { let lineTypeData = [ { - name: '实线', + name: '实线', value: '实线', - key: 0 + key: 0, + icon: 'line' }, { - name: '虚线', + name: '虚线', value: '虚线', - key: 1 + key: 1, + icon: 'dash-line' }, { - name: '泛光', + name: '泛光', value: '泛光', - key: 2 + key: 2, + icon: 'light-line' + }, + { + name: '尾迹光线', + value: '尾迹光线', + key: 3, + icon: 'tail-line' + }, + { + name: '多尾迹光线', + value: '多尾迹光线', + key: 4, + icon: 'mult-tail-line' + }, + { + name: '流动虚线1', + value: '流动虚线1', + key: 5, + icon: 'flow-dash-line1' + }, + { + name: '流动虚线2', + value: '流动虚线2', + key: 6, + icon: 'flow-dash-line2' + }, + { + name: '流动箭头1', + value: '流动箭头1', + key: 7, + icon: 'pic-line1' + }, + { + name: '流动箭头2', + value: '流动箭头2', + key: 8, + icon: 'pic-line2' + }, + { + name: '流动箭头3', + value: '流动箭头3', + key: 9, + icon: 'pic-line3' + }, + { + name: '流动箭头4', + value: '流动箭头4', + key: 10, + icon: 'pic-line4' + }, + { + name: '流动箭头5', + value: '流动箭头5', + key: 11, + icon: 'pic-line5' + }, + { + name: '流动箭头6', + value: '流动箭头6', + key: 12, + icon: 'pic-line6' } ] this.options.type = Number(v) @@ -320,6 +430,18 @@ class CurvelineObject extends Base { this._elms.lineType && this._elms.lineType.forEach(item => { item.value = lineTypeData[i].value + if (2 < item.value && item.value < 13) {//贴图参数 + document.getElementById('dashTextureDom') && (document.getElementById('dashTextureDom').style.display = 'flex') + } else { + document.getElementById('dashTextureDom') && (document.getElementById('dashTextureDom').style.display = 'none') + } + if (2 < item.value && item.value < 5) {//尾迹参数 + document.getElementsByClassName('lineSpace')[0] && (document.getElementsByClassName('lineSpace')[0].style.display = 'none') + document.getElementsByClassName('lineSpace')[1] && (document.getElementsByClassName('lineSpace')[1].style.display = 'none') + } else { + document.getElementsByClassName('lineSpace')[0] && (document.getElementsByClassName('lineSpace')[0].style.display = 'flex') + document.getElementsByClassName('lineSpace')[1] && (document.getElementsByClassName('lineSpace')[1].style.display = 'flex') + } }) break } @@ -328,7 +450,9 @@ class CurvelineObject extends Base { this.entity.polyline && (this.entity.polyline.material = this.getMaterial( this.options.color, - this.options.type + this.options.type, + this.entity, + this.options )) } get noseToTail() { @@ -1212,6 +1336,16 @@ class CurvelineObject extends Base { zIndex: that.sdk._entityZIndex } }) + + that.entity.polyline.oriWidth = that.options.width + that.judgeLine(that.entity, that.options) + that.entity.polyline.material = that.getMaterial( + that.options.color, + that.options.type, + that.entity, + that.options + ) + that.sdk._entityZIndex++ CurvelineObject.createLabel(that) // that.entity.polyline.positionsLngLat = positions @@ -1252,7 +1386,130 @@ class CurvelineObject extends Base { let scene = that.sdk.viewer.scene } + judgeLine(entity, newParam) { + if (!entity.polyline.oriRepeat) { + let param = { + color: newParam.color, + image: this.getSourceRootPath() + `/img/arrow/1.png`, + space: newParam.space, + speed: newParam.speed + } + param.speed = newParam.rotate ? param.speed : 0 - param.speed + + const canvasEle = document.createElement('canvas'); + const ctx = canvasEle.getContext('2d') + const myImg = new Image() + // myImg.src = that.getSourceRootPath() + '/img/arrow/1.png' + myImg.src = param.image + let that = this + myImg.onload = function () { + canvasEle.width = myImg.width * (param.space + 1) + canvasEle.height = myImg.height + + let oriRepeat = that.getSceenLine(entity, param, canvasEle) + oriRepeat && (entity.polyline.oriRepeat = oriRepeat) + + + var positionProperty = entity.polyline.positions; + var positions = positionProperty.getValue(that.sdk.viewer.clock.currentTime); + + if (!Cesium.defined(positions)) { + return new Cesium.Cartesian2(1.0, 1.0); + // return 1.0; + } + + var distance = 0; + for (var i = 0; i < positions.length - 1; ++i) { + distance += Cesium.Cartesian3.distance(positions[i], positions[i + 1]); + } + + var repeatX = distance / entity.polyline.width.getValue(); + // 根据地图缩放程度调整repeatX + var cameraHeight = that.sdk.viewer.camera.positionCartographic.height; + var boundingSphere = new Cesium.BoundingSphere( + new Cesium.Cartesian3(-1000000, 0, 0), // 中心点坐标 + 500000 // 半径(距离) + ); + + // 获取绘图缓冲区的宽度和高度(通常是屏幕的分辨率) + var drawingBufferWidth = that.sdk.viewer.canvas.clientWidth; + var drawingBufferHeight = that.sdk.viewer.canvas.clientHeight; + + // 使用 getPixelSize 方法获取包围球在屏幕上的像素大小 + var groundResolution = that.sdk.viewer.scene.camera.getPixelSize(boundingSphere, drawingBufferWidth, drawingBufferHeight) + repeatX *= groundResolution / cameraHeight / (param.space * (canvasEle.width / canvasEle.height * 5) + 1); + // if (entity.polyline.material.oriRepeat) { + + if (that.sdk.viewer.scene.mode === Cesium.SceneMode.SCENE3D) { + let speed = repeatX / entity.polyline.oriRepeat + entity.polyline.oriSpeed = speed + entity.polyline.oriRepeatX = repeatX + } else { + let sdk3d = get3DView() + let sdk3dEntity = sdk3d.viewer.entities.getById(that.options.id) + entity.polyline.oriSpeed = sdk3dEntity.polyline.oriSpeed + entity.polyline.oriRepeatX = sdk3dEntity.polyline.oriRepeatX + } + } + + } + } + /**获取当前满屏横线速度 */ + getSceenLine(entity, options, canvasEle) { + let point1 = new Cesium.Cartesian2(0, this.sdk.viewer.canvas.clientHeight) + let point2 = new Cesium.Cartesian2(this.sdk.viewer.canvas.clientWidth / 2, this.sdk.viewer.canvas.clientHeight) + // var cartesian1 = this.sdk.viewer.scene.pickPosition(point1) + // var cartesian2 = this.sdk.viewer.scene.pickPosition(point2) + + let ray = this.sdk.viewer.camera.getPickRay(point1); + let cartesian1 = this.sdk.viewer.scene.globe.pick(ray, this.sdk.viewer.scene); + + let ray2 = this.sdk.viewer.camera.getPickRay(point2); + let cartesian2 = this.sdk.viewer.scene.globe.pick(ray2, this.sdk.viewer.scene); + // if (!cartesian1 || !cartesian2) { + // let ray = this.sdk.viewer.camera.getPickRay(point1); + // cartesian1 = this.sdk.viewer.scene.globe.pick(ray, this.sdk.viewer.scene); + + // let ray2 = this.sdk.viewer.camera.getPickRay(point2); + // cartesian2 = this.sdk.viewer.scene.globe.pick(ray2, this.sdk.viewer.scene); + // } + if (cartesian1 && cartesian2) { + + + var distance = Cesium.Cartesian3.distance(cartesian1, cartesian2); + + var repeatX = distance / entity.polyline.width.getValue(); + // 根据地图缩放程度调整repeatX + var cameraHeight = this.sdk.viewer.camera.positionCartographic.height; + var boundingSphere = new Cesium.BoundingSphere( + new Cesium.Cartesian3(-1000000, 0, 0), // 中心点坐标 + 500000 // 半径(距离) + ); + + + // 获取绘图缓冲区的宽度和高度(通常是屏幕的分辨率) + var drawingBufferWidth = this.sdk.viewer.canvas.clientWidth; + var drawingBufferHeight = this.sdk.viewer.canvas.clientHeight; + + // 使用 getPixelSize 方法获取包围球在屏幕上的像素大小 + var groundResolution = this.sdk.viewer.scene.camera.getPixelSize(boundingSphere, drawingBufferWidth, drawingBufferHeight) + // repeatX *= groundResolution / cameraHeight / ((myImg.width / myImg.height * 5) + 1); + if (groundResolution > 700) { + repeatX *= groundResolution / cameraHeight / (options.space * (canvasEle.width / canvasEle.height * 5) + 1); + } else { + repeatX = undefined; + } + + if (this.sdk.viewer.scene.mode === Cesium.SceneMode.SCENE3D) { + return repeatX + } else { + let sdk3d = get3DView() + let sdk3dEntity = sdk3d.viewer.entities.getById(this.options.id) + return sdk3dEntity.polyline.oriRepeatX + } + } + } /** * 编辑框 * @param {boolean} state true打开,false关闭 @@ -1327,6 +1584,15 @@ class CurvelineObject extends Base { this.attributeType = this.options.attributeType // this.attributeCamera = this.options.attribute.camera.content // this.attributeGoods = this.options.attribute.goods.content + function tabClick(e) { + if (e === '2' || e === 2) {//点击线条样式 + if (2 < _this.options.type && _this.options.type < 13) {//贴图参数 + document.getElementById('dashTextureDom') && (document.getElementById('dashTextureDom').style.display = 'flex') + } else { + document.getElementById('dashTextureDom') && (document.getElementById('dashTextureDom').style.display = 'none') + } + } + } // 创建标签页 let tabsElm = new cy_tabs( @@ -1590,19 +1856,82 @@ class CurvelineObject extends Base { let lineTypeData = [ { - name: '实线', + name: '实线', value: '实线', - key: 0 + key: 0, + icon: 'line' }, { - name: '虚线', + name: '虚线', value: '虚线', - key: 1 + key: 1, + icon: 'dash-line' }, { - name: '泛光', + name: '泛光', value: '泛光', - key: 2 + key: 2, + icon: 'light-line' + }, + { + name: '尾迹光线', + value: '尾迹光线', + key: 3, + icon: 'tail-line' + }, + { + name: '多尾迹光线', + value: '多尾迹光线', + key: 4, + icon: 'mult-tail-line' + }, + { + name: '流动虚线1', + value: '流动虚线1', + key: 5, + icon: 'flow-dash-line1' + }, + { + name: '流动虚线2', + value: '流动虚线2', + key: 6, + icon: 'flow-dash-line2' + }, + { + name: '流动箭头1', + value: '流动箭头1', + key: 7, + icon: 'pic-line1' + }, + { + name: '流动箭头2', + value: '流动箭头2', + key: 8, + icon: 'pic-line2' + }, + { + name: '流动箭头3', + value: '流动箭头3', + key: 9, + icon: 'pic-line3' + }, + { + name: '流动箭头4', + value: '流动箭头4', + key: 10, + icon: 'pic-line4' + }, + { + name: '流动箭头5', + value: '流动箭头5', + key: 11, + icon: 'pic-line5' + }, + { + name: '流动箭头6', + value: '流动箭头6', + key: 12, + icon: 'pic-line6' } ] let lineTypeDataLegpObject = legp( @@ -1613,6 +1942,11 @@ class CurvelineObject extends Base { ) if (lineTypeDataLegpObject) { lineTypeDataLegpObject.legp_search(lineTypeData) + + let iActiveElm2 = document.createElement('i') + iActiveElm2.className = 'icon icon-active' + this._DialogObject._element.content.getElementsByClassName('input-select-line-type')[0].getElementsByClassName('cy_datalist')[0].appendChild(iActiveElm2) + let lineTypeDataLegpElm = this._DialogObject._element.content .getElementsByClassName('input-select-line-type')[0] .getElementsByTagName('input')[0] @@ -1621,6 +1955,7 @@ class CurvelineObject extends Base { if (lineTypeData[i].key === this.options.type) { lineTypeDataLegpObject.legp_searchActive(lineTypeData[i].value) lineTypeDataLegpElm.value = lineTypeData[i].value + iActiveElm2.className = `icon icon-active ${lineTypeData[i].icon}` break } } @@ -1628,6 +1963,21 @@ class CurvelineObject extends Base { for (let i = 0; i < lineTypeData.length; i++) { if (lineTypeData[i].value === lineTypeDataLegpElm.value) { this.lineType = lineTypeData[i].key + iActiveElm2.className = `icon icon-active ${lineTypeData[i].icon}` + + //控制参数显隐 + if (2 < this.lineType && this.lineType < 13) {//贴图参数 + document.getElementById('dashTextureDom') && (document.getElementById('dashTextureDom').style.display = 'flex') + } else { + document.getElementById('dashTextureDom') && (document.getElementById('dashTextureDom').style.display = 'none') + } + if (2 < this.lineType && this.lineType < 5) {//尾迹参数 + document.getElementsByClassName('lineSpace')[0] && (document.getElementsByClassName('lineSpace')[0].style.display = 'none') + document.getElementsByClassName('lineSpace')[1] && (document.getElementsByClassName('lineSpace')[1].style.display = 'none') + } else { + document.getElementsByClassName('lineSpace')[0] && (document.getElementsByClassName('lineSpace')[0].style.display = 'flex') + document.getElementsByClassName('lineSpace')[1] && (document.getElementsByClassName('lineSpace')[1].style.display = 'flex') + } break } } @@ -2111,6 +2461,10 @@ class CurvelineObject extends Base { this.attributeVr = this.options.attribute.vr.content this.attributeCamera = this.options.attribute.camera.content this.attributeGoods = this.options.attribute.goods.content + this.rotate = this.originalOptions.rotate + this.speed = this.originalOptions.speed + this.dashSize = this.originalOptions.dashSize + this.space = this.originalOptions.space this.cameraSelect && this.cameraSelect() this.goodsSelect && this.goodsSelect() From 25a7c967bbd7bb3852c12fb14d02582694e3c39e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E5=A4=A7=E8=83=86?= <1101282782@qq.com> Date: Fri, 15 Aug 2025 14:20:26 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=96=87=E6=9C=AC=E6=A1=86=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0flyto=E5=AE=9A=E4=BD=8D=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Obj/Base/TextBox/index.js | 95 ++++++++++++++++++++++++++++++++--- 1 file changed, 87 insertions(+), 8 deletions(-) diff --git a/src/Obj/Base/TextBox/index.js b/src/Obj/Base/TextBox/index.js index e78e9a9..b97613b 100644 --- a/src/Obj/Base/TextBox/index.js +++ b/src/Obj/Base/TextBox/index.js @@ -2,6 +2,7 @@ * 文本框 */ import Base from "../index"; +import { setActiveViewer, closeRotateAround, closeViewFollow } from '../../../Global/global' class TextBox extends Base { constructor(sdk, options = {}) { // this.sdk = { ...sdk } @@ -39,10 +40,12 @@ class TextBox extends Base { 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`; + if (position) { + 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 @@ -68,10 +71,12 @@ class TextBox extends Base { 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`; + 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); } @@ -92,6 +97,80 @@ class TextBox extends Base { set positions(v) { this.options.positions = v } + async flyTo(options = {}) { + setActiveViewer(0) + closeRotateAround(this.sdk) + closeViewFollow(this.sdk) + + if (this.options.customView && this.options.customView.relativePosition && this.options.customView.orientation) { + let orientation = { + heading: Cesium.Math.toRadians(this.options.customView.orientation.heading || 0.0), + pitch: Cesium.Math.toRadians(this.options.customView.orientation.pitch || -60.0), + roll: Cesium.Math.toRadians(this.options.customView.orientation.roll || 0.0) + } + + let lng = this.options.customView.relativePosition.lng + let lat = this.options.customView.relativePosition.lat + let alt = this.options.customView.relativePosition.alt + let destination = Cesium.Cartesian3.fromDegrees(lng, lat, alt) + + let position = { lng: 0, lat: 0 } + if (this.options.position) { + position = { ...this.options.position } + } + else if (this.options.positions) { + position = { ...this.options.positions[0] } + } + else if (this.options.center) { + position = { ...this.options.center } + } + else if (this.options.start) { + position = { ...this.options.start } + } + else { + if (this.options.hasOwnProperty('lng')) { + position.lng = this.options.lng + } + if (this.options.hasOwnProperty('lat')) { + position.lat = this.options.lat + } + if (this.options.hasOwnProperty('alt')) { + position.alt = this.options.alt + } + } + // 如果没有高度值,则获取紧贴高度计算 + // if (!position.hasOwnProperty('alt')) { + // position.alt = await this.getClampToHeight(position) + // } + lng = this.options.customView.relativePosition.lng + position.lng + lat = this.options.customView.relativePosition.lat + position.lat + alt = this.options.customView.relativePosition.alt + position.alt + destination = Cesium.Cartesian3.fromDegrees(lng, lat, alt) + this.sdk.viewer.camera.flyTo({ + destination: destination, + orientation: orientation + }) + } + else { + let positionArray = [] + let a = Cesium.Cartesian3.fromDegrees( + this.positions.lng, + this.positions.lat, + this.positions.alt + ) + positionArray.push(a.x, a.y, a.z) + + let BoundingSphere = Cesium.BoundingSphere.fromVertices(positionArray) + this.viewer.camera.flyToBoundingSphere(BoundingSphere, { + offset: { + heading: Cesium.Math.toRadians(0.0), + pitch: Cesium.Math.toRadians(-20.0), + roll: Cesium.Math.toRadians(0.0) + } + }) + + } + } async remove() { if (this.handler) {