2174 lines
76 KiB
JavaScript
2174 lines
76 KiB
JavaScript
/**
|
||
* 圆
|
||
*/
|
||
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 MouseEvent from '../../../Event/index'
|
||
import MouseTip from '../../../MouseTip'
|
||
import { syncData } from '../../../Global/MultiViewportMode'
|
||
import { legp } from '../../Element/datalist';
|
||
import { getFontList, getFontFamilyName } from '../../Element/fontSelect'
|
||
import { setSplitDirection, syncSplitData, setActiveId } from '../../../Global/SplitScreen'
|
||
import { setActiveViewer, closeRotateAround, closeViewFollow } from '../../../Global/global'
|
||
|
||
class CircleObject extends Base {
|
||
/**
|
||
* @constructor
|
||
* @description 创建圆
|
||
* @param options {object} 圆属性
|
||
* @param options.id {string} 标注id
|
||
* @param options.name {string} 名称
|
||
* @param options.show=true {boolean} 显示/隐藏
|
||
* @param options.color="#ff000080" {string} 颜色
|
||
* @param options.center {object} 位置
|
||
* @param options.center.lng {object} 经度
|
||
* @param options.center.lat {object} 纬度
|
||
* @param options.center.alt {object} 高度
|
||
* @param options.radius=10 {object}半径
|
||
* @param options.line {object} 边框
|
||
* @param options.line.width=2 {string} 边框宽
|
||
* @param options.line.color="#ff000080" {string} 边框颜色
|
||
* @param options.label {object} 标注
|
||
* @param options.heightMode=2{number} 高度模式(0:海拔高度;1:相对地表;2:依附模式)
|
||
*/
|
||
constructor(sdk, options = {}) {
|
||
super(sdk, options);
|
||
this.options.name = options.name || '未命名对象'
|
||
this.options.color = options.color || "#ff000080"
|
||
this.options.heightMode = (options.heightMode || options.heightMode == 0) ? options.heightMode : 2
|
||
this.options.radius = (options.radius || options.radius === 0) ? options.radius : 10
|
||
this.options.show = (options.show || options.show === false) ? options.show : true
|
||
this.options.center = options.center || {}
|
||
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 = {
|
||
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.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'
|
||
this.event = new MouseEvent(this.sdk)
|
||
this.nodePoints = []
|
||
this.operate = {}
|
||
this.Dialog = {}
|
||
|
||
this.sdk.addIncetance(this.options.id, this)
|
||
CircleObject.create(this)
|
||
}
|
||
|
||
get type() {
|
||
return 'CircleObject'
|
||
}
|
||
|
||
get heightMode() {
|
||
return this.options.heightMode ? this.options.heightMode : 0
|
||
}
|
||
set heightMode(v) {
|
||
this.entity.polygon.hierarchy = []
|
||
setTimeout(() => {
|
||
this.options.heightMode = (v || v == 0) ? v : 2
|
||
this.positionEditing = false
|
||
if (!this.entity) {
|
||
return
|
||
}
|
||
let heightModeName = ''
|
||
CircleObject.closeNodeEdit(this)
|
||
let ground = false
|
||
let disabled = false
|
||
this.renewPositions()
|
||
this.entity.polyline.positions = [
|
||
...this.positions,
|
||
this.positions[0],
|
||
this.positions[1]
|
||
]
|
||
this.entity.polygon.hierarchy = new Cesium.PolygonHierarchy(
|
||
this.positions
|
||
)
|
||
switch (this.options.heightMode) {
|
||
case '0':
|
||
case 0:
|
||
heightModeName = '海拔高度'
|
||
break
|
||
case '1':
|
||
case 1:
|
||
heightModeName = '相对地表'
|
||
break
|
||
case '2':
|
||
case 2:
|
||
ground = true
|
||
disabled = true
|
||
heightModeName = '依附模型'
|
||
break
|
||
}
|
||
this.label.ground = ground
|
||
this.entity.polyline.clampToGround = ground
|
||
this.entity.polyline.arcType = !ground ? Cesium.ArcType.NONE : Cesium.ArcType.GEODESIC,
|
||
this.entity.polygon.perPositionHeight = !ground ? true : false
|
||
this._elms.heightMode && (this._elms.heightMode.value = heightModeName)
|
||
this._elms.heightModeObject && (this._elms.heightModeObject.legp_searchActive(
|
||
heightModeName
|
||
))
|
||
if (disabled) {
|
||
this._elms.heightBox && (this._elms.heightBox.className = 'input-number input-number-unit-1 height-box disabled');
|
||
this._elms.heightConfirm && this._elms.heightConfirm.setAttribute('disabled', 'disabled');
|
||
}
|
||
else {
|
||
this._elms.heightBox && (this._elms.heightBox.className = 'input-number input-number-unit-1 height-box');
|
||
this._elms.heightConfirm && this._elms.heightConfirm.removeAttribute('disabled');
|
||
}
|
||
}, 50);
|
||
}
|
||
|
||
get height() {
|
||
return this.options.center.alt
|
||
}
|
||
|
||
set height(v) {
|
||
if (!v || isNaN(Number(v))) {
|
||
this.options.center.alt = 0
|
||
}
|
||
else {
|
||
this.options.center.alt = Number(Number(v).toFixed(2))
|
||
}
|
||
let ground
|
||
if (this.heightMode == 2) {
|
||
ground = true
|
||
} else {
|
||
ground = false
|
||
}
|
||
this.renewPositions()
|
||
setTimeout(() => {
|
||
this.entity.polygon.hierarchy = new Cesium.PolygonHierarchy(this.positions)
|
||
this.entity.polygon.perPositionHeight = !ground ? true : false
|
||
this.entity.polyline.positions = [
|
||
...this.positions,
|
||
this.positions[0],
|
||
this.positions[1]
|
||
]
|
||
this.entity.polyline.clampToGround = !ground ? false : true
|
||
this.entity.polyline.arcType = !ground ? Cesium.ArcType.NONE : Cesium.ArcType.GEODESIC
|
||
}, 0);
|
||
|
||
this._elms.alt &&
|
||
this._elms.alt.forEach(item => {
|
||
item.innerHTML = this.options.center.alt
|
||
})
|
||
}
|
||
|
||
get radius() {
|
||
return this.options.radius
|
||
}
|
||
set radius(v) {
|
||
this.options.radius = v
|
||
this.renewPositions()
|
||
this.entity.polygon.hierarchy = new Cesium.PolygonHierarchy(this.positions)
|
||
this.entity.polyline.positions = [
|
||
...this.positions,
|
||
this.positions[0],
|
||
this.positions[1]
|
||
]
|
||
}
|
||
|
||
get center() {
|
||
return this.options.center
|
||
}
|
||
set center(v) {
|
||
this.options.center = v
|
||
this.height = this.height
|
||
this._elms.lng &&
|
||
this._elms.lng.forEach(item => {
|
||
item.innerHTML = this.options.center.lng
|
||
})
|
||
this._elms.lat &&
|
||
this._elms.lat.forEach(item => {
|
||
item.innerHTML = this.options.center.lat
|
||
})
|
||
}
|
||
|
||
get color() {
|
||
return this.options.color
|
||
}
|
||
set color(v) {
|
||
this.options.color = v || 'rgba(255, 0, 0, 0.5)'
|
||
if (!this.sdk || !this.sdk.viewer || !this.entity || !this.entity.polygon) {
|
||
return
|
||
}
|
||
let material = Cesium.Color.fromCssColorString(this.options.color)
|
||
if (this.sdk.viewer.scene.mode === 2) {
|
||
material = new Cesium.CustomColorMaterialSource({
|
||
color: this.options.color
|
||
})
|
||
}
|
||
this.entity.polygon.material = material
|
||
if (this._elms.color) {
|
||
this._elms.color.forEach((item, i) => {
|
||
let colorPicker = new YJColorPicker({
|
||
el: item.el,
|
||
size: 'mini',//颜色box类型
|
||
alpha: true,//是否开启透明度
|
||
defaultColor: this.options.color,
|
||
disabled: false,//是否禁止打开颜色选择器
|
||
openPickerAni: 'opacity',//打开颜色选择器动画
|
||
sure: (c) => {
|
||
this.color = c
|
||
},//点击确认按钮事件回调
|
||
clear: () => {
|
||
this.color = 'rgba(255,0,0,0.5)'
|
||
},//点击清空按钮事件回调
|
||
})
|
||
this._elms.color[i] = colorPicker
|
||
})
|
||
}
|
||
}
|
||
|
||
get lineColor() {
|
||
return this.options.line.color
|
||
}
|
||
set lineColor(v) {
|
||
this.options.line.color = v || 'rgba(255, 0, 0, 0.5)'
|
||
if (!this.sdk || !this.sdk.viewer || !this.entity || !this.entity.polyline) {
|
||
return
|
||
}
|
||
this.entity.polyline.material = Cesium.Color.fromCssColorString(this.options.line.color)
|
||
if (this._elms.lineColor) {
|
||
this._elms.lineColor.forEach((item, i) => {
|
||
let lineColorPicker = new YJColorPicker({
|
||
el: item.el,
|
||
size: 'mini',//颜色box类型
|
||
alpha: true,//是否开启透明度
|
||
defaultColor: this.options.line.color,
|
||
disabled: false,//是否禁止打开颜色选择器
|
||
openPickerAni: 'opacity',//打开颜色选择器动画
|
||
sure: (c) => {
|
||
this.lineColor = c
|
||
},//点击确认按钮事件回调
|
||
clear: () => {
|
||
this.lineColor = 'rgba(255,0,0,0.5)'
|
||
},//点击清空按钮事件回调
|
||
})
|
||
this._elms.lineColor[i] = lineColorPicker
|
||
})
|
||
}
|
||
}
|
||
|
||
get lineWidth() {
|
||
return this.options.line.width
|
||
}
|
||
set lineWidth(v) {
|
||
this.options.line.width = ((v || v === 0) ? v : 3)
|
||
this.entity.polyline.width = this.options.line.width
|
||
this._elms.lineWidth && this._elms.lineWidth.forEach((item) => {
|
||
item.value = v
|
||
})
|
||
}
|
||
|
||
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
|
||
}
|
||
set labelShow(v) {
|
||
this.options.label.show = v
|
||
if (this.show && !this.showView || this.showView == 3) {
|
||
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 YJColorPicker({
|
||
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 YJColorPicker({
|
||
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 YJColorPicker({
|
||
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 YJColorPicker({
|
||
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 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 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
|
||
}
|
||
|
||
static create(that) {
|
||
let fromDegreesArray = that.createCircle(that.options.center, that.options.radius)
|
||
let ground
|
||
let height = 0
|
||
|
||
switch (that.options.heightMode) {
|
||
case '0':
|
||
case 0:
|
||
ground = false
|
||
break
|
||
case '1':
|
||
case 1:
|
||
height = that.sdk.viewer.scene.globe.getHeight(Cesium.Cartographic.fromDegrees(that.options.center.lng, that.options.center.lat)) || 0
|
||
ground = false
|
||
break
|
||
case '2':
|
||
case 2:
|
||
ground = true
|
||
break
|
||
}
|
||
if (!that.options.label.position) {
|
||
that.options.label.position = { lng: that.options.center.lng, lat: that.options.center.lat, alt: that.options.center.alt + height }
|
||
}
|
||
|
||
let material = Cesium.Color.fromCssColorString(that.options.color)
|
||
if (that.sdk.viewer.scene.mode === 2) {
|
||
ground = false
|
||
material = new Cesium.CustomColorMaterialSource({
|
||
color: that.options.color
|
||
})
|
||
}
|
||
let fromDegreesArray2 = []
|
||
let positionsA
|
||
for (let i = 0; i < fromDegreesArray.length; i += 2) {
|
||
fromDegreesArray2.push(fromDegreesArray[i], fromDegreesArray[i + 1], that.options.center.alt + height)
|
||
}
|
||
that.options.label.ground = ground
|
||
that.positions = Cesium.Cartesian3.fromDegreesArrayHeights(fromDegreesArray2)
|
||
positionsA = Cesium.Cartesian3.fromDegreesArray(fromDegreesArray)
|
||
that.entity = that.sdk.viewer.entities.add({
|
||
id: that.options.id,
|
||
show: that.options.show,
|
||
polygon: {
|
||
hierarchy: !ground ? new Cesium.PolygonHierarchy(that.positions) : new Cesium.PolygonHierarchy(positionsA),
|
||
perPositionHeight: !ground ? true : false,
|
||
material: material,
|
||
zIndex: that.sdk._entityZIndex
|
||
},
|
||
polyline: {
|
||
positions: [...that.positions, that.positions[0], that.positions[1]],
|
||
width: that.options.line.width,
|
||
material: Cesium.Color.fromCssColorString(that.options.line.color),
|
||
clampToGround: !ground ? false : true,
|
||
arcType: !ground ? Cesium.ArcType.NONE : Cesium.ArcType.GEODESIC,
|
||
zIndex: that.sdk._entityZIndex
|
||
},
|
||
})
|
||
that.sdk._entityZIndex++
|
||
CircleObject.createLabel(that)
|
||
that.options.areaByMeter = Number((Cesium.Math.PI * that.options.radius * that.options.radius).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
|
||
}
|
||
|
||
syncData(that.sdk, that.options.id)
|
||
if (that.options.show) {
|
||
|
||
setSplitDirection(0, that.options.id)
|
||
}
|
||
}
|
||
|
||
static async createLabel(that) {
|
||
// 标签
|
||
that.label = new LabelObject(that.sdk, {
|
||
id: that.options.id,
|
||
show: that.options.show ? that.options.label.show : false,
|
||
position: [that.options.label.position.lng, that.options.label.position.lat, that.options.label.position.alt],
|
||
text: that.options.name,
|
||
fontSize: that.options.label.fontSize,
|
||
fontFamily: that.options.label.fontFamily,
|
||
color: that.options.label.color,
|
||
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,
|
||
ground: that.options.label.ground,
|
||
})
|
||
}
|
||
|
||
// 编辑框
|
||
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) {
|
||
function createSpatialInfoTableContent() {
|
||
let tableElm = contentElm.getElementsByClassName('spatial-info-table')[0]
|
||
let tBodyElm = tableElm.getElementsByClassName('table-body')[0]
|
||
tBodyElm.innerHTML = ''
|
||
_this._elms.lng = []
|
||
_this._elms.lngInput = []
|
||
_this._elms.lat = []
|
||
_this._elms.latInput = []
|
||
_this._elms.alt = []
|
||
_this._elms.altInput = []
|
||
let tr = document.createElement('div')
|
||
tr.className = 'tr'
|
||
tr.innerHTML = `
|
||
<div class="td align-center">圆心坐标</div>
|
||
<div class="td lng align-center"></div>
|
||
<div class="td lat align-center"></div>
|
||
<div class="td alt align-center"></div>
|
||
`
|
||
let lngBox = tr.getElementsByClassName('lng')[0]
|
||
let lng = document.createElement('span')
|
||
lng.innerHTML = (_this.options.center.lng).toFixed(8)
|
||
lngBox.appendChild(lng)
|
||
let lngInput = document.createElement('input')
|
||
lngInput.className = 'input'
|
||
lngInput.type = 'number'
|
||
lngInput.title = ''
|
||
lngInput.min = -180
|
||
lngInput.max = 180
|
||
lngInput.value = (_this.options.center.lng).toFixed(8)
|
||
|
||
let latBox = tr.getElementsByClassName('lat')[0]
|
||
let lat = document.createElement('span')
|
||
lat.innerHTML = (_this.options.center.lat).toFixed(8)
|
||
latBox.appendChild(lat)
|
||
let latInput = document.createElement('input')
|
||
latInput.className = 'input'
|
||
latInput.type = 'number'
|
||
latInput.title = ''
|
||
latInput.min = -90
|
||
latInput.max = 90
|
||
latInput.value = (_this.options.center.lat).toFixed(8)
|
||
|
||
let altBox = tr.getElementsByClassName('alt')[0]
|
||
let alt = document.createElement('span')
|
||
alt.innerHTML = (_this.height).toFixed(2)
|
||
altBox.appendChild(alt)
|
||
let altInput = document.createElement('input')
|
||
altInput.className = 'input'
|
||
altInput.type = 'number'
|
||
altInput.title = ''
|
||
altInput.min = -9999999
|
||
altInput.max = 999999999
|
||
altInput.value = (_this.height).toFixed(2)
|
||
|
||
lngBox.addEventListener('dblclick', () => {
|
||
lngBox.innerHTML = ''
|
||
lngInput.value = Number((_this.options.center.lng).toFixed(8))
|
||
lngBox.appendChild(lngInput)
|
||
lngInput.focus()
|
||
if (_this.operate.positionEditing) {
|
||
_this.positionEditing = false
|
||
}
|
||
CircleObject.closeNodeEdit(_this)
|
||
_this.heightMode = _this.heightMode
|
||
})
|
||
lngInput.addEventListener('blur', () => {
|
||
lngInput.value = Number((_this.options.center.lng).toFixed(8))
|
||
lngBox.innerHTML = ''
|
||
lngBox.appendChild(lng)
|
||
})
|
||
lngInput.addEventListener('input', () => {
|
||
_this.options.center.lng = Number(Number(lngInput.value).toFixed(8))
|
||
lng.innerHTML = _this.options.center.lng.toFixed(8)
|
||
_this.height = _this.height
|
||
})
|
||
|
||
latBox.addEventListener('dblclick', () => {
|
||
latBox.innerHTML = ''
|
||
latInput.value = Number((_this.options.center.lat).toFixed(8))
|
||
latBox.appendChild(latInput)
|
||
latInput.focus()
|
||
if (_this.operate.positionEditing) {
|
||
_this.positionEditing = false
|
||
}
|
||
CircleObject.closeNodeEdit(_this)
|
||
_this.heightMode = _this.heightMode
|
||
})
|
||
latInput.addEventListener('blur', () => {
|
||
latInput.value = Number((_this.options.center.lat).toFixed(8))
|
||
latBox.innerHTML = ''
|
||
latBox.appendChild(lat)
|
||
})
|
||
latInput.addEventListener('input', () => {
|
||
_this.options.center.lat = Number(Number(latInput.value).toFixed(8))
|
||
lat.innerHTML = _this.options.center.lat.toFixed(8)
|
||
_this.height = _this.height
|
||
})
|
||
|
||
altBox.addEventListener('dblclick', () => {
|
||
if (_this.heightMode == 2) {
|
||
return;
|
||
}
|
||
altBox.innerHTML = ''
|
||
altInput.value = Number((_this.height).toFixed(2))
|
||
altBox.appendChild(altInput)
|
||
altInput.focus()
|
||
if (_this.operate.positionEditing) {
|
||
_this.positionEditing = false
|
||
}
|
||
CircleObject.closeNodeEdit(_this)
|
||
_this.heightMode = _this.heightMode
|
||
})
|
||
altInput.addEventListener('blur', () => {
|
||
altInput.value = Number((_this.height).toFixed(2))
|
||
altBox.innerHTML = ''
|
||
altBox.appendChild(alt)
|
||
})
|
||
altInput.addEventListener('input', () => {
|
||
_this.height = Number(Number(altInput.value).toFixed(2))
|
||
alt.innerHTML = Number(_this.height.toFixed(2))
|
||
})
|
||
|
||
|
||
_this._elms.lng.push(lng)
|
||
_this._elms.lngInput.push(lngInput)
|
||
_this._elms.lat.push(lat)
|
||
_this._elms.latInput.push(latInput)
|
||
_this._elms.alt.push(alt)
|
||
_this._elms.altInput.push(altInput)
|
||
tBodyElm.appendChild(tr)
|
||
}
|
||
|
||
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.positionEditing = false
|
||
this.Dialog.closeCallBack && this.Dialog.closeCallBack()
|
||
},
|
||
showCallBack: (show) => {
|
||
this.options.show = show
|
||
this.originalOptions.show = show
|
||
this.show = show
|
||
this.Dialog.showCallBack && this.Dialog.showCallBack()
|
||
},
|
||
translationalCallBack: () => {
|
||
this.positionEditing = !this.positionEditing
|
||
},
|
||
secondaryEditCallBack: () => {
|
||
CircleObject.nodeEdit(this, () => {
|
||
createSpatialInfoTableContent()
|
||
})
|
||
}
|
||
})
|
||
this._DialogObject._element.body.className = this._DialogObject._element.body.className + ' circle'
|
||
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
|
||
|
||
// 创建标签页
|
||
let tabsElm = new cy_tabs('circle-object-edit-tabs', undefined, this.sdk)
|
||
// 颜色组件
|
||
let colorPicker = new YJColorPicker({
|
||
el: contentElm.getElementsByClassName("color")[0],
|
||
size: 'mini',//颜色box类型
|
||
alpha: true,//是否开启透明度
|
||
defaultColor: this.color,
|
||
disabled: false,//是否禁止打开颜色选择器
|
||
openPickerAni: 'opacity',//打开颜色选择器动画
|
||
sure: (color) => {
|
||
this.color = color
|
||
},//点击确认按钮事件回调
|
||
clear: () => {
|
||
this.color = 'rgba(255,255,255,1)'
|
||
},//点击清空按钮事件回调
|
||
})
|
||
let linecolorPicker = new YJColorPicker({
|
||
el: contentElm.getElementsByClassName("lineColor")[0],
|
||
size: 'mini',//颜色box类型
|
||
alpha: true,//是否开启透明度
|
||
defaultColor: this.lineColor,
|
||
disabled: false,//是否禁止打开颜色选择器
|
||
openPickerAni: 'opacity',//打开颜色选择器动画
|
||
sure: (color) => {
|
||
this.lineColor = color
|
||
},//点击确认按钮事件回调
|
||
clear: () => {
|
||
this.lineColor = 'rgba(255,255,255,1)'
|
||
},//点击清空按钮事件回调
|
||
})
|
||
let labelColorPicker = new YJColorPicker({
|
||
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 labellineColorPicker = new YJColorPicker({
|
||
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 YJColorPicker({
|
||
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 YJColorPicker({
|
||
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("*")
|
||
CircleObject.EventBinding(this, all_elm)
|
||
this._elms.color = [colorPicker]
|
||
this._elms.lineColor = [linecolorPicker]
|
||
this._elms.labelColor = [labelColorPicker]
|
||
this._elms.labelLineColor = [labellineColorPicker]
|
||
this._elms.labelBackgroundColorStart = [labelBackgroundColorStartPicker]
|
||
this._elms.labelBackgroundColorEnd = [labelBackgroundColorEndPicker]
|
||
|
||
setTimeout(() => {
|
||
this.attributeLink = this.options.attribute.link.content
|
||
this.attributeVr = this.options.attribute.vr.content
|
||
this.cameraSelect && this.cameraSelect()
|
||
this.goodsSelect && this.goodsSelect()
|
||
let tagData = this.attributeSelect
|
||
let attributeElm = this._DialogObject._element.content.getElementsByClassName('attribute-select-box')[0]
|
||
if (attributeElm) {
|
||
let legpObject = legp(attributeElm, ".attribute-select")
|
||
legpObject.legp_search(tagData)
|
||
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 unitData = [{
|
||
name: '平方米',
|
||
value: '平方米'
|
||
},
|
||
{
|
||
name: '平方千米',
|
||
value: '平方千米'
|
||
},
|
||
{
|
||
name: '亩',
|
||
value: '亩'
|
||
},
|
||
{
|
||
name: '公顷',
|
||
value: '公顷'
|
||
},
|
||
]
|
||
let unitDataLegpObject = legp(this._DialogObject._element.content.getElementsByClassName('input-select-unit-box')[0], ".input-select-unit")
|
||
if (unitDataLegpObject) {
|
||
unitDataLegpObject.legp_search(unitData)
|
||
let unitDataLegpElm = this._DialogObject._element.content.getElementsByClassName('input-select-unit')[0].getElementsByTagName('input')[0]
|
||
unitDataLegpElm.value = this.options['area-unit']
|
||
for (let i = 0; i < unitData.length; i++) {
|
||
if (unitData[i].value === unitDataLegpElm.value) {
|
||
unitDataLegpObject.legp_searchActive(unitData[i].value)
|
||
break
|
||
}
|
||
}
|
||
unitDataLegpElm.addEventListener('input', () => {
|
||
for (let i = 0; i < unitData.length; i++) {
|
||
if (unitData[i].value === unitDataLegpElm.value) {
|
||
this.areaUnit = unitData[i].value
|
||
break
|
||
}
|
||
}
|
||
})
|
||
}
|
||
|
||
let heightBoxElm = this._DialogObject._element.content.getElementsByClassName('height-box')[0]
|
||
let heightElm = heightBoxElm.getElementsByClassName('height')[0]
|
||
let heightConfirmElm = this._DialogObject._element.content.getElementsByClassName('height-confirm')[0]
|
||
heightElm.value = 10
|
||
if (this.heightMode == 2) {
|
||
heightBoxElm && (heightBoxElm.className = 'input-number input-number-unit-1 height-box disabled');
|
||
heightConfirmElm && heightConfirmElm.setAttribute('disabled', 'disabled');
|
||
}
|
||
else {
|
||
heightBoxElm && (heightBoxElm.className = 'input-number input-number-unit-1 height-box');
|
||
heightConfirmElm && heightConfirmElm.removeAttribute('disabled');
|
||
}
|
||
let heightModeData = [
|
||
{
|
||
name: '海拔高度',
|
||
value: '海拔高度',
|
||
key: '0',
|
||
},
|
||
{
|
||
name: '相对地表',
|
||
value: '相对地表',
|
||
key: '1',
|
||
},
|
||
{
|
||
name: '依附模型',
|
||
value: '依附模型',
|
||
key: '2',
|
||
}
|
||
]
|
||
let heightModeObject = legp(
|
||
this._DialogObject._element.content.getElementsByClassName(
|
||
'height-mode-box'
|
||
)[0],
|
||
'.height-mode'
|
||
)
|
||
if (heightModeObject) {
|
||
heightModeObject.legp_search(heightModeData)
|
||
let heightModeDataLegpElm = this._DialogObject._element.content
|
||
.getElementsByClassName('height-mode')[0]
|
||
.getElementsByTagName('input')[0]
|
||
for (let i = 0; i < heightModeData.length; i++) {
|
||
if (heightModeData[i].key == this.heightMode) {
|
||
heightModeDataLegpElm.value = heightModeData[i].value
|
||
heightModeObject.legp_searchActive(
|
||
heightModeData[i].value
|
||
)
|
||
break
|
||
}
|
||
}
|
||
heightModeDataLegpElm.addEventListener('input', () => {
|
||
for (let i = 0; i < heightModeData.length; i++) {
|
||
if (heightModeData[i].value === heightModeDataLegpElm.value) {
|
||
this.heightMode = heightModeData[i].key
|
||
break
|
||
}
|
||
}
|
||
})
|
||
|
||
heightElm.addEventListener('input', () => {
|
||
switch (this.heightMode) {
|
||
case 0:
|
||
case '0':
|
||
break;
|
||
case 1:
|
||
case '1':
|
||
break;
|
||
case 2:
|
||
case '2':
|
||
break;
|
||
}
|
||
})
|
||
|
||
this._elms.height = heightElm
|
||
this._elms.heightBox = heightBoxElm
|
||
this._elms.heightMode = heightModeDataLegpElm
|
||
this._elms.heightConfirm = heightConfirmElm
|
||
this._elms.heightModeObject = heightModeObject
|
||
|
||
heightConfirmElm.addEventListener('click', () => {
|
||
if (this.operate.positionEditing) {
|
||
this.positionEditing = false
|
||
this.height = this.height + Number(heightElm.value)
|
||
}
|
||
else {
|
||
CircleObject.closeNodeEdit(this)
|
||
this.heightMode = this.heightMode
|
||
setTimeout(() => {
|
||
this.height = this.height + Number(heightElm.value)
|
||
}, 100);
|
||
}
|
||
})
|
||
}
|
||
|
||
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]
|
||
}
|
||
|
||
createSpatialInfoTableContent()
|
||
}, 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.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
|
||
this.labelLineWidth = this.originalOptions.label.lineWidth
|
||
this.labelLineColor = this.originalOptions.label.lineColor
|
||
this.labelPixelOffset = this.originalOptions.label.pixelOffset
|
||
this.labelScaleByDistance = this.originalOptions.label.scaleByDistance
|
||
this.labelNear = this.originalOptions.label.near
|
||
this.labelFar = this.originalOptions.label.far
|
||
this.labelColor = this.originalOptions.label.color
|
||
this.lineWidth = this.originalOptions.line.width
|
||
this.lineLength = this.originalOptions.line.length
|
||
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
|
||
|
||
this._elms.lng &&
|
||
this._elms.lng.forEach(item => {
|
||
item.innerHTML = this.options.center.lng
|
||
})
|
||
this._elms.lat &&
|
||
this._elms.lat.forEach(item => {
|
||
item.innerHTML = this.options.center.lat
|
||
})
|
||
this._elms.alt &&
|
||
this._elms.alt.forEach(item => {
|
||
item.innerHTML = this.options.center.alt
|
||
})
|
||
|
||
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.tip && this.tip.destroy()
|
||
}
|
||
|
||
async remove() {
|
||
this.event && this.event.destroy()
|
||
this.tip && this.tip.destroy()
|
||
this.label.remove()
|
||
this.sdk.viewer.entities.remove(this.entity)
|
||
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)
|
||
}
|
||
|
||
_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
|
||
}
|
||
|
||
/**
|
||
* 飞到
|
||
*/
|
||
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 positions = this.entity.polygon.hierarchy.getValue(Cesium.JulianDate.now()).positions
|
||
let positionArray = []
|
||
let height = 0
|
||
let pos84 = this.cartesian3Towgs84(positions[0], this.sdk.viewer)
|
||
let point1 = Cesium.Cartesian3.fromDegrees(pos84.lng, pos84.lat, 0);
|
||
let point2 = Cesium.Cartesian3.fromDegrees(pos84.lng, pos84.lat, 10000000);
|
||
let direction = Cesium.Cartesian3.subtract(point2, point1, new Cesium.Cartesian3());
|
||
let c = Cesium.Cartesian3.normalize(direction, direction);
|
||
let ray = new Cesium.Ray(point1, c);
|
||
let r = {}
|
||
let pickedObjects = this.sdk.viewer.scene.drillPickFromRay(ray);
|
||
for (let i = 0; i < pickedObjects.length; i++) {
|
||
if (pickedObjects[i].position) {
|
||
r = pickedObjects[i]
|
||
break
|
||
}
|
||
}
|
||
if (r && r.position) {
|
||
height = this.cartesian3Towgs84(r.position, this.sdk.viewer).alt
|
||
}
|
||
else {
|
||
try {
|
||
let promise = await Cesium.sampleTerrainMostDetailed(this.sdk.viewer.terrainProvider, [Cesium.Cartographic.fromDegrees(pos84.lng, pos84.lat)]);
|
||
height = promise[0].height
|
||
} catch (error) {
|
||
}
|
||
}
|
||
let a = Cesium.Cartesian3.fromDegrees(pos84.lng, pos84.lat, height)
|
||
positionArray.push(a.x, a.y, a.z)
|
||
for (let i = 1; i < positions.length; i++) {
|
||
positionArray.push(positions[i].x, positions[i].y, positions[i].z)
|
||
}
|
||
let BoundingSphere = Cesium.BoundingSphere.fromVertices(positionArray)
|
||
this.sdk.viewer.camera.flyToBoundingSphere(BoundingSphere, {
|
||
offset: options.orientation || {
|
||
heading: Cesium.Math.toRadians(0.0),
|
||
pitch: Cesium.Math.toRadians(-90.0),
|
||
roll: Cesium.Math.toRadians(0.0)
|
||
}
|
||
})
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 打开富文本框
|
||
*/
|
||
openRichTextEditor(e) {
|
||
richText.open(this.options.id, this.options.name, this.options.richTextContent)
|
||
richText.primaryCallBack = (content) => {
|
||
this.options.richTextContent = content
|
||
}
|
||
}
|
||
|
||
/**@desc 打开平移功能
|
||
*
|
||
* @memberOf Source
|
||
* @param status {boolean}
|
||
*
|
||
* */
|
||
set positionEditing(status) {
|
||
if (YJ.Measure.GetMeasureStatus() || !this.sdk || !this.sdk.viewer || !this.entity) {
|
||
return
|
||
}
|
||
let _this = this
|
||
this.operate.positionEditing = status
|
||
this.event && this.event.destroy()
|
||
this.event = new MouseEvent(this.sdk)
|
||
this.previous = {
|
||
positions: { ...this.options.center }
|
||
}
|
||
if (status === true) {
|
||
this.tip && this.tip.destroy()
|
||
this.tip = new MouseTip('点击鼠标左键确认,右键取消', this.sdk)
|
||
this.label && (this.label.entity.billboard.color = Cesium.Color.fromCssColorString(`rgba(255,255,255,0.9)`))
|
||
this.picking = false
|
||
this.renewPositions()
|
||
this.event.mouse_move((movement, cartesian) => {
|
||
let positions = this.cartesian3Towgs84(cartesian, this.sdk.viewer)
|
||
positions.alt = this.options.center.alt
|
||
// this.renewPositions(positions)
|
||
let height = 0
|
||
let ground = false
|
||
switch (this.options.heightMode) {
|
||
case '0':
|
||
case 0:
|
||
ground = false
|
||
break
|
||
case '1':
|
||
case 1:
|
||
height = this.sdk.viewer.scene.globe.getHeight(Cesium.Cartographic.fromDegrees(positions.lng, positions.lat)) || 0
|
||
ground = false
|
||
break
|
||
case '2':
|
||
case 2:
|
||
ground = true
|
||
break
|
||
}
|
||
|
||
let fromDegreesArray = this.createCircle(positions, this.options.radius)
|
||
let fromDegreesArray2 = []
|
||
if (!ground) {
|
||
for (let i = 0; i < fromDegreesArray.length; i += 2) {
|
||
fromDegreesArray2.push(fromDegreesArray[i], fromDegreesArray[i + 1], positions.alt + height)
|
||
}
|
||
this.positions = Cesium.Cartesian3.fromDegreesArrayHeights(
|
||
fromDegreesArray2
|
||
)
|
||
|
||
this.label && (this.label.position = [
|
||
positions.lng,
|
||
positions.lat,
|
||
positions.alt + height
|
||
])
|
||
} else {
|
||
this.positions = Cesium.Cartesian3.fromDegreesArray(fromDegreesArray)
|
||
let objectsToExclude = [...this.sdk.viewer.entities.values]
|
||
this.getClampToHeight({
|
||
lng: positions.lng,
|
||
lat: positions.lat
|
||
}, objectsToExclude).then(height => {
|
||
this.label && (this.label.position = [
|
||
positions.lng,
|
||
positions.lat,
|
||
height
|
||
])
|
||
})
|
||
}
|
||
this.tip.setPosition(
|
||
cartesian,
|
||
movement.endPosition.x,
|
||
movement.endPosition.y
|
||
)
|
||
})
|
||
this.event.mouse_left((movement, cartesian) => {
|
||
let positions = this.cartesian3Towgs84(cartesian, this.sdk.viewer)
|
||
this.options.center.lng = Number((positions.lng).toFixed(8))
|
||
this.options.center.lat = Number((positions.lat).toFixed(8))
|
||
this.center = this.options.center
|
||
this.event.mouse_move(() => { })
|
||
this.event.mouse_left(() => { })
|
||
this.event.mouse_right(() => { })
|
||
this.event.gesture_pinck_start(() => { })
|
||
this.previous = {
|
||
positions: { ...this.options.center }
|
||
}
|
||
this.positionEditing = false
|
||
})
|
||
this.event.mouse_right((movement, cartesian) => {
|
||
this.positionEditing = false
|
||
})
|
||
this.event.gesture_pinck_start((movement, cartesian) => {
|
||
let startTime = new Date()
|
||
this.event.gesture_pinck_end(() => {
|
||
let endTime = new Date()
|
||
if (endTime - startTime >= 500) {
|
||
// 长按取消
|
||
this.positionEditing = false
|
||
}
|
||
else {
|
||
let positions = this.cartesian3Towgs84(cartesian, this.sdk.viewer)
|
||
this.options.center.lng = Number((positions.lng).toFixed(8))
|
||
this.options.center.lat = Number((positions.lat).toFixed(8))
|
||
this.center = this.options.center
|
||
this.event.mouse_move(() => { })
|
||
this.event.mouse_left(() => { })
|
||
this.event.mouse_right(() => { })
|
||
this.event.gesture_pinck_start(() => { })
|
||
this.event.gesture_pinck_end(() => { })
|
||
this.previous = {
|
||
positions: { ...this.options.center }
|
||
}
|
||
this.positionEditing = false
|
||
}
|
||
})
|
||
})
|
||
|
||
this.entity.polygon.hierarchy = new Cesium.CallbackProperty(function () {
|
||
return new Cesium.PolygonHierarchy(_this.positions)
|
||
}, false)
|
||
this.entity.polyline.positions = new Cesium.CallbackProperty(function () {
|
||
return [..._this.positions, _this.positions[0], _this.positions[1]]
|
||
}, false)
|
||
}
|
||
else {
|
||
if (this.label && this.label.entity && this.label.entity.billboard) {
|
||
this.label.entity.billboard.color = Cesium.Color.fromCssColorString(`rgba(255,255,255,1)`)
|
||
}
|
||
this.picking = true
|
||
if (this.event) {
|
||
this.event.mouse_move(() => { })
|
||
this.event.mouse_left(() => { })
|
||
this.event.mouse_right(() => { })
|
||
this.event.gesture_pinck_start(() => { })
|
||
this.event.destroy()
|
||
}
|
||
this.tip && this.tip.destroy()
|
||
this.renewPositions()
|
||
this.entity.polygon.hierarchy = new Cesium.CallbackProperty(function () {
|
||
return new Cesium.PolygonHierarchy(_this.positions)
|
||
}, true)
|
||
this.entity.polyline.positions = new Cesium.CallbackProperty(function () {
|
||
return [..._this.positions, _this.positions[0], _this.positions[1]]
|
||
}, true)
|
||
}
|
||
}
|
||
get positionEditing() {
|
||
return this.operate.positionEditing
|
||
}
|
||
|
||
static nodeEdit(that, cb = () => { }) {
|
||
that.positionEditing = false
|
||
if (YJ.Measure.GetMeasureStatus()) {
|
||
} else {
|
||
that.event && that.event.destroy()
|
||
that.event = new MouseEvent(that.sdk)
|
||
YJ.Measure.SetMeasureStatus(true)
|
||
that.tip = new MouseTip('左键确认,右键取消', that.sdk)
|
||
that.event = new MouseEvent(that.sdk)
|
||
that.nodePoints = []
|
||
let selectPoint
|
||
let originalPosition
|
||
let newpositions = []
|
||
let fromDegreesArray = []
|
||
let endpoint = { ...that.options.center }
|
||
let moveRadius = null
|
||
let entity
|
||
fromDegreesArray = that.createCircle(that.options.center, that.options.radius)
|
||
|
||
|
||
|
||
that.entity.polyline.clampToGround = true
|
||
that.entity.polyline.arcType = Cesium.ArcType.GEODESIC
|
||
that.entity.polygon.perPositionHeight = false
|
||
that.entity.polygon.hierarchy = new Cesium.CallbackProperty(function () {
|
||
return new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArray(fromDegreesArray))
|
||
}, false)
|
||
that.entity.polyline.positions = new Cesium.CallbackProperty(function () {
|
||
return Cesium.Cartesian3.fromDegreesArray(fromDegreesArray)
|
||
}, false)
|
||
setTimeout(() => {
|
||
let objectsToExclude = [...that.sdk.viewer.entities.values]
|
||
that
|
||
.getClampToHeight({
|
||
lng: that.options.center.lng,
|
||
lat: that.options.center.lat
|
||
}, objectsToExclude)
|
||
.then(height => {
|
||
that.label.position = [
|
||
that.options.center.lng,
|
||
that.options.center.lat,
|
||
height
|
||
]
|
||
})
|
||
}, 50);
|
||
|
||
setTimeout(() => {
|
||
that.event.mouse_left((movement, cartesian) => {
|
||
if (entity) {
|
||
that.sdk.viewer.entities.remove(entity)
|
||
entity = null
|
||
}
|
||
endpoint = that.cartesian3Towgs84(cartesian, that.viewer)
|
||
let radius = that.computeDistance2([that.options.center, endpoint])
|
||
that.radius = radius
|
||
|
||
YJ.Measure.SetMeasureStatus(false)
|
||
that.event.destroy()
|
||
that.tip.destroy()
|
||
|
||
that.heightMode = that.heightMode
|
||
})
|
||
|
||
that.event.mouse_right((movement, cartesian) => {
|
||
if (entity) {
|
||
that.sdk.viewer.entities.remove(entity)
|
||
entity = null
|
||
}
|
||
|
||
YJ.Measure.SetMeasureStatus(false)
|
||
that.event.destroy()
|
||
that.tip.destroy()
|
||
|
||
that.heightMode = that.heightMode
|
||
})
|
||
|
||
that.event.mouse_move((movement, cartesian) => {
|
||
entity && (entity.show = true)
|
||
endpoint = that.cartesian3Towgs84(cartesian, that.viewer)
|
||
moveRadius = that.computeDistance2([that.options.center, endpoint])
|
||
fromDegreesArray = that.createCircle(that.options.center, moveRadius)
|
||
that.tip.setPosition(
|
||
cartesian,
|
||
movement.endPosition.x,
|
||
movement.endPosition.y
|
||
)
|
||
})
|
||
createNodePoints()
|
||
}, 200);
|
||
async function createNodePoints() {
|
||
let objectsToExclude = [...that.sdk.viewer.entities.values]
|
||
let height = await that.getClampToHeight(that.options.center, objectsToExclude)
|
||
let entity = that.sdk.viewer.entities.add({
|
||
name: 'node-secondary-edit-point',
|
||
position: Cesium.Cartesian3.fromDegrees(that.options.center.lng, that.options.center.lat, height),
|
||
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)
|
||
}
|
||
|
||
entity = that.sdk.viewer.entities.add(
|
||
new Cesium.Entity({
|
||
show: false,
|
||
position: new Cesium.CallbackProperty((e) => {
|
||
if (endpoint) {
|
||
let c = that.computeMidpoint(that.options.center, endpoint)
|
||
return Cesium.Cartesian3.fromDegrees(c.lng, c.lat, endpoint.alt)
|
||
} else {
|
||
return Cesium.Cartesian3()
|
||
}
|
||
}, false),
|
||
label: {
|
||
text: new Cesium.CallbackProperty((e) => {
|
||
if (moveRadius > 1000) {
|
||
return '半径:' + (moveRadius / 1000).toFixed(2) + ' 公里'
|
||
}
|
||
return '半径:' + moveRadius + ' 米'
|
||
}, false),
|
||
font: '20px Microsoft YaHei',
|
||
distanceDisplayCondition: 10000000,
|
||
scale: 1,
|
||
horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
|
||
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
||
fillColor: Cesium.Color.fromCssColorString('#f5ce0a'),
|
||
style: Cesium.LabelStyle.FILL_AND_OUTLINE
|
||
},
|
||
polyline: {
|
||
positions: new Cesium.CallbackProperty((e) => {
|
||
return Cesium.Cartesian3.fromDegreesArray([that.options.center.lng, that.options.center.lat, endpoint.lng, endpoint.lat])
|
||
}, false),
|
||
width: 2,
|
||
material:
|
||
Cesium.Color.fromCssColorString('#c1c505').withAlpha(0.5),
|
||
clampToGround: true,
|
||
zIndex: 99999999
|
||
}
|
||
})
|
||
)
|
||
that.nodePoints.push(entity)
|
||
|
||
}
|
||
}
|
||
|
||
static closeNodeEdit(that) {
|
||
YJ.Measure.SetMeasureStatus(false)
|
||
that.event && that.event.destroy()
|
||
that.tip && that.tip.destroy()
|
||
that.tip = null
|
||
|
||
for (let i = 0; i < that.nodePoints.length; i++) {
|
||
that.sdk.viewer.entities.remove(that.nodePoints[i])
|
||
}
|
||
that.nodePoints = []
|
||
that.picking = true
|
||
}
|
||
|
||
|
||
static EventBinding(that, elements) {
|
||
for (let i = 0; i < elements.length; i++) {
|
||
let Event = []
|
||
let isEvent = false
|
||
let removeName = []
|
||
if (!elements[i] || !elements[i].attributes) {
|
||
continue
|
||
}
|
||
for (let m of elements[i].attributes) {
|
||
switch (m.name) {
|
||
case '@model': {
|
||
isEvent = true
|
||
if (elements[i].type == 'checkbox') {
|
||
Event.push((e) => { that[m.value] = e.target.checked })
|
||
elements[i].checked = that[m.value]
|
||
}
|
||
else {
|
||
Event.push((e) => {
|
||
let value = e.target.value
|
||
if (e.target.type == 'number') {
|
||
if (e.data != '.' && (e.data != '-' || e.target.value)) {
|
||
value = Number(value)
|
||
if ((e.target.max) && value > Number(e.target.max)) {
|
||
value = Number(e.target.max)
|
||
}
|
||
if ((e.target.min) && value < Number(e.target.min)) {
|
||
value = Number(e.target.min)
|
||
}
|
||
that[m.value] = value
|
||
}
|
||
}
|
||
else {
|
||
that[m.value] = value
|
||
}
|
||
})
|
||
if (elements[i].nodeName == 'IMG') {
|
||
elements[i].src = that[m.value]
|
||
}
|
||
else {
|
||
elements[i].value = that[m.value]
|
||
}
|
||
}
|
||
if (that._elms[m.value]) {
|
||
that._elms[m.value].push(elements[i])
|
||
}
|
||
else {
|
||
that._elms[m.value] = [elements[i]]
|
||
}
|
||
removeName.push(m.name)
|
||
break;
|
||
}
|
||
case '@click': {
|
||
elements[i].addEventListener('click', (e) => {
|
||
if (typeof (that[m.value]) === 'function') {
|
||
that[m.value](e)
|
||
}
|
||
});
|
||
removeName.push(m.name)
|
||
// elements[i].attributes.removeNamedItem(m.name)
|
||
break;
|
||
}
|
||
case '@change': {
|
||
isEvent = true
|
||
Event.push((e) => {
|
||
let value = e.target.value
|
||
if (e.target.type == 'number' && value != '') {
|
||
value = Number(value)
|
||
e.target.value = value
|
||
}
|
||
if (typeof (that[m.value]) === 'function') {
|
||
that[m.value](e, value)
|
||
}
|
||
})
|
||
break;
|
||
}
|
||
}
|
||
// elements[i].attributes[m] = undefined
|
||
}
|
||
for (let n = 0; n < removeName.length; n++) {
|
||
elements[i].attributes.removeNamedItem(removeName[n])
|
||
}
|
||
|
||
if (isEvent) {
|
||
let ventType = 'input'
|
||
if (elements[i].tagName != 'INPUT' || elements[i].type == 'checkbox') {
|
||
ventType = 'change'
|
||
}
|
||
elements[i].addEventListener(ventType, (e) => {
|
||
for (let t = 0; t < Event.length; t++) {
|
||
Event[t](e)
|
||
}
|
||
});
|
||
}
|
||
}
|
||
}
|
||
|
||
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 siteInfoDom = document.getElementById(options.domid)
|
||
let siteInfoPosition = Cesium.Cartesian3.fromDegrees(this.options.center.lng, this.options.center.lat)
|
||
|
||
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';
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
// 更新坐标
|
||
renewPositions(center) {
|
||
if (this._error) {
|
||
return
|
||
}
|
||
let ground = false
|
||
|
||
if (!center) {
|
||
center = this.options.center
|
||
}
|
||
|
||
let height = 0
|
||
switch (this.options.heightMode) {
|
||
case '0':
|
||
case 0:
|
||
ground = false
|
||
break
|
||
case '1':
|
||
case 1:
|
||
height = this.sdk.viewer.scene.globe.getHeight(Cesium.Cartographic.fromDegrees(center.lng, center.lat)) || 0
|
||
ground = false
|
||
break
|
||
case '2':
|
||
case 2:
|
||
ground = true
|
||
break
|
||
}
|
||
|
||
let fromDegreesArray = this.createCircle(center, this.options.radius)
|
||
let fromDegreesArray2 = []
|
||
if (!ground) {
|
||
for (let i = 0; i < fromDegreesArray.length; i += 2) {
|
||
fromDegreesArray2.push(fromDegreesArray[i], fromDegreesArray[i + 1], center.alt + height)
|
||
}
|
||
this.positions = Cesium.Cartesian3.fromDegreesArrayHeights(
|
||
fromDegreesArray2
|
||
)
|
||
|
||
this.label && (this.label.position = [
|
||
center.lng,
|
||
center.lat,
|
||
center.alt + height
|
||
])
|
||
} else {
|
||
this.positions = Cesium.Cartesian3.fromDegreesArray(fromDegreesArray)
|
||
|
||
setTimeout(() => {
|
||
let objectsToExclude = [...this.sdk.viewer.entities.values]
|
||
this.getClampToHeight({
|
||
lng: center.lng,
|
||
lat: center.lat
|
||
}, objectsToExclude).then(height => {
|
||
this.label && (this.label.position = [
|
||
center.lng,
|
||
center.lat,
|
||
height
|
||
])
|
||
})
|
||
}, 100)
|
||
}
|
||
|
||
// 计算投影面积
|
||
this.options.areaByMeter = Number((Cesium.Math.PI * this.options.radius * this.options.radius).toFixed(2))
|
||
this.areaUnit = this.areaUnit
|
||
return fromDegreesArray
|
||
}
|
||
}
|
||
|
||
export default CircleObject
|