From a1be89ade7bdb9e711f988c19fdd441dbc947d31 Mon Sep 17 00:00:00 2001 From: zh <972939975@qq.com> Date: Tue, 4 Nov 2025 11:30:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=87=E5=BD=A2=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Obj/Base/SectorObject/index.js | 429 +++-------------------------- 1 file changed, 31 insertions(+), 398 deletions(-) diff --git a/src/Obj/Base/SectorObject/index.js b/src/Obj/Base/SectorObject/index.js index b07c5d9..30ae4f5 100644 --- a/src/Obj/Base/SectorObject/index.js +++ b/src/Obj/Base/SectorObject/index.js @@ -36,7 +36,6 @@ class SectorObject extends Base { * @param options.line.width=3 {number} 边框宽 * @param options.line.color="rgba(155, 155, 124, 0.89)" {string} 边框颜色 * @param options.heightMode=2{number} 高度模式(0:海拔高度;1:相对地表;2:依附模式) - * @param options.areaUnit='平方米' {string} 面积单位 * @param options.label {object} 标签对象 * @param options.label.text {string} 标签文本 * @param options.label.show {string} 标签显隐 @@ -82,7 +81,6 @@ class SectorObject extends Base { this.options.line = options.line || {} this.options.line.width = ((this.options.line.width || this.options.line.width === 0) ? this.options.line.width : 3) this.options.line.color = this.options.line.color || 'rgba(255, 0, 0, 1)' - this.options['area-unit'] = options['area-unit'] || '平方米' options.label = options.label || {} this._elms = {}; this.options.label = { @@ -103,13 +101,10 @@ class SectorObject extends Base { this.options.attribute = options.attribute || {} this.options.attribute.link = this.options.attribute.link || {} this.options.attribute.link.content = this.options.attribute.link.content || [] - this.options.attribute.vr = this.options.attribute.vr || {} - this.options.attribute.vr.content = this.options.attribute.vr.content || [] - this.options.attribute.camera = this.options.attribute.camera || {} - this.options.attribute.camera.content = this.options.attribute.camera.content || [] - this.options.attribute.goods = this.options.attribute.goods || {} - this.options.attribute.goods.content = this.options.attribute.goods.content || [] - this.options.attributeType = options.attributeType || 'richText' + + delete this.options.attribute.camera + delete this.options.attribute.vr + delete this.options.attribute.goods this.options.richTextContent = options.richTextContent || '' this.event = new MouseEvent(this.sdk) @@ -136,7 +131,7 @@ class SectorObject extends Base { return } let heightModeName = '' - SectorObject.closeNodeEdit(this) + this.closeNodeEdit() let ground = false let disabled = false this.renewPositions() @@ -336,45 +331,6 @@ class SectorObject extends Base { }) } - get area() { - return this.options.area - } - - set area(v) { - this.options.area = v - this._elms.area && this._elms.area.forEach((item) => { - item.value = v - }) - } - - get areaUnit() { - return this.options['area-unit'] - } - set areaUnit(v) { - this.options['area-unit'] = v - this._elms.areaUnit && this._elms.areaUnit.forEach((item) => { - item.value = v - }) - if (this.options.areaByMeter) { - switch (v) { - case '平方米': - this.area = this.options.areaByMeter - break; - case '平方千米': - this.area = Number((this.options.areaByMeter / 1000000).toFixed(8)) - break; - case '亩': - this.area = Number((this.options.areaByMeter / 666.6666667).toFixed(4)) - break; - case '公顷': - this.area = Number((this.options.areaByMeter / 10000).toFixed(6)) - break; - default: - this.area = this.options.areaByMeter - } - } - } - get labelShow() { return this.options.label.show } @@ -586,320 +542,6 @@ class SectorObject extends Base { } } - get attributeType() { - return this.options.attributeType - } - - set attributeType(v) { - this.options.attributeType = v - this._elms.attributeType && this._elms.attributeType.forEach((item) => { - item.value = v - }) - let attributeContent = this._DialogObject._element.content.getElementsByClassName('attribute-content') - for (let i = 0; i < attributeContent.length; i++) { - if (attributeContent[i].className.indexOf('attribute-content-' + v) > -1) { - attributeContent[i].style.display = 'block'; - } - else { - attributeContent[i].style.display = 'none'; - } - } - } - - get attributeLink() { - return this.options.attribute.link.content - } - - set attributeLink(v) { - this.options.attribute.link.content = v - if (!this._DialogObject || !this._DialogObject._element || !this._DialogObject._element.content || this._DialogObject._element.content.getElementsByClassName('attribute-content-link').length == 0) { - return - } - let table = this._DialogObject._element.content.getElementsByClassName('attribute-content-link')[1].getElementsByClassName('table')[0] - let tableContent = table.getElementsByClassName('table-body')[0] - tableContent.innerHTML = '' - if (this.options.attribute.link.content.length > 0) { - table.getElementsByClassName('table-empty')[0].style.display = 'none' - } - else { - table.getElementsByClassName('table-empty')[0].style.display = 'flex' - } - for (let i = 0; i < this.options.attribute.link.content.length; i++) { - let tr = ` -
-
` + this.options.attribute.link.content[i].name + `
-
` + this.options.attribute.link.content[i].url + `
-
- - -
-
` - let trElm = document.createRange().createContextualFragment(tr) - tableContent.appendChild(trElm) - } - let item = tableContent.getElementsByClassName('tr') - let fun = { - linkEdit: async (index) => { - this.attributeLink = await this.options.attribute.link.content - let table = this._DialogObject._element.content.getElementsByClassName('attribute-content-link')[1].getElementsByClassName('table')[0] - let tableContent = table.getElementsByClassName('table-body')[0] - let item = tableContent.getElementsByClassName('tr') - for (let i = 0; i < item.length; i++) { - if (index === i) { - let height = item[i].offsetHeight - let html = ` -
- -
-
- -
-
- - -
` - item[i].innerHTML = html - let textareaElm = item[i].getElementsByClassName('link-edit')[0] - textareaElm.style.height = (height - 10) + 'px' - let td = item[i].getElementsByClassName('td') - td[0].getElementsByClassName('input')[0].value = this.options.attribute.link.content[index].name - td[1].getElementsByClassName('input')[0].value = this.options.attribute.link.content[index].url - let btn = item[i].getElementsByTagName('button') - for (let n = 0; n < btn.length; n++) { - if (!btn[n] || !btn[n].attributes) { - continue - } - for (let m of btn[n].attributes) { - if (m.name === '@click') { - btn[n].addEventListener('click', (e) => { - if (typeof (fun[m.value]) === 'function') { - fun[m.value]({ name: td[0].getElementsByClassName('input')[0].value, url: td[1].getElementsByClassName('input')[0].value }, i) - } - }); - btn[n].attributes.removeNamedItem(m.name) - break - } - } - } - break - } - } - }, - linkDelete: (i) => { - this.options.attribute.link.content.splice(i, 1) - this.attributeLink = this.options.attribute.link.content - }, - - confirmEdit: (value, i) => { - let name = value.name && value.name.replace(/\s/g, "") - let url = value.url && value.url.replace(/\s/g, "") - if (name && url) { - this.options.attribute.link.content[i] = value - } - else { - window.ELEMENT && window.ELEMENT.Message({ - message: '名称或链接不能为空!', - type: 'warning', - duration: 1500 - }); - } - this.attributeLink = this.options.attribute.link.content - }, - cancelEdit: () => { - this.attributeLink = this.options.attribute.link.content - }, - fileSelect: (value, i) => { - let fileElm = item[i].getElementsByClassName('file-select')[0] - fileElm.click() - fileElm.removeEventListener('change', fileSelect) - fileElm.addEventListener('change', fileSelect) - } - } - let fileSelect = (event) => { - if (event.target.value) { - let td = item[event.target.getAttribute('index')].getElementsByClassName('td') - td[1].getElementsByClassName('input')[0].value = event.target.value - event.target.value = null - } - } - for (let i = 0; i < item.length; i++) { - let btn = item[i].getElementsByTagName('button') - for (let n = 0; n < btn.length; n++) { - if (!btn[n] || !btn[n].attributes) { - continue - } - for (let m of btn[n].attributes) { - if (m.name === '@click') { - btn[n].addEventListener('click', (e) => { - if (typeof (fun[m.value]) === 'function') { - fun[m.value](i) - } - }); - btn[n].attributes.removeNamedItem(m.name) - break - } - } - } - } - - - - - } - - get attributeCamera() { - return this.options.attribute.camera.content - } - - set attributeCamera(v) { - this.options.attribute.camera.content = v - } - - get attributeVr() { - return this.options.attribute.vr.content - } - - set attributeVr(v) { - this.options.attribute.vr.content = v - if (!this._DialogObject || !this._DialogObject._element || !this._DialogObject._element.content || this._DialogObject._element.content.getElementsByClassName('attribute-content-vr').length == 0) { - return - } - let table = this._DialogObject._element.content.getElementsByClassName('attribute-content-vr')[1].getElementsByClassName('table')[0] - let tableContent = table.getElementsByClassName('table-body')[0] - tableContent.innerHTML = '' - if (this.options.attribute.vr.content.length > 0) { - table.getElementsByClassName('table-empty')[0].style.display = 'none' - } - else { - table.getElementsByClassName('table-empty')[0].style.display = 'flex' - } - for (let i = 0; i < this.options.attribute.vr.content.length; i++) { - let tr = ` -
-
` + this.options.attribute.vr.content[i].name + `
-
` + this.options.attribute.vr.content[i].url + `
-
- - -
-
` - let trElm = document.createRange().createContextualFragment(tr) - tableContent.appendChild(trElm) - } - let item = tableContent.getElementsByClassName('tr') - let fun = { - vrEdit: async (index) => { - this.attributeVr = await this.options.attribute.vr.content - let table = this._DialogObject._element.content.getElementsByClassName('attribute-content-vr')[1].getElementsByClassName('table')[0] - let tableContent = table.getElementsByClassName('table-body')[0] - let item = tableContent.getElementsByClassName('tr') - for (let i = 0; i < item.length; i++) { - if (index === i) { - let height = item[i].offsetHeight - let html = ` -
- -
-
- -
-
- - -
` - item[i].innerHTML = html - let textareaElm = item[i].getElementsByClassName('link-edit')[0] - textareaElm.style.height = (height - 10) + 'px' - let td = item[i].getElementsByClassName('td') - td[0].getElementsByClassName('input')[0].value = this.options.attribute.vr.content[index].name - td[1].getElementsByClassName('input')[0].value = this.options.attribute.vr.content[index].url - let btn = item[i].getElementsByTagName('button') - for (let n = 0; n < btn.length; n++) { - if (!btn[n] || !btn[n].attributes) { - continue - } - for (let m of btn[n].attributes) { - if (m.name === '@click') { - btn[n].addEventListener('click', (e) => { - if (typeof (fun[m.value]) === 'function') { - fun[m.value]({ name: td[0].getElementsByClassName('input')[0].value, url: td[1].getElementsByClassName('input')[0].value }, i) - } - }); - btn[n].attributes.removeNamedItem(m.name) - break - } - } - } - break - } - } - }, - vrDelete: (i) => { - this.options.attribute.vr.content.splice(i, 1) - this.attributeVr = this.options.attribute.vr.content - }, - - confirmEdit: (value, i) => { - let name = value.name && value.name.replace(/\s/g, "") - let url = value.url && value.url.replace(/\s/g, "") - if (name && url) { - this.options.attribute.vr.content[i] = value - } - else { - window.ELEMENT && window.ELEMENT.Message({ - message: '名称或链接不能为空!', - type: 'warning', - duration: 1500 - }); - } - this.attributeVr = this.options.attribute.vr.content - }, - cancelEdit: () => { - this.attributeVr = this.options.attribute.vr.content - }, - fileSelect: (value, i) => { - let fileElm = item[i].getElementsByClassName('file-select')[0] - fileElm.click() - fileElm.removeEventListener('change', fileSelect) - fileElm.addEventListener('change', fileSelect) - } - } - let fileSelect = (event) => { - if (event.target.value) { - let td = item[event.target.getAttribute('index')].getElementsByClassName('td') - td[1].getElementsByClassName('input')[0].value = event.target.value - event.target.value = null - } - } - for (let i = 0; i < item.length; i++) { - let btn = item[i].getElementsByTagName('button') - for (let n = 0; n < btn.length; n++) { - if (!btn[n] || !btn[n].attributes) { - continue - } - for (let m of btn[n].attributes) { - if (m.name === '@click') { - btn[n].addEventListener('click', (e) => { - if (typeof (fun[m.value]) === 'function') { - fun[m.value](i) - } - }); - btn[n].attributes.removeNamedItem(m.name) - break - } - } - } - } - } - - get attributeGoods() { - return this.options.attribute.goods.content - } - - set attributeGoods(v) { - this.options.attribute.goods.content = v - } - static create(that) { let fromDegreesArray = that.calSector(that.options.center, that.options.radius, that.options.startAngle, that.options.endAngle, 360, true) let ground = true @@ -973,23 +615,8 @@ class SectorObject extends Base { if (angle < 0) { angle = 360 + angle } - that.options.areaByMeter = Number((Cesium.Math.PI * that.options.radius * that.options.radius * (angle / 360)).toFixed(2)); - switch (that.options['area-unit']) { - case '平方米': - that.options.area = that.options.areaByMeter - break; - case '平方千米': - that.options.area = Number((that.options.areaByMeter / 1000000).toFixed(8)) - break; - case '亩': - that.options.area = Number((that.options.areaByMeter / 666.6666667).toFixed(4)) - break; - case '公顷': - that.options.area = Number((that.options.areaByMeter / 10000).toFixed(6)) - break; - default: - that.options.area = that.options.areaByMeter - } + that.areaByMeter = Number((Cesium.Math.PI * that.options.radius * that.options.radius * (angle / 360)).toFixed(2)); + that.areaChangeCallBack && that.areaChangeCallBack() syncData(that.sdk, that.options.id) if (that.options.show) { @@ -1021,6 +648,7 @@ class SectorObject extends Base { // 编辑框 async edit(state) { + return let _this = this this.originalOptions = this.deepCopyObj(this.options) @@ -1511,8 +1139,6 @@ class SectorObject extends Base { this.name = this.originalOptions.name this.radius = this.originalOptions.radius this.color = this.originalOptions.color - this.area = this.originalOptions.area - this.areaUnit = this.originalOptions['area-unit'] this.labelShow = this.originalOptions.label.show this.labelFontSize = this.originalOptions.label.fontSize this.labelFontFamily = this.originalOptions.label.fontFamily @@ -1525,12 +1151,6 @@ class SectorObject extends Base { this.lineColor = this.originalOptions.line.color this.labelBackgroundColorStart = this.originalOptions.label.backgroundColor[0] this.labelBackgroundColorEnd = this.originalOptions.label.backgroundColor[1] - this.attributeLink = this.options.attribute.link.content - this.attributeVr = this.options.attribute.vr.content - this.attributeCamera = this.options.attribute.camera.content - this.attributeGoods = this.options.attribute.goods.content - this.cameraSelect && this.cameraSelect() - this.goodsSelect && this.goodsSelect() this.heightMode = this.originalOptions.heightMode @@ -1887,6 +1507,19 @@ class SectorObject extends Base { return this.operate.positionEditing } + openPositionEditing(cd) { + this.positionEditing = true + this._positionEditingCallback = cd + } + + get areaChangeCallBack() { + return this._areaChangeCallBack + } + + set areaChangeCallBack (cd) { + this._areaChangeCallBack = cd + } + static nodeEdit(that, cb = () => { }) { that.positionEditing = false if (YJ.Measure.GetMeasureStatus()) { @@ -2064,17 +1697,17 @@ class SectorObject extends Base { } } - static closeNodeEdit(that) { + closeNodeEdit() { YJ.Measure.SetMeasureStatus(false) - that.event && that.event.destroy() - that.tip && that.tip.destroy() - that.tip = null + this.event && this.event.destroy() + this.tip && this.tip.destroy() + this.tip = null - for (let i = 0; i < that.nodePoints.length; i++) { - that.sdk.viewer.entities.remove(that.nodePoints[i]) + for (let i = 0; i < this.nodePoints.length; i++) { + this.sdk.viewer.entities.remove(this.nodePoints[i]) } - that.nodePoints = [] - that.picking = true + this.nodePoints = [] + this.picking = true } static EventBinding(that, elements) { @@ -2259,8 +1892,8 @@ class SectorObject extends Base { if (angle < 0) { angle = 360 + angle } - this.options.areaByMeter = Number((Cesium.Math.PI * this.options.radius * this.options.radius * (angle / 360)).toFixed(2)); - this.areaUnit = this.areaUnit + this.areaByMeter = Number((Cesium.Math.PI * this.options.radius * this.options.radius * (angle / 360)).toFixed(2)); + this.areaChangeCallBack && this.areaChangeCallBack() return fromDegreesArray } }