Files
sdk4.0/src/Obj/Base/WallRealStereoscopic/index.js
2025-07-09 11:15:53 +08:00

2093 lines
77 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @description 实体墙
*/
import { getHost } from "../../../on";
import Dialog from '../../Element/Dialog';
import cy_tabs from "../../Element/cy_html_tabs";
import richText from "../../Element/richText";
import { html } from "./_element";
import Base from "../index";
import LabelObject from '../LabelObject'
import EventBinding from './eventBinding'
import MouseEvent from '../../../Event'
import MouseTip from '../../../MouseTip'
import { syncData } from '../../../Global/MultiViewportMode'
import { legp } from '../../Element/datalist';
import { getFontList, getFontFamilyName } from '../../Element/fontSelect'
import PolylineImageTrailMaterialProperty from "../../Materail/PolylineImageTrailMaterialProperty";
import FlowPictureMaterialProperty from "../../Materail/FlowPictureMaterialProperty";
import { setSplitDirection, syncSplitData, setActiveId } from '../../../Global/SplitScreen'
class WallRealStereoscopic extends Base {
/**
* @constructor
* @param sdk
* @description 实体围墙
* @param options {object} 墙属性
* @param options.id {string} 唯一标识
* @param options.name {string} 名称
* @param options.color="#ffffff" {string} 颜色
* @param options.width=0.24 {number} 宽
* @param options.show=true {boolean} 显隐
* @param options['nose-to-tail']=false {boolean} 首尾相连
* @param options.extrudedHeight=2.4 {number} 拉伸高度
* @param options.cornerType=0 {string} 拐角类型;0直角1斜角2圆角
* @param options.material=0 {number} 材质0纯色墙1砖墙12砖墙23砖墙3
* @param {Array.<object>} positions 经纬度和高度的列表,值交替 [{lon,lat,alt},...]
* @param _Dialog {object} 弹框事件
* @param _Dialog.confirmCallBack {function} 弹框确认时的回调
* */
constructor(sdk, options, _Dialog = {}) {
super(sdk, options);
this._elms = {};
this.options.color = options.color || "#ffffff"
this.options.width = options.width || 0.24
this.options['nose-to-tail'] = options['nose-to-tail'] || false
this.options.extrudedHeight = options.extrudedHeight || 2.4
this.cornerType = options.cornerType
this.options.positions = options.positions
this.options.material = Number(options.material) || 0
this.options.show = (options.show || options.show === false) ? options.show : true
this.entity
this.nodePoints = []
options.label = options.label || {}
this.options.label = {
text: this.options.name,
show: options.label.show || false,
position: options.label.position,
fontSize: (options.label.fontSize || options.label.fontSize === 0) ? options.label.fontSize : 20,
fontFamily: options.label.fontFamily ? options.label.fontFamily : 0,
color: options.label.color || '#ffffff',
lineWidth: (options.label.lineWidth || options.label.lineWidth === 0) ? options.label.lineWidth : 4,
pixelOffset: (options.label.pixelOffset || options.label.pixelOffset === 0) ? options.label.pixelOffset : 20,
backgroundColor: options.label.backgroundColor || ['#00ffff80', '#00ffff80'],
lineColor: options.label.lineColor || '#00ffff80',
scaleByDistance: options.label.scaleByDistance || false,
near: (options.label.near || options.label.near === 0) ? options.label.near : 2000,
far: (options.label.far || options.label.far === 0) ? options.label.far : 100000,
}
this.options.instruct = options.instruct || ""
this.options.operatingPoint = options.operatingPoint || ""
this.options.attribute = options.attribute || {}
this.options.attribute.vr = this.options.attribute.vr || {}
this.options.attribute.vr.content = this.options.attribute.vr.content || []
this.options.attribute.link = this.options.attribute.link || {}
this.options.attribute.link.content = this.options.attribute.link.content || []
this.options.attribute.camera = this.options.attribute.camera || {}
this.options.attribute.camera.content = this.options.attribute.camera.content || []
this.options.attribute.ISC = this.options.attribute.ISC || {}
this.options.attribute.ISC.content = this.options.attribute.ISC.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'
this.Dialog = _Dialog
if (!this.options.positions || this.options.positions.length < 2) {
this._error = '最少需要两个坐标!'
console.warn(this._error)
window.ELEMENT && window.ELEMENT.Message({
message: this._error,
type: 'warning',
duration: 1500
});
}
else {
this.sdk.addIncetance(this.options.id, this)
WallRealStereoscopic.create(this)
}
}
get type() {
return 'WallRealStereoscopic'
}
static createLabel(that) {
// 标签
that.label = new LabelObject(that.sdk, {
id: that.options.id,
show: that.options.show ? that.options.label.show : false,
position: [that.options.positions[0].lng, that.options.positions[0].lat, that.options.positions[0].alt + that.options.extrudedHeight],
text: that.options.name,
fontSize: that.options.label.fontSize,
fontFamily: that.options.label.fontFamily,
color: that.options.label.color,
ground: false,
pixelOffset: that.options.label.pixelOffset,
backgroundColor: that.options.label.backgroundColor,
lineColor: that.options.label.lineColor,
lineWidth: that.options.label.lineWidth,
scaleByDistance: that.options.label.scaleByDistance,
near: that.options.label.near,
far: that.options.label.far
})
}
get color() {
return this.options.color
}
set color(v) {
this.options.color = v
if (this.entity) {
for (let i = 0; i < this.entity.values.length; i++) {
if (this.entity.values[i].polylineVolume) {
let wall = this.entity.values[i]
wall.polylineVolume.material = this.getMaterial(wall.id)
}
if (this.entity.values[i].polygon) {
let top = this.entity.values[i]
top.polygon.material = Cesium.Color.fromCssColorString(this.options.color)
}
}
}
if (this._elms.color) {
this._elms.color.forEach((item, i) => {
let colorPicker = new ewPlugins('colorpicker', {
el: item.el,
size: 'mini',//颜色box类型
alpha: false,//是否开启透明度
defaultColor: v,
disabled: false,//是否禁止打开颜色选择器
openPickerAni: 'opacity',//打开颜色选择器动画
sure: (c) => {
this.color = c
},//点击确认按钮事件回调
clear: () => {
this.color = 'rgba(255,255,255,1)'
},//点击清空按钮事件回调
})
this._elms.color[i] = colorPicker
})
}
}
get width() {
return this.options.width
}
set width(v) {
this.options.width = v
if (this.options.width <= 0.01) {
this.options.width = 0.01
}
this.update()
this._elms.width && this._elms.width.forEach((item) => {
item.value = v
})
}
get cornerType() {
return this.options.cornerType
}
set cornerType(v) {
switch (v) {
case 0:
case '0':
v = 0
break;
case 1:
case '1':
v = 1
break;
case 2:
case '2':
v = 2
break;
default:
v = 0
break;
}
this.options.cornerType = v
this.update()
// this.entity.polylineVolume.cornerType = Cesium.CornerType[this.options.cornerType]
this._elms.cornerType && this._elms.cornerType.forEach((item) => {
item.value = v
})
}
get material() {
return this.options.material
}
set material(v) {
this.options.material = Number(v)
if (this.entity) {
for (let i = 0; i < this.entity.values.length; i++) {
if (this.entity.values[i].polylineVolume) {
let wall = this.entity.values[i]
wall.polylineVolume.material = this.getMaterial(wall.id)
}
}
}
this._elms.material && this._elms.material.forEach((item) => {
item.value = v
})
}
get noseToTail() {
return this.options['nose-to-tail']
}
set noseToTail(v) {
this.options['nose-to-tail'] = v
this.update()
this.material = this.material
this._elms.noseToTail &&
this._elms.noseToTail.forEach(item => {
item.checked = v
})
}
get extrudedHeight() {
return this.options.extrudedHeight
}
set extrudedHeight(v) {
this.options.extrudedHeight = v
this.label.position = [this.options.positions[0].lng, this.options.positions[0].lat, this.options.positions[0].alt + this.options.extrudedHeight]
this.update()
this._elms.extrudedHeight && this._elms.extrudedHeight.forEach((item) => {
item.value = v
})
}
get labelShow() {
return this.options.label.show
}
set labelShow(v) {
this.options.label.show = v
if (this.show) {
this.label.show = v
}
else {
this.label.show = false
}
this._elms.labelShow && this._elms.labelShow.forEach((item) => {
item.checked = v
})
}
get labelFontFamily() {
return this.options.label.fontFamily
}
set labelFontFamily(v) {
this.options.label.fontFamily = v || 0
this.label && (this.label.fontFamily = this.options.label.fontFamily)
let name = getFontFamilyName(this.labelFontFamily) || ''
this._elms.labelFontFamily &&
this._elms.labelFontFamily.forEach(item => {
item.value = name
})
}
get labelColor() {
return this.options.label.color
}
set labelColor(v) {
this.options.label.color = v
this.label.color = v
if (this._elms.labelColor) {
this._elms.labelColor.forEach((item, i) => {
let labelColorPicker = new ewPlugins('colorpicker', {
el: item.el,
size: 'mini',//颜色box类型
alpha: true,//是否开启透明度
defaultColor: this.labelColor,
disabled: false,//是否禁止打开颜色选择器
openPickerAni: 'opacity',//打开颜色选择器动画
sure: (color) => {
this.labelColor = color
},//点击确认按钮事件回调
clear: () => {
this.labelColor = 'rgba(255,255,255,1)'
},//点击清空按钮事件回调
})
this._elms.labelColor[i] = labelColorPicker
})
}
}
get labelFontSize() {
return this.options.label.fontSize
}
set labelFontSize(v) {
this.options.label.fontSize = v
this.label.fontSize = v
this._elms.labelFontSize && this._elms.labelFontSize.forEach((item) => {
item.value = v
})
}
get labelScaleByDistance() {
return this.options.label.scaleByDistance
}
set labelScaleByDistance(v) {
this.options.label.scaleByDistance = v
this.label.scaleByDistance = v
this._elms.labelScaleByDistance && this._elms.labelScaleByDistance.forEach((item) => {
item.checked = v
})
}
get labelNear() {
return this.options.label.near
}
set labelNear(v) {
let near = v
if (near > this.labelFar) {
near = this.labelFar
}
this.options.label.near = near
this.label.near = near
this._elms.labelNear && this._elms.labelNear.forEach((item) => {
item.value = near
})
}
get labelFar() {
return this.options.label.far
}
set labelFar(v) {
let far = v
if (far < this.labelNear) {
far = this.labelNear
}
this.options.label.far = far
this.label.far = far
this._elms.labelFar && this._elms.labelFar.forEach((item) => {
item.value = far
})
}
get labelLineWidth() {
return this.options.label.lineWidth
}
set labelLineWidth(v) {
this.options.label.lineWidth = v
this.label.lineWidth = v
this._elms.labelLineWidth && this._elms.labelLineWidth.forEach((item) => {
item.value = v
})
}
get labelPixelOffset() {
return this.options.label.pixelOffset
}
set labelPixelOffset(v) {
this.options.label.pixelOffset = v
this.label.pixelOffset = v
this._elms.labelPixelOffset && this._elms.labelPixelOffset.forEach((item) => {
item.value = v
})
}
get labelLineColor() {
return this.options.label.lineColor
}
set labelLineColor(v) {
this.options.label.lineColor = v
this.label.lineColor = v
if (this._elms.labelLineColor) {
this._elms.labelLineColor.forEach((item, i) => {
let lineColorPicker = new ewPlugins('colorpicker', {
el: item.el,
size: 'mini',//颜色box类型
alpha: true,//是否开启透明度
defaultColor: this.labelLineColor,
disabled: false,//是否禁止打开颜色选择器
openPickerAni: 'opacity',//打开颜色选择器动画
sure: (color) => {
this.labelLineColor = color
},//点击确认按钮事件回调
clear: () => {
this.labelLineColor = 'rgba(0,255,255,0.5)'
},//点击清空按钮事件回调
})
this._elms.labelLineColor[i] = lineColorPicker
})
}
}
get labelBackgroundColorStart() {
return this.options.label.backgroundColor[0]
}
set labelBackgroundColorStart(v) {
this.options.label.backgroundColor[0] = v
this.label.backgroundColor = [v, this.label.backgroundColor[1]]
if (this._elms.labelBackgroundColorStart) {
this._elms.labelBackgroundColorStart.forEach((item, i) => {
let labelBackgroundColorStartPicker = new ewPlugins('colorpicker', {
el: item.el,
size: 'mini',//颜色box类型
alpha: true,//是否开启透明度
defaultColor: this.labelBackgroundColorStart,
disabled: false,//是否禁止打开颜色选择器
openPickerAni: 'opacity',//打开颜色选择器动画
sure: (color) => {
this.labelBackgroundColorStart = color
},//点击确认按钮事件回调
clear: () => {
this.labelBackgroundColorStart = 'rgba(255,255,255,1)'
},//点击清空按钮事件回调
})
this._elms.labelBackgroundColorStart[i] = labelBackgroundColorStartPicker
})
}
}
get labelBackgroundColorEnd() {
return this.options.label.backgroundColor[1]
}
set labelBackgroundColorEnd(v) {
this.options.label.backgroundColor[1] = v
this.label.backgroundColor = [this.label.backgroundColor[0], v]
if (this._elms.labelBackgroundColorEnd) {
this._elms.labelBackgroundColorEnd.forEach((item, i) => {
let labelBackgroundColorEndPicker = new ewPlugins('colorpicker', {
el: item.el,
size: 'mini',//颜色box类型
alpha: true,//是否开启透明度
defaultColor: this.labelBackgroundColorEnd,
disabled: false,//是否禁止打开颜色选择器
openPickerAni: 'opacity',//打开颜色选择器动画
sure: (color) => {
this.labelBackgroundColorEnd = color
},//点击确认按钮事件回调
clear: () => {
this.labelBackgroundColorEnd = 'rgba(255,255,255,1)'
},//点击清空按钮事件回调
})
this._elms.labelBackgroundColorEnd[i] = labelBackgroundColorEndPicker
})
}
}
get instruct() {
return this.options.instruct
}
set instruct(v) {
this.options.instruct = v
this._elms.instruct && this._elms.instruct.forEach((item) => {
item.value = v
})
}
get operatingPoint() {
return this.options.operatingPoint
}
set operatingPoint(v) {
this.options.operatingPoint = v
this._elms.operatingPoint && this._elms.operatingPoint.forEach((item) => {
item.value = v
})
}
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 = `
<div class="tr">
<div class="td">` + this.options.attribute.link.content[i].name + `</div>
<div class="td">` + this.options.attribute.link.content[i].url + `</div>
<div class="td">
<button @click="linkEdit">编辑</button>
<button @click="linkDelete">删除</button>
</div>
</div>`
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 = `
<div class="td">
<input class="input" type="text">
</div>
<div class="td">
<textarea class="input link-edit" type="text"></textarea>
</div>
<div class="td">
<button @click="confirmEdit">确认</button>
<button @click="cancelEdit">取消</button>
</div>`
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 attributeISC() {
return this.options.attribute.ISC.content
}
set attributeISC(v) {
this.options.attribute.ISC.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 = `
<div class="tr">
<div class="td">` + this.options.attribute.vr.content[i].name + `</div>
<div class="td">` + this.options.attribute.vr.content[i].url + `</div>
<div class="td">
<button @click="vrEdit">编辑</button>
<button @click="vrDelete">删除</button>
</div>
</div>`
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 = `
<div class="td">
<input class="input" type="text">
</div>
<div class="td">
<textarea class="input link-edit" type="text"></textarea>
</div>
<div class="td">
<button @click="confirmEdit">确认</button>
<button @click="cancelEdit">取消</button>
</div>`
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
}
calculatePositions3() {
let optionsPositions = this.deepCopyObj(this.options.positions)
if (this.noseToTail) {
optionsPositions.push(optionsPositions[0], optionsPositions[1])
}
let pos1 = []
let pos2 = []
let positions = []
let forward = []
let reverse = []
for (let i = 0; i < optionsPositions.length - 1; i++) {
let pot1 = turf.point([optionsPositions[i].lng, optionsPositions[i].lat])
let pot2 = turf.point([optionsPositions[i + 1].lng, optionsPositions[i + 1].lat])
let bearing = turf.rhumbBearing(pot1, pot2);
let destination = turf.destination(pot1, this.options.width / 2 / 1000, bearing + 90, { units: 'kilometers' });
let destination2 = turf.destination(pot2, this.options.width / 2 / 1000, bearing + 90, { units: 'kilometers' });
let destination3 = turf.destination(pot1, this.options.width / 2 / 1000, bearing - 90, { units: 'kilometers' });
let destination4 = turf.destination(pot2, this.options.width / 2 / 1000, bearing - 90, { units: 'kilometers' });
let coordinates = destination.geometry.coordinates
let coordinates2 = destination2.geometry.coordinates
let coordinates3 = destination3.geometry.coordinates
let coordinates4 = destination4.geometry.coordinates
coordinates[2] = optionsPositions[i].alt
coordinates2[2] = optionsPositions[i + 1].alt
coordinates3[2] = optionsPositions[i].alt
coordinates4[2] = optionsPositions[i + 1].alt
pos1.push(coordinates, coordinates2)
pos2.push(coordinates3, coordinates4)
}
// 直角
if (this.cornerType === 0) { }
else if (this.cornerType === 1) {
// 斜角
for (let i = 0; i < pos1.length - 3; i += 2) {
if (i == 0) {
forward.push(pos1[i])
reverse.push(pos2[i])
}
forward.push(pos1[i + 1], pos1[i + 2])
reverse.push(pos2[i + 1], pos2[i + 2])
if (i == pos1.length - 4) {
forward.push(pos1[i + 3])
reverse.push(pos2[i + 3])
}
}
}
else if (this.cornerType === 2) {
// 圆角
for (let i = 0; i < pos1.length - 3; i += 2) {
let center = optionsPositions[(i / 2) + 1]
let pot1 = turf.point(pos1[i + 1])
let pot2 = turf.point(pos2[i + 1])
let bearing1 = turf.rhumbBearing(pot1, pot2);
let pot3 = turf.point(pos1[i + 2])
let pot4 = turf.point(pos2[i + 2])
let bearing2 = turf.rhumbBearing(pot3, pot4);
console.log('bearing1, bearing2', (bearing1 - bearing2))
let face = true
if (Math.sin(Cesium.Math.toRadians(bearing1 - bearing2)) > 0) {
let temporary = bearing1
bearing1 = bearing2 + 180
bearing2 = temporary + 180
face = false
}
let sector = turf.sector([center.lng, center.lat, center.alt], this.options.width / 1000 / 2, bearing1, bearing2, { units: 'kilometers' });
console.log('sector', sector)
if (i == 0) {
forward.push(pos1[i])
reverse.push(pos2[i])
}
console.log('face', face)
if (face) {
forward.push(pos1[i + 1], pos1[i + 2])
for (let n = 1; n < sector.geometry.coordinates[0].length - 1; n++) {
reverse.push([...sector.geometry.coordinates[0][n], pos1[i + 1][2]])
// this.sdk.viewer.entities.add({
// position: Cesium.Cartesian3.fromDegrees(...sector.geometry.coordinates[0][n], pos1[i + 1][2]),
// // billboard: {
// // image: this.getSourceRootPath() + '/img/point.png',
// // width: 15,
// // height: 15,
// // disableDepthTestDistance: Number.POSITIVE_INFINITY,
// // },
// label: {
// text: n+'',
// font: '12px Microsoft YaHei',
// fillColor: Cesium.Color.fromCssColorString('#f1e605'),
// style: Cesium.LabelStyle.FILL_AND_OUTLINE,
// horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
// verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
// disableDepthTestDistance: Number.POSITIVE_INFINITY,
// }
// })
}
}
else {
for (let n = sector.geometry.coordinates[0].length - 2; n > 0; n--) {
forward.push([...sector.geometry.coordinates[0][n], pos1[i + 1][2]])
}
reverse.push(pos2[i + 1], pos2[i + 2])
}
if (i == pos1.length - 4) {
forward.push(pos1[i + 3])
reverse.push(pos2[i + 3])
}
}
// for (let i = 0; i < pos1.length - 3; i += 2) {
// if (i == 0) {
// forward.push(pos1[i])
// reverse.push(pos2[i])
// }
// forward.push(pos1[i + 1], pos1[i + 2])
// reverse.push(pos2[i + 1], pos2[i + 2])
// if (i == pos1.length - 4) {
// forward.push(pos1[i + 3])
// reverse.push(pos2[i + 3])
// }
// let pot1 = turf.point(pos1[i])
// let pot2 = turf.point(pos1[i + 1])
// let bearing1 = turf.rhumbBearing(pot1, pot2);
// let pot3 = turf.point(pos1[i + 2])
// let pot4 = turf.point(pos1[i + 3])
// let bearing2 = turf.rhumbBearing(pot3, pot4);
// let line1 = turf.lineString([pos1[i], pos1[i + 1]]);
// let line2 = turf.lineString([pos1[i + 2], pos1[i + 3]]);
// let intersects = turf.lineIntersect(line1, line2);
// if (i == 0) {
// forward.push(pos1[i])
// reverse.push(pos2[i])
// }
// if (intersects.features[0]) {
// forward.push([...intersects.features[0].geometry.coordinates, pos1[i + 1][2]])
// let sector = turf.sector(intersects.features[0].geometry.coordinates, this.options.width / 1000, bearing1 - 90, bearing2 - 90, { units: 'kilometers' });
// for (let n = 1; n < sector.geometry.coordinates[0].length - 1; n++) {
// reverse.push([...sector.geometry.coordinates[0][n], pos1[i + 1][2]])
// }
// }
// else {
// let pot1 = turf.point(pos2[i])
// let pot2 = turf.point(pos2[i + 1])
// let bearing1 = turf.rhumbBearing(pot1, pot2);
// let pot3 = turf.point(pos2[i + 2])
// let pot4 = turf.point(pos2[i + 3])
// let bearing2 = turf.rhumbBearing(pot3, pot4);
// let line1 = turf.lineString([pos2[i], pos2[i + 1]]);
// let line2 = turf.lineString([pos2[i + 2], pos2[i + 3]]);
// let intersects = turf.lineIntersect(line1, line2);
// if (intersects.features[0]) {
// reverse.push([...intersects.features[0].geometry.coordinates, pos2[i + 1][2]])
// let sector = turf.sector(intersects.features[0].geometry.coordinates, this.options.width / 1000, bearing2 + 90, bearing1 + 90, { units: 'kilometers' });
// for (let n = sector.geometry.coordinates[0].length - 2; n >= 1; n--) {
// forward.push([...sector.geometry.coordinates[0][n], pos2[i + 1][2]])
// }
// }
// }
// if (i == pos1.length - 4) {
// forward.push(pos1[i + 3])
// reverse.push(pos2[i + 3])
// }
// }
}
positions = [...forward]
for (let i = reverse.length - 1; i >= 0; i--) {
positions.push(reverse[i])
}
positions.push(positions[0])
// for (let i = 0; i < positions.length; i++) {
// this.sdk.viewer.entities.add({
// position: Cesium.Cartesian3.fromDegrees(...positions[i]),
// label: {
// text: i+'',
// font: '18px Microsoft YaHei',
// fillColor: Cesium.Color.fromCssColorString('#f1e605'),
// style: Cesium.LabelStyle.FILL_AND_OUTLINE,
// horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
// verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
// disableDepthTestDistance: Number.POSITIVE_INFINITY,
// }
// })
// }
console.log('positions', positions)
return positions
}
calculatePositions2() {
// let collection = new Cesium.EntityCollection()
let positions = []
for (let i = 0; i < this.options.positions.length - 2; i++) {
let bearing = (180 - caculateAngle(this.options.positions[i], this.options.positions[i + 1], this.options.positions[i + 2])) / 2
let width = Math.tan((bearing) * Math.PI / 180) * (this.options.width / 2)
console.log('width', width, bearing)
let line1 = turf.lineString([[this.options.positions[1].lng, this.options.positions[1].lat], [this.options.positions[0].lng, this.options.positions[0].lat]]);
let line2 = turf.lineString([[this.options.positions[1].lng, this.options.positions[1].lat], [this.options.positions[2].lng, this.options.positions[2].lat]]);
let sliced1 = turf.lineSliceAlong(line1, 0, width / 1000, { units: 'kilometers' });
let sliced2 = turf.lineSliceAlong(line2, 0, width / 1000, { units: 'kilometers' });
let pos1 = sliced1.geometry.coordinates[sliced1.geometry.coordinates.length - 1]
let pos2 = sliced2.geometry.coordinates[sliced2.geometry.coordinates.length - 1]
pos1[2] = this.options.positions[i + 1].alt
pos2[2] = this.options.positions[i + 1].alt
positions.push([pos1, pos2])
this.sdk.viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(pos1[0], pos1[1], pos1[2]),
billboard: {
image: this.getSourceRootPath() + '/img/point.png',
width: 15,
height: 15,
disableDepthTestDistance: Number.POSITIVE_INFINITY,
color: Cesium.Color.WHITE.withAlpha(0.99)
},
})
this.sdk.viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(pos2[0], pos2[1], pos2[2]),
billboard: {
image: this.getSourceRootPath() + '/img/point.png',
width: 15,
height: 15,
disableDepthTestDistance: Number.POSITIVE_INFINITY,
color: Cesium.Color.WHITE.withAlpha(0.99)
},
})
}
function caculateAngle(p1, p2, p3) {
let point1 = turf.point([p1.lng, p1.lat]);
let point2 = turf.point([p2.lng, p2.lat]);
let point3 = turf.point([p3.lng, p3.lat]);
let options = { units: 'kilometers' };
let distance1 = turf.rhumbDistance(point1, point2, options);
let distance2 = turf.rhumbDistance(point3, point2, options);
let distance = distance1
if (distance1 > distance2) {
distance = distance2
}
let bearing1 = turf.rhumbBearing(point1, point2)
let bearing2 = turf.rhumbBearing(point3, point2)
let bearing = Math.abs(((bearing1 - bearing2) + 360) % 360)
if (bearing > 180) {
bearing = 360 - bearing
}
return bearing
}
return positions
}
calculatePositions() {
let optionsPositions = this.deepCopyObj(this.options.positions)
if (this.noseToTail) {
optionsPositions.push(optionsPositions[0], optionsPositions[1])
}
let pos1 = []
let pos2 = []
let positions = []
for (let i = 0; i < optionsPositions.length - 1; i++) {
let pot1 = turf.point([optionsPositions[i].lng, optionsPositions[i].lat])
let pot2 = turf.point([optionsPositions[i + 1].lng, optionsPositions[i + 1].lat])
let bearing = turf.rhumbBearing(pot1, pot2);
let destination = turf.destination(pot1, this.options.width / 2 / 1000, bearing + 90, { units: 'kilometers' });
let destination2 = turf.destination(pot2, this.options.width / 2 / 1000, bearing + 90, { units: 'kilometers' });
let destination3 = turf.destination(pot1, this.options.width / 2 / 1000, bearing - 90, { units: 'kilometers' });
let destination4 = turf.destination(pot2, this.options.width / 2 / 1000, bearing - 90, { units: 'kilometers' });
let coordinates = destination.geometry.coordinates
let coordinates2 = destination2.geometry.coordinates
let coordinates3 = destination3.geometry.coordinates
let coordinates4 = destination4.geometry.coordinates
coordinates[2] = optionsPositions[i].alt
coordinates2[2] = optionsPositions[i + 1].alt
coordinates3[2] = optionsPositions[i].alt
coordinates4[2] = optionsPositions[i + 1].alt
pos1.push([coordinates, coordinates2, coordinates4, coordinates3, coordinates])
}
positions.push(pos1[0])
if (this.cornerType === 0) {
// 直角
for (let i = 1; i < pos1.length; i++) {
let center = optionsPositions[i]
let pot1 = turf.point(pos1[i - 1][1])
let pot2 = turf.point(pos1[i - 1][2])
let bearing1 = turf.rhumbBearing(pot1, pot2);
let pot3 = turf.point(pos1[i][0])
let pot4 = turf.point(pos1[i][3])
let bearing2 = turf.rhumbBearing(pot3, pot4);
let face = true
if (Math.sin(Cesium.Math.toRadians(bearing1 - bearing2)) > 0) {
let temporary = bearing1
bearing1 = bearing2 + 180
bearing2 = temporary + 180
face = false
}
let bearing3 = Math.abs(bearing1 - bearing2)
if (bearing3 > 180) {
bearing3 = 360 - bearing3
}
let distance = (this.options.width / 2) / Math.cos(Cesium.Math.toRadians(bearing3 / 2))
if (distance > this.options.width * 5) {
distance = this.options.width * 5
}
let sector = turf.sector([center.lng, center.lat], this.options.width / 1000 / 2, bearing1, bearing2, { units: 'kilometers', steps: 3600 });
let point1 = turf.point([center.lng, center.lat]);
let point2 = turf.point([...sector.geometry.coordinates[0][Math.ceil(sector.geometry.coordinates[0].length / 2)]]);
let bearing = turf.bearing(point1, point2);
let destination = turf.destination(point1, distance / 1000, bearing, { units: 'kilometers' });
let array = []
array.push([...sector.geometry.coordinates[0][0], center.alt])
array.push([...sector.geometry.coordinates[0][1], center.alt])
array.push([...destination.geometry.coordinates, center.alt])
array.push([...sector.geometry.coordinates[0][sector.geometry.coordinates[0].length - 2], center.alt])
positions.push(array)
positions.push(pos1[i])
}
}
else if (this.cornerType === 1) {
// 斜角
for (let i = 1; i < pos1.length; i++) {
positions.push([pos1[i - 1][2], pos1[i][0], pos1[i - 1][1], pos1[i][3], pos1[i - 1][2]])
positions.push(pos1[i])
}
}
else if (this.cornerType === 2) {
// 圆角
for (let i = 1; i < pos1.length; i++) {
let center = optionsPositions[i]
let pot1 = turf.point(pos1[i - 1][1])
let pot2 = turf.point(pos1[i - 1][2])
let bearing1 = turf.rhumbBearing(pot1, pot2);
let pot3 = turf.point(pos1[i][0])
let pot4 = turf.point(pos1[i][3])
let bearing2 = turf.rhumbBearing(pot3, pot4);
if (Math.sin(Cesium.Math.toRadians(bearing1 - bearing2)) > 0) {
let temporary = bearing1
bearing1 = bearing2 + 180
bearing2 = temporary + 180
}
let sector = turf.sector([center.lng, center.lat], this.options.width / 1000 / 2, bearing1, bearing2, { units: 'kilometers' });
let array = []
for (let n = 0; n < sector.geometry.coordinates[0].length - 1; n++) {
array.push([...sector.geometry.coordinates[0][n], center.alt])
}
positions.push(array)
positions.push(pos1[i])
}
}
return positions
}
//创建
static async create(that) {
// console.log(new Cesium.CustomMaterialSource(), new Cesium.PolylineTrailLinkMaterialProperty())
// let positions = that.options.positions
// let fromDegreesArray = []
// let minimumHeights = []
// let maximumHeights = []
// for (let i = 0; i < positions.length; i++) {
// fromDegreesArray.push(positions[i].lng, positions[i].lat, positions[i].alt)
// minimumHeights.push(positions[i].alt)
// maximumHeights.push(positions[i].alt + that.options.extrudedHeight)
// }
that.entity = new Cesium.EntityCollection()
let positions = that.calculatePositions()
let maximumHeights = []
let minimumHeights = []
for (let i = 0; i < positions.length; i++) {
let fromDegreesArray = []
let fromDegreesArray2 = []
for (let n = 0; n < positions[i].length; n++) {
fromDegreesArray.push(positions[i][n][0], positions[i][n][1], positions[i][n][2])
fromDegreesArray2.push(positions[i][n][0], positions[i][n][1], positions[i][n][2] + that.options.extrudedHeight)
}
let wall = that.sdk.viewer.entities.add({
id: that.options.id + '-' + WallRealStereoscopic.randomString(12),
polylineVolume: {
positions: Cesium.Cartesian3.fromDegreesArrayHeights(fromDegreesArray),
shape: [
{ x: -0.0000001, y: -that.options.extrudedHeight / 2 },
{ x: 0.0000001, y: -that.options.extrudedHeight / 2 },
{ x: 0.0000001, y: that.options.extrudedHeight / 2 },
{ x: -0.0000001, y: that.options.extrudedHeight / 2 },
],
cornerType: Cesium.CornerType.MITERED
},
})
let top = that.sdk.viewer.entities.add({
id: that.options.id + '-' + WallRealStereoscopic.randomString(12),
polygon: {
hierarchy: Cesium.Cartesian3.fromDegreesArrayHeights(fromDegreesArray2),
perPositionHeight: true,
material: Cesium.Color.fromCssColorString(that.options.color)
},
})
that.entity.add(wall)
that.entity.add(top)
wall.polylineVolume.material = that.getMaterial(wall.id)
}
that.entity.show = that.options.show
WallRealStereoscopic.createLabel(that)
syncData(that.sdk, that.options.id)
if (that.options.show) {
setSplitDirection(0, that.options.id)
}
}
// 编辑框
async edit(state) {
let _this = this
this.originalOptions = this.deepCopyObj(this.options)
if (this._DialogObject && this._DialogObject.close) {
this._DialogObject.close()
this._DialogObject = null
}
if (state) {
this._DialogObject = await new Dialog(this.sdk, this.options, {
title: '实体墙属性', left: '180px', top: '100px',
confirmCallBack: (options) => {
this.name = this.name.trim()
if (!this.name) {
this.name = '未命名对象'
}
this.options.label.position = { lng: this.label.position[0], lat: this.label.position[1], alt: this.label.position[2] }
this.originalOptions = this.deepCopyObj(this.options)
this._DialogObject.close()
this.Dialog.confirmCallBack && this.Dialog.confirmCallBack(this.originalOptions)
syncData(this.sdk, this.options.id)
syncSplitData(this.sdk, this.options.id)
},
resetCallBack: () => {
this.reset()
this.Dialog.resetCallBack && this.Dialog.resetCallBack()
},
removeCallBack: () => {
this.Dialog.removeCallBack && this.Dialog.removeCallBack()
},
closeCallBack: () => {
this.reset()
this.Dialog.closeCallBack && this.Dialog.closeCallBack()
for (let i = 0; i < this.nodePoints.length; i++) {
this.sdk.viewer.entities.remove(this.nodePoints[i])
}
this.nodePoints = []
YJ.Measure.SetMeasureStatus(false)
this.event && this.event.destroy()
this.event && this.tip.destroy()
},
showCallBack: (show) => {
this.options.show = show
this.originalOptions.show = show
this.show = show
this.Dialog.showCallBack && this.Dialog.showCallBack()
},
secondaryEditCallBack: () => {
WallRealStereoscopic.nodeEdit(this)
}
})
this._DialogObject._element.body.className = this._DialogObject._element.body.className + ' wall-stereoscopic'
let contentElm = document.createElement('div');
contentElm.innerHTML = html(this)
this._DialogObject.contentAppChild(contentElm)
this.attributeType = this.options.attributeType
this.attributeCamera = this.options.attribute.camera.content
this.attributeISC = this.options.attribute.ISC.content
// 拐角类型下拉
let cornerTypeList = [
{
name: '<svg class="icon-zj"><use xlink:href="#yj-icon-zj"></use></svg>直角',
value: '直角',
key: 0,
icon: 'yj-icon-zj'
},
{
name: '<svg class="icon-xj"><use xlink:href="#yj-icon-xj"></use></svg>斜角',
value: '斜角',
key: 1,
icon: 'yj-icon-xj'
},
{
name: '<svg class="icon-yj"><use xlink:href="#yj-icon-yj"></use></svg>圆角',
value: '圆角',
key: 2,
icon: 'yj-icon-yj'
},
]
let legpCornerType = legp(contentElm.getElementsByClassName('corner-type-box')[0], ".corner-type")
legpCornerType.legp_search(cornerTypeList)
let iActiveElm = document.createElement('i')
iActiveElm.className = "icon-active"
contentElm.getElementsByClassName('corner-type')[0].getElementsByClassName('cy_datalist')[0].appendChild(iActiveElm)
let legpCornerTypeInput = contentElm.getElementsByClassName('corner-type')[0].getElementsByTagName('input')[0]
for (let i = 0; i < cornerTypeList.length; i++) {
if (cornerTypeList[i].key === this.cornerType) {
legpCornerType.legp_searchActive(cornerTypeList[i].value)
legpCornerTypeInput.value = cornerTypeList[i].value
iActiveElm.innerHTML = `<svg class="${cornerTypeList[i].icon}"><use xlink:href="#${cornerTypeList[i].icon}"></use></svg>`
break
}
}
legpCornerTypeInput.addEventListener('input', (e, c) => {
for (let i = 0; i < cornerTypeList.length; i++) {
if (cornerTypeList[i].value === legpCornerTypeInput.value) {
this.cornerType = cornerTypeList[i].key
iActiveElm.innerHTML = `<svg class="${cornerTypeList[i].icon}"><use xlink:href="#${cornerTypeList[i].icon}"></use></svg>`
break
}
}
})
// 材质下拉
let materialList = [
{
name: '<i class="icon icon-wall"></i>纯色墙',
value: '纯色墙',
key: 0,
icon: 'icon-wall'
},
{
name: '<i class="icon icon-wall-brick1"></i>砖墙1',
value: '砖墙1',
key: 1,
icon: 'icon-wall-brick1'
},
{
name: '<i class="icon icon-wall-brick2"></i>砖墙2',
value: '砖墙2',
key: 2,
icon: 'icon-wall-brick2'
},
{
name: '<i class="icon icon-wall-brick3"></i>砖墙3',
value: '砖墙3',
key: 3,
icon: 'icon-wall-brick3'
}
]
let legpMaterial = legp(contentElm.getElementsByClassName('material-box')[0], ".material")
legpMaterial.legp_search(materialList)
let iActiveElm2 = document.createElement('i')
iActiveElm2.className = "icon icon-active"
contentElm.getElementsByClassName('material')[0].getElementsByClassName('cy_datalist')[0].appendChild(iActiveElm2)
let legpMaterialInput = contentElm.getElementsByClassName('material')[0].getElementsByTagName('input')[0]
for (let i = 0; i < materialList.length; i++) {
if (materialList[i].key === this.material) {
legpMaterial.legp_searchActive(materialList[i].value)
legpMaterialInput.value = materialList[i].value
iActiveElm2.className = `icon icon-active ${materialList[i].icon}`
break
}
}
legpMaterialInput.addEventListener('input', (e, c) => {
for (let i = 0; i < materialList.length; i++) {
if (materialList[i].value === legpMaterialInput.value) {
this.material = materialList[i].key
iActiveElm2.className = `icon icon-active ${materialList[i].icon}`
break
}
}
})
// 创建标签页
let tabsElm = new cy_tabs('radar-scan-edit-tabs', undefined, this.sdk)
// 颜色组件
let colorPicker = new ewPlugins('colorpicker', {
el: contentElm.getElementsByClassName("color")[0],
size: 'mini',//颜色box类型
alpha: false,//是否开启透明度
defaultColor: this.color,
disabled: false,//是否禁止打开颜色选择器
openPickerAni: 'opacity',//打开颜色选择器动画
sure: (color) => {
this.color = color
},//点击确认按钮事件回调
clear: () => {
this.color = 'rgba(255,255,255,1)'
},//点击清空按钮事件回调
})
let labelColorPicker = new ewPlugins('colorpicker', {
el: contentElm.getElementsByClassName("labelColor")[0],
size: 'mini',//颜色box类型
alpha: true,//是否开启透明度
defaultColor: this.labelColor,
disabled: false,//是否禁止打开颜色选择器
openPickerAni: 'opacity',//打开颜色选择器动画
sure: (color) => {
this.labelColor = color
},//点击确认按钮事件回调
clear: () => {
this.labelColor = 'rgba(255,255,255,1)'
},//点击清空按钮事件回调
})
let lineColorPicker = new ewPlugins('colorpicker', {
el: contentElm.getElementsByClassName("labelLineColor")[0],
size: 'mini',//颜色box类型
alpha: true,//是否开启透明度
defaultColor: this.labelLineColor,
disabled: false,//是否禁止打开颜色选择器
openPickerAni: 'opacity',//打开颜色选择器动画
sure: (color) => {
this.labelLineColor = color
},//点击确认按钮事件回调
clear: () => {
this.labelLineColor = 'rgba(255,255,255,1)'
},//点击清空按钮事件回调
})
let labelBackgroundColorStartPicker = new ewPlugins('colorpicker', {
el: contentElm.getElementsByClassName("labelBackgroundColorStart")[0],
size: 'mini',
alpha: true,
defaultColor: this.labelBackgroundColorStart,
disabled: false,
openPickerAni: 'opacity',
sure: (color) => {
this.labelBackgroundColorStart = color
},
clear: () => {
this.labelBackgroundColorStart = 'rgba(255,255,255,1)'
},
})
let labelBackgroundColorEndPicker = new ewPlugins('colorpicker', {
el: contentElm.getElementsByClassName("labelBackgroundColorEnd")[0],
size: 'mini',
alpha: true,
defaultColor: this.labelBackgroundColorEnd,
disabled: false,
openPickerAni: 'opacity',
sure: (color) => {
this.labelBackgroundColorEnd = color
},
clear: () => {
this.labelBackgroundColorEnd = 'rgba(255,255,255,1)'
},
})
let all_elm = contentElm.getElementsByTagName("*")
EventBinding.on(this, all_elm)
this._elms = EventBinding.element
this._elms.color = [colorPicker]
this._elms.labelColor = [labelColorPicker]
this._elms.labelLineColor = [lineColorPicker]
this._elms.labelBackgroundColorStart = [labelBackgroundColorStartPicker]
this._elms.labelBackgroundColorEnd = [labelBackgroundColorEndPicker]
setTimeout(() => {
this.attributeLink = this.options.attribute.link.content
this.ISCSelect && this.ISCSelect()
this.goodsSelect && this.goodsSelect()
this.cameraSelect && this.cameraSelect()
this.attributeVr = this.options.attribute.vr.content
let tagData = this.attributeSelect
let legpObject = legp(this._DialogObject._element.content.getElementsByClassName('attribute-select-box')[0], ".attribute-select")
legpObject.legp_search(tagData)
let attributeElm = this._DialogObject._element.content.getElementsByClassName('attribute-select')[0]
if (!attributeElm) {
return
}
let attributeSelectElm = this._DialogObject._element.content.getElementsByClassName('attribute-select')[0].getElementsByTagName('input')[0]
for (let i = 0; i < tagData.length; i++) {
if (tagData[i].key === this.options.attributeType) {
attributeSelectElm.value = tagData[i].value
legpObject.legp_searchActive(tagData[i].value)
break
}
}
attributeSelectElm.addEventListener('input', () => {
for (let i = 0; i < tagData.length; i++) {
if (tagData[i].value === attributeSelectElm.value) {
this.attributeType = tagData[i].key
break
}
}
})
let fontData = getFontList()
let fontObject = legp(
this._DialogObject._element.content.getElementsByClassName(
'font-select-box'
)[0],
'.font-select'
)
if (fontObject) {
fontObject.legp_search(fontData)
let fontDataLegpElm = this._DialogObject._element.content
.getElementsByClassName('font-select')[0]
.getElementsByTagName('input')[0]
fontDataLegpElm.value = fontData[this.labelFontFamily].value
for (let i = 0; i < fontData.length; i++) {
if (fontData[i].value == fontDataLegpElm.value) {
fontObject.legp_searchActive(fontData[i].value)
break
}
}
fontDataLegpElm.addEventListener('input', () => {
for (let i = 0; i < fontData.length; i++) {
if (fontData[i].value === fontDataLegpElm.value) {
this.labelFontFamily = fontData[i].key
break
}
}
})
this._elms.labelFontFamily = [fontDataLegpElm]
}
}, 0);
} else {
if (this._DialogObject && this._DialogObject.remove) {
this._DialogObject.remove()
this._DialogObject = null
}
}
}
reset() {
if (!this.entity) {
return
}
this.options = this.deepCopyObj(this.originalOptions)
this.name = this.originalOptions.name
this.color = this.originalOptions.color
this.width = this.originalOptions.width
this.cornerType = this.originalOptions.cornerType
this.extrudedHeight = this.originalOptions.extrudedHeight
this.labelShow = this.originalOptions.label.show
this.labelColor = this.originalOptions.label.color
this.labelFontSize = this.originalOptions.label.fontSize
this.labelFontFamily = this.originalOptions.label.fontFamily
this.labelScaleByDistance = this.originalOptions.label.scaleByDistance
this.labelNear = this.originalOptions.label.near
this.labelFar = this.originalOptions.label.far
this.labelLineWidth = this.originalOptions.label.lineWidth
this.labelPixelOffset = this.originalOptions.label.pixelOffset
this.labelLineColor = this.originalOptions.label.lineColor
this.labelBackgroundColorStart = this.originalOptions.label.backgroundColor[0]
this.labelBackgroundColorEnd = this.originalOptions.label.backgroundColor[1]
this.instruct = this.originalOptions.instruct
this.operatingPoint = this.originalOptions.operatingPoint
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.attributeISC = this.options.attribute.ISC.content
this.cameraSelect && this.cameraSelect()
this.goodsSelect && this.goodsSelect()
let positions = this.options.positions
let fromDegreesArray = []
let minimumHeights = []
let maximumHeights = []
for (let i = 0; i < positions.length; i++) {
fromDegreesArray.push(positions[i].lng, positions[i].lat, positions[i].alt)
minimumHeights.push(positions[i].alt)
maximumHeights.push(positions[i].alt + this.options.extrudedHeight)
}
// this.entity.polylineVolume.positions = Cesium.Cartesian3.fromDegreesArrayHeights(fromDegreesArray)
}
async remove() {
this.event && this.event.destroy()
this.tip && this.tip.destroy()
this.label.remove()
for (let i = 0; i < this.entity.values.length; i++) {
this.sdk.viewer.entities.remove(this.entity.values[i])
}
this.entity = null
if (this._DialogObject && !this._DialogObject.isDestroy) {
this._DialogObject.close()
this._DialogObject = null
}
await this.sdk.removeIncetance(this.options.id)
await syncData(this.sdk, this.options.id)
}
instructSubmit() {
this.Dialog.instructSubmit && this.Dialog.instructSubmit(this.options.id, this.options.label.text, this.instruct)
this.originalOptions.instruct = this.instruct
}
operatingPointSubmit() {
this.Dialog.operatingPointSubmit && this.Dialog.operatingPointSubmit(this.options.id, this.options.label.text, this.operatingPoint)
this.originalOptions.operatingPoint = this.operatingPoint
}
_addLink() {
// document.getElementsByClassName
if (this._DialogObject._element.content.getElementsByClassName('link_add')[0].value) {
this.options.attribute.link.content.push({
name: '链接',
url: this._DialogObject._element.content.getElementsByClassName('link_add')[0].value
})
this._DialogObject._element.content.getElementsByClassName('link_add')[0].value = ''
this.attributeLink = this.options.attribute.link.content
}
else {
this.Dialog.clickAddLink && this.Dialog.clickAddLink()
}
}
addAttributeLink(link) {
this.options.attribute.link.content.push({
name: '链接',
url: link
})
this.attributeLink = this.options.attribute.link.content
}
_addRr() {
if (this._DialogObject._element.content.getElementsByClassName('vr_add')[0].value) {
this.options.attribute.vr.content.push({
name: '全景图' ,
url: this._DialogObject._element.content.getElementsByClassName('vr_add')[0].value
})
this._DialogObject._element.content.getElementsByClassName('vr_add')[0].value = ''
this.attributeVr = this.options.attribute.vr.content
}
else {
this.Dialog.clickAddVr && this.Dialog.clickAddVr()
}
}
addAttributeRr(vr) {
this.options.attribute.vr.content.push({
name: '全景图' ,
url: vr
})
this.attributeVr = this.options.attribute.vr.content
}
getMaterial(id) {
let material
let img
switch (this.options.material) {
case 0:
material = Cesium.Color.fromCssColorString(this.options.color)
if (this.sdk.viewer.scene.mode === 2) {
material = new Cesium.CustomColorMaterialSource({
color: this.options.color
})
}
break;
case 1:
case 2:
case 3:
case 4:
// material = new Cesium.CustomMaterialSource({
// image: './image/arrow.png',
// repeat: new Cesium.Cartesian2(10, 1.0),
// color: this.options.color,
// duration: this.options.duration
// })
switch (this.options.material) {
case 1:
img = 'brick1'
break
case 2:
img = 'brick2'
break
case 3:
img = 'brick3'
break
case 4:
img = 'brick4'
break
}
material = new Cesium.CustomMaterialSource({
image: this.getSourceRootPath() + `/img/material/${img}.png`,
color: this.options.color,
is2D: false,
repeats: new Cesium.CallbackProperty(() => {
let repeat = [['1.0', 1.0, 1.0]]
if (!this.entity) {
return repeat
}
let entity = this.entity.getById(id)
if (!entity || !entity.polylineVolume) {
return repeat
}
let positionProperty = entity.polylineVolume.positions;
let positions = positionProperty.getValue();
if (!Cesium.defined(positions)) {
return repeat;
}
let totalDistance = 0;
let distances = []
repeat = []
for (let i = 0; i < positions.length - 1; ++i) {
let distance = Cesium.Cartesian3.distance(positions[i], positions[i + 1])
distances.push(distance)
totalDistance += distance;
}
let imgProportion = 45 / 45 // 图片长宽比例
let totalRepeatX = totalDistance / this.options.extrudedHeight;
totalRepeatX = totalRepeatX / imgProportion
let totalRatio = 0
for (let i = 0; i < distances.length; i++) {
let ratio = (distances[i] / totalDistance)
totalRatio += ratio
let repeatX = ratio * totalRepeatX
let repeatY = 1.0
repeat.push([((i + 1) / distances.length).toFixed(30), repeatX, repeatY])
}
return repeat
}, false),
isTranslucent: false,
duration: 0,
})
break;
}
return material
}
/**
* 打开富文本框
*/
openRichTextEditor(e) {
richText.open(this.options.id, this.options.name, this.options.richTextContent)
richText.primaryCallBack = (content) => {
this.options.richTextContent = content
}
}
static nodeEdit(that, cb = () => { }) {
if (YJ.Measure.GetMeasureStatus()) {
cb('上一次测量未结束')
} else {
YJ.Measure.SetMeasureStatus(true)
that.tip = new MouseTip('请选择一个顶点,右键取消', that.sdk)
that.event = new MouseEvent(that.sdk)
that.nodePoints = []
let selectPoint
let originalPosition
let positions = that.options.positions
let fromDegreesArray = []
let fromDegreesArray2 = []
let array = []
let wallPositions = []
let topPositions = []
let isAdd = false
let firstMove = true
let leftEvent = (movement, cartesian) => {
firstMove = true
if (selectPoint) {
isAdd = true
let pos3 = that.sdk.viewer.scene.clampToHeight(cartesian, [...that.entity.values])
that.options.positions[selectPoint.index] = that.cartesian3Towgs84(pos3, that.sdk.viewer)
originalPosition = that.options.positions[selectPoint.index]
let entity = that.sdk.viewer.entities.add({
name: 'node-secondary-edit-point',
position: Cesium.Cartesian3.fromDegrees(that.options.positions[selectPoint.index].lng, that.options.positions[selectPoint.index].lat, that.options.positions[selectPoint.index].alt),
billboard: {
image: that.getSourceRootPath() + '/img/point.png',
width: 15,
height: 15,
disableDepthTestDistance: Number.POSITIVE_INFINITY,
color: Cesium.Color.WHITE.withAlpha(0.99)
},
})
that.nodePoints.splice(selectPoint.index, 0, entity)
that.options.positions.splice(selectPoint.index, 0, that.options.positions[selectPoint.index])
update(true)
that.label.position = [that.options.positions[0].lng, that.options.positions[0].lat, that.options.positions[0].alt + that.options.extrudedHeight]
that.tip.setPosition(
cartesian,
movement.position.x,
movement.position.y
)
that.material = that.material
}
else {
var pick = that.sdk.viewer.scene.pick(movement.position);
if (pick && pick.id && pick.id.name && pick.id.name === 'node-secondary-edit-point') {
selectPoint = pick.id
that.nodePoints.splice(pick.id.index, 1)
that.sdk.viewer.entities.remove(pick.id)
that.tip.set_text('左键开始右键结束CTRL+右键撤销')
originalPosition = that.cartesian3Towgs84(selectPoint.position._value, that.sdk.viewer)
// that.entity.polylineVolume.positions = new Cesium.CallbackProperty(function () {
// return Cesium.Cartesian3.fromDegreesArrayHeights(fromDegreesArray)
// }, false)
update(true)
}
}
}
let rightEvent = (movement, cartesian) => {
if (selectPoint) {
that.options.positions[selectPoint.index] = originalPosition
if (isAdd) {
that.options.positions.splice(selectPoint.index, 1)
}
update()
cb(null, that.options.positions)
}
// that.entity.polylineVolume.positions = Cesium.Cartesian3.fromDegreesArrayHeights(fromDegreesArray)
that.label.position = [that.options.positions[0].lng, that.options.positions[0].lat, that.options.positions[0].alt + that.options.extrudedHeight]
for (let i = 0; i < that.nodePoints.length; i++) {
that.sdk.viewer.entities.remove(that.nodePoints[i])
}
that.nodePoints = []
YJ.Measure.SetMeasureStatus(false)
that.event.destroy()
that.tip.destroy()
that.material = that.material
}
function update(isCallback = false) {
if (that.entity) {
let positions = that.calculatePositions()
for (let i = 0; i < that.entity.values.length; i++) {
that.sdk.viewer.entities.remove(that.entity.values[i])
}
that.entity.removeAll()
wallPositions = []
topPositions = []
for (let i = 0; i < positions.length; i++) {
let fromDegreesArray = []
let fromDegreesArray2 = []
for (let n = 0; n < positions[i].length; n++) {
fromDegreesArray.push(positions[i][n][0], positions[i][n][1], positions[i][n][2])
fromDegreesArray2.push(positions[i][n][0], positions[i][n][1], positions[i][n][2] + that.options.extrudedHeight)
}
wallPositions.push(fromDegreesArray)
topPositions.push(fromDegreesArray2)
let wall = that.sdk.viewer.entities.add({
id: that.options.id + '-' + WallRealStereoscopic.randomString(12),
polylineVolume: {
positions: isCallback ? new Cesium.CallbackProperty(function () {
return Cesium.Cartesian3.fromDegreesArrayHeights(wallPositions[i])
}, false) : Cesium.Cartesian3.fromDegreesArrayHeights(wallPositions[i]),
shape: [
{ x: -0.0000001, y: -that.options.extrudedHeight / 2 },
{ x: 0.0000001, y: -that.options.extrudedHeight / 2 },
{ x: 0.0000001, y: that.options.extrudedHeight / 2 },
{ x: -0.0000001, y: that.options.extrudedHeight / 2 },
],
cornerType: Cesium.CornerType.MITERED
},
})
let top = that.sdk.viewer.entities.add({
id: that.options.id + '-' + WallRealStereoscopic.randomString(12),
polygon: {
hierarchy: isCallback ? new Cesium.CallbackProperty(function () {
return new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArrayHeights(topPositions[i]))
}, false) : new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArrayHeights(topPositions[i])),
perPositionHeight: true,
material: Cesium.Color.fromCssColorString(that.options.color)
},
})
that.entity.add(wall)
that.entity.add(top)
wall.polylineVolume.material = that.getMaterial(wall.id)
}
}
}
that.event.mouse_left(leftEvent)
that.event.mouse_right(rightEvent)
that.event.mouse_move((movement, cartesian) => {
if (selectPoint) {
let pos3 = that.sdk.viewer.scene.clampToHeight(cartesian, [...that.entity.values])
that.options.positions[selectPoint.index] = that.cartesian3Towgs84(pos3, that.sdk.viewer)
let positions = that.calculatePositions()
for (let i = 0; i < positions.length; i++) {
let fromDegreesArray = []
let fromDegreesArray2 = []
for (let n = 0; n < positions[i].length; n++) {
fromDegreesArray.push(positions[i][n][0], positions[i][n][1], positions[i][n][2])
fromDegreesArray2.push(positions[i][n][0], positions[i][n][1], positions[i][n][2] + that.options.extrudedHeight)
}
wallPositions[i] = fromDegreesArray
topPositions[i] = fromDegreesArray2
}
that.label.position = [that.options.positions[0].lng, that.options.positions[0].lat, that.options.positions[0].alt + that.options.extrudedHeight]
// if (firstMove) {
// firstMove = false
// that.material = that.material
// return
// }
}
that.tip.setPosition(
cartesian,
movement.endPosition.x,
movement.endPosition.y
)
})
that.event.mouse_right_keyboard_ctrl((movement, cartesian) => {
if (selectPoint) {
firstMove = true
that.options.positions.pop()
update(true)
that.sdk.viewer.entities.remove(that.nodePoints[that.nodePoints.length - 1])
if (selectPoint.index === that.options.positions.length) {
if (that.nodePoints[selectPoint.index - 1]) {
selectPoint = that.nodePoints[selectPoint.index - 1]
}
else {
selectPoint.index = 0
}
}
that.nodePoints.pop()
}
})
that.event.gesture_pinck_start((movement, cartesian) => {
let startTime = new Date()
let pos = {
position: {
x: (movement.position1.x + movement.position2.x) / 2,
y: (movement.position1.y + movement.position2.y) / 2
}
}
that.event.gesture_pinck_end(() => {
let endTime = new Date()
if (endTime - startTime >= 500) {
// 长按取消
rightEvent(pos, cartesian)
}
else {
leftEvent(pos, cartesian)
}
})
})
for (let i = 0; i < that.options.positions.length; i++) {
let entity = that.sdk.viewer.entities.add({
name: 'node-secondary-edit-point',
index: i,
position: Cesium.Cartesian3.fromDegrees(that.options.positions[i].lng, that.options.positions[i].lat, that.options.positions[i].alt),
billboard: {
image: that.getSourceRootPath() + '/img/point.png',
width: 15,
height: 15,
disableDepthTestDistance: Number.POSITIVE_INFINITY,
color: Cesium.Color.WHITE.withAlpha(0.99)
},
})
that.nodePoints.push(entity)
}
}
}
update() {
if (this.entity) {
let positions = this.calculatePositions()
let wallPositions = []
let topPositions = []
for (let i = 0; i < this.entity.values.length; i++) {
this.sdk.viewer.entities.remove(this.entity.values[i])
}
this.entity.removeAll()
for (let i = 0; i < positions.length; i++) {
let fromDegreesArray = []
let fromDegreesArray2 = []
for (let n = 0; n < positions[i].length; n++) {
fromDegreesArray.push(positions[i][n][0], positions[i][n][1], positions[i][n][2])
fromDegreesArray2.push(positions[i][n][0], positions[i][n][1], positions[i][n][2] + this.options.extrudedHeight)
}
wallPositions.push(fromDegreesArray)
topPositions.push(fromDegreesArray2)
let wall = this.sdk.viewer.entities.add({
id: this.options.id + '-' + WallRealStereoscopic.randomString(12),
polylineVolume: {
positions: Cesium.Cartesian3.fromDegreesArrayHeights(wallPositions[i]),
shape: [
{ x: -0.0000001, y: -this.options.extrudedHeight / 2 },
{ x: 0.0000001, y: -this.options.extrudedHeight / 2 },
{ x: 0.0000001, y: this.options.extrudedHeight / 2 },
{ x: -0.0000001, y: this.options.extrudedHeight / 2 },
],
cornerType: Cesium.CornerType.MITERED
},
})
let top = this.sdk.viewer.entities.add({
id: this.options.id + '-' + WallRealStereoscopic.randomString(12),
polygon: {
hierarchy: new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArrayHeights(topPositions[i])),
perPositionHeight: true,
material: Cesium.Color.fromCssColorString(this.options.color)
},
})
this.entity.add(wall)
this.entity.add(top)
wall.polylineVolume.material = this.getMaterial(wall.id)
}
}
}
setDIV(options = { domid: "", x: 10, y: 10 }) {
options.x = (options.x || options.x === 0) ? options.x : 10
options.y = (options.y || options.y === 0) ? options.y : 10
let points = []
for (let i = 0; i < this.options.positions.length; i++) {
points.push([this.options.positions[i].lng, this.options.positions[i].lat])
}
let line = turf.lineString(points)
let length = turf.length(line, { units: 'kilometers' })
let sliced = turf.lineSliceAlong(line, 0, length / 2, { units: 'kilometers' });
let siteInfoDom = document.getElementById(options.domid)
let siteInfoPosition = Cesium.Cartesian3.fromDegrees(...sliced.geometry.coordinates[sliced.geometry.coordinates.length - 1], this.options.positions[0].alt + this.options.extrudedHeight)
this.sdk.viewer.scene.postRender.addEventListener((percentage) => {
//转换到屏幕坐标
if (siteInfoDom.style.display === 'block' || siteInfoDom.style.display === '') {
let winpos = this.sdk.viewer.scene.cartesianToCanvasCoordinates(siteInfoPosition);
if (winpos) {
siteInfoDom.style.left = (winpos.x + options.x).toFixed(0) + 'px';
siteInfoDom.style.top = (winpos.y + options.y).toFixed(0) + 'px';
}
}
});
}
static randomString(e) {
e = e || 32
var t = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678',
a = t.length,
n = ''
for (let i = 0; i < e; i++) n += t.charAt(Math.floor(Math.random() * a))
return n
}
}
export default WallRealStereoscopic