diff --git a/src/Obj/Base/GroundSvg/index.js b/src/Obj/Base/GroundSvg/index.js
index 3f1200c..2cd9bb2 100644
--- a/src/Obj/Base/GroundSvg/index.js
+++ b/src/Obj/Base/GroundSvg/index.js
@@ -6,9 +6,13 @@ import LabelObject from '../LabelObject'
import DrawPoint from '../../../Draw/drawPoint.js'
import richText from '../../Element/richText'
import { legp } from '../../Element/datalist'
+import { getGroundCover } from '../../../Global/global'
+import { getFontList, getFontFamily, getFontFamilyName } from '../../Element/fontSelect'
import { FontLoader } from '../../../../static/3rdparty/three/jsm/loaders/FontLoader.js';
import { TextGeometry } from '../../../../static/3rdparty/three/jsm/geometries/TextGeometry.js';
import * as variable from '../../../../static/3rdparty/three/fonts/FZZongYi-M05S_regular.typeface.json'
+import MouseTip from '../../../MouseTip'
+import MouseEvent from '../../../Event/index'
import Base from "../index";
import { setActiveViewer, closeRotateAround, closeViewFollow } from '../../../Global/global'
import { setSplitDirection, syncSplitData, setActiveId } from '../../../Global/SplitScreen'
@@ -91,6 +95,35 @@ class GroundSvg extends Base {
far: (options.text.far || options.text.far === 0) ? options.text.far : 100000,
}
+ this.options.offset = options.offset || { x: 0.5, y: 1 }
+ this.options.mode = this.options.mode ? 1 : 0
+ this.options.billboard = options.billboard || {}
+ this.options.billboard.scale = this.options.billboard.scale || 1
+ this.options.billboard.near = this.options.billboard.near || this.options.billboard.near === 0 ? this.options.billboard.near : 2000
+ this.options.billboard.far = this.options.billboard.far || this.options.billboard.far === 0 ? this.options.billboard.far : 100000
+ this.options.billboard.scaleByDistance = this.options.billboard.scaleByDistance ? true : false
+
+ options.label = options.label || {}
+ this.options.label = options.label || {}
+ this.options.label.text = options.label.text || this.options.name
+ this.options.name = this.options.label.text
+ this.options.label.show =
+ options.label.show || options.label.show === false
+ ? options.label.show
+ : true
+ this.options.label.fontFamily = options.label.fontFamily || 0
+ this.options.label.fontSize = options.label.fontSize || 39
+ this.options.label.color = options.label.color || '#00ffff'
+ this.options.label.offset = options.label.offset || {}
+ this.options.label.offset.x = this.options.label.offset.x || 0
+ this.options.label.offset.y = this.options.label.offset.y || 0
+
+ this.options.flipe = options.flipe || {}
+ this.options.flipe.x = this.options.flipe.x || false
+ this.options.flipe.y = this.options.flipe.y || false
+ this.options.heightMode =
+ options.heightMode || options.heightMode == 0 ? options.heightMode : 3
+
if (this.options.text.position) {
let point1 = turf.point([this.options.position.lng, this.options.position.lat])
let point2 = turf.point([this.options.text.position.lng, this.options.text.position.lat])
@@ -103,29 +136,30 @@ class GroundSvg extends Base {
}
+ this.operate = {}
this.hierarchys = []
this._elms = {};
this.Dialog = _Dialog
this._isdrag = false
this._EventBinding = new EventBinding()
- if(this.sdk.entityMap.get(this.options.id)) {
+ if (this.sdk.entityMap.get(this.options.id)) {
return
}
this.sdk.addIncetance(this.options.id, this)
this.picking = true
-
+
if (this.options.show) {
setSplitDirection(0, this.options.id)
}
this._entityArray = []
-
+
this.init()
}
- get type () {
+ get type() {
return 'GroundSvg'
}
@@ -149,6 +183,8 @@ class GroundSvg extends Base {
}
set name(v) {
this.options.name = v
+ this.options.label.text = this.options.name
+ this.entity && this.entity.label && (this.entity.label.text = this.options.label.text)
this._elms.name && this._elms.name.forEach((item) => {
item.value = v
})
@@ -161,17 +197,17 @@ class GroundSvg extends Base {
set show(v) {
if (typeof v === "boolean") {
if (this.options.text && this.options.text.show) {
- if(this.text) {
- if((!this.showView || this.showView == 3)) {
+ if (this.text) {
+ if ((!this.showView || this.showView == 3)) {
this.text.show = v
}
else {
this.text.show = false
}
}
-
}
super.show = v
+ this.renewPoint()
} else {
console.error("参数必须为boolean")
}
@@ -207,15 +243,20 @@ class GroundSvg extends Base {
set color(v) {
this.options.color = v
- if (this.options.color) {
- for (let i = 0; i < this.entity.values.length; i++) {
- this.entity.values[i].polygon.material = Cesium.Color.fromCssColorString(this.options.color)
+ if (this.entity.values) {
+ if (this.options.color) {
+ for (let i = 0; i < this.entity.values.length; i++) {
+ this.entity.values[i].polygon.material = Cesium.Color.fromCssColorString(this.options.color)
+ }
+ }
+ else {
+ for (let i = 0; i < this.entity.values.length; i++) {
+ this.entity.values[i].polygon.material = Cesium.Color.fromCssColorString(this.entity.values[i].properties.color._value)
+ }
}
}
else {
- for (let i = 0; i < this.entity.values.length; i++) {
- this.entity.values[i].polygon.material = Cesium.Color.fromCssColorString(this.entity.values[i].properties.color._value)
- }
+ this.createEntity()
}
if (this._elms.color) {
this._elms.color.forEach((item, i) => {
@@ -300,7 +341,7 @@ class GroundSvg extends Base {
}
set textValue(v) {
this.options.text.value = v
- if(this.text) {
+ if (this.text) {
this.text.text = v
}
else {
@@ -317,7 +358,7 @@ class GroundSvg extends Base {
set textShow(v) {
this.options.text.show = v
if (this.show) {
- if((!this.showView || this.showView == 3)) {
+ if ((!this.showView || this.showView == 3)) {
this.text && (this.text.show = v)
}
else {
@@ -611,6 +652,380 @@ class GroundSvg extends Base {
}
}
+ get mode() {
+ return this.options.mode
+ }
+ set mode(v) {
+ this.options.mode = v ? 1 : 0
+ this.drag(false)
+ if (this._DialogObject && this._DialogObject._element && this._DialogObject._element.body) {
+ let elms = [...this._DialogObject._element.body.getElementsByClassName('div-item')]
+ let elms2 = [...this._DialogObject._element.foot.getElementsByTagName('button')]
+ let elms3 = [...this._DialogObject._element.body.getElementsByClassName('custom-divider')]
+ elms.push(...elms2, ...elms3)
+ for (let i = 0; i < elms.length; i++) {
+ let mode = elms[i].getAttribute('mode')
+ if (mode !== null) {
+ if (mode == this.options.mode) {
+ elms[i].style.display = 'block'
+ }
+ else {
+ elms[i].style.display = 'none'
+ }
+ }
+ }
+ }
+
+
+ this.createEntity()
+ let modeData = [
+ {
+ name: '贴地',
+ value: '贴地',
+ key: 0
+ },
+ {
+ name: '立体',
+ value: '立体',
+ key: 1
+ }
+ ]
+ for (let i = 0; i < modeData.length; i++) {
+ if (modeData[i].key === this.options.mode) {
+ this._elms.mode && this._elms.mode.forEach((item) => {
+ item.value = modeData[i].value
+ })
+ break
+ }
+ }
+ }
+
+ get offset() {
+ return this.options.offset
+ }
+ set offset(v) {
+ this.options.offset.x = (v.x || v.x == 0) ? Number(v.x.toFixed(2)) : 0.5
+ this.options.offset.y = (v.y || v.y == 0) ? Number(v.y.toFixed(2)) : 1
+ if (this.options.offset.x < 0) {
+ this.options.offset.x = 0
+ }
+ if (this.options.offset.x > 1) {
+ this.options.offset.x = 1
+ }
+ if (this.options.offset.y < 0) {
+ this.options.offset.y = 0
+ }
+ if (this.options.offset.y > 1) {
+ this.options.offset.y = 1
+ }
+ this.renewPoint()
+ }
+
+ get heightMode() {
+ return this.options.heightMode ? this.options.heightMode : 0
+ }
+ set heightMode(v) {
+ this.options.heightMode = v ? v : 0
+ this.options.heightMode = v || v == 0 ? v : 3
+ let heightMode
+ let heightModeName = ''
+ let altBoxElm
+ if (
+ this._DialogObject &&
+ this._DialogObject._element &&
+ this._DialogObject._element.content
+ ) {
+ altBoxElm = this._DialogObject._element.content.getElementsByClassName(
+ 'alt-box'
+ )[0]
+ }
+ let heightElm
+ if (this._elms.height) {
+ heightElm = this._elms.height.getElementsByClassName('input-number')[0]
+ }
+ switch (this.options.heightMode) {
+ case '0':
+ case 0:
+ altBoxElm &&
+ (altBoxElm.className = 'input-number input-number-unit-1 alt-box')
+ // this._elms.height && (this._elms.height.style.display = 'flex')
+ heightElm && (heightElm.className = 'input-number input-number-unit-1')
+ heightMode = Cesium.HeightReference.NONE
+ heightModeName = '海拔高度'
+ break
+ case '1':
+ case 1:
+ altBoxElm &&
+ (altBoxElm.className = 'input-number input-number-unit-1 alt-box')
+ // this._elms.height && (this._elms.height.style.display = 'flex')
+ heightElm && (heightElm.className = 'input-number input-number-unit-1')
+ heightMode = Cesium.HeightReference.NONE
+ heightModeName = '相对地表'
+ break
+ case '2':
+ case 2:
+ altBoxElm &&
+ (altBoxElm.className =
+ 'input-number input-number-unit-1 alt-box disabled')
+ heightModeName = '依附地表'
+ altBoxElm &&
+ (altBoxElm.className =
+ 'input-number input-number-unit-1 alt-box disabled')
+ heightModeName = '依附地表'
+ heightMode = Cesium.HeightReference.CLAMP_TO_GROUND
+ // this._elms.height && (this._elms.height.style.display = 'none')
+ heightElm && (heightElm.className = 'input-number input-number-unit-1 disabled')
+ break
+ case '3':
+ case 3:
+ altBoxElm &&
+ (altBoxElm.className =
+ 'input-number input-number-unit-1 alt-box disabled')
+ // this._elms.height && (this._elms.height.style.display = 'none')
+ heightElm && (heightElm.className = 'input-number input-number-unit-1 disabled')
+ heightMode = Cesium.HeightReference.NONE
+ heightModeName = '依附模型'
+ break
+ }
+ if (this.entity && this.entity.billboard) {
+ this.entity.billboard.heightReference = heightMode
+ }
+ this._elms.heightMode && (this._elms.heightMode.value = heightModeName)
+ }
+ get billboardScale() {
+ return this.options.billboard.scale
+ }
+ set billboardScale(v) {
+ let billboardScale = Number(v.toFixed(2))
+ if (billboardScale > 99) {
+ billboardScale = 99
+ }
+ if (billboardScale < 0.1) {
+ billboardScale = 0.1
+ }
+ this.options.billboard.scale = billboardScale
+ this.renewPoint()
+ this._elms.billboardScale &&
+ this._elms.billboardScale.forEach(item => {
+ item.value = v
+ })
+ }
+
+ get billboardScaleByDistance() {
+ return this.options.billboard.scaleByDistance
+ }
+ set billboardScaleByDistance(v) {
+ this.options.billboard.scaleByDistance = v
+ this.renewPoint()
+ this._elms.billboardScaleByDistance &&
+ this._elms.billboardScaleByDistance.forEach(item => {
+ item.checked = v
+ })
+ }
+
+ get billboardNear() {
+ return this.options.billboard.near
+ }
+ set billboardNear(v) {
+ let near = v
+ if (near > this.billboardFar) {
+ near = this.billboardFar
+ }
+ this.options.billboard.near = near
+ this.renewPoint()
+ this._elms.billboardNear &&
+ this._elms.billboardNear.forEach(item => {
+ item.value = near
+ })
+ }
+
+ get billboardFar() {
+ return this.options.billboard.far
+ }
+ set billboardFar(v) {
+ let far = v
+ if (far < this.billboardNear) {
+ far = this.billboardNear
+ }
+ this.options.billboard.far = far
+ this.renewPoint()
+ this._elms.billboardFar &&
+ this._elms.billboardFar.forEach(item => {
+ item.value = far
+ })
+ }
+ get labelShow() {
+ return this.options.label.show
+ }
+ set labelShow(v) {
+ this.options.label.show = v
+ if (this.entity) {
+ if (this.mode == 1) {
+ this.entity.label.show = v
+ }
+ else {
+ this.entity.label.show = false
+ }
+ }
+
+ this._elms.labelShow &&
+ this._elms.labelShow.forEach(item => {
+ item.value = v
+ })
+ }
+
+ get labelFontFamily() {
+ return this.options.label.fontFamily
+ }
+
+ set labelFontFamily(v) {
+ this.options.label.fontFamily = v || 0
+ this.renewPoint()
+
+ let name = getFontFamilyName(this.labelFontFamily) || ''
+ this._elms.labelFontFamily &&
+ this._elms.labelFontFamily.forEach(item => {
+ item.value = name
+ })
+ }
+
+ get labelFontSize() {
+ return this.options.label.fontSize
+ }
+ set labelFontSize(v) {
+ this.options.label.fontSize = v
+ this.renewPoint()
+ this._elms.labelFontSize &&
+ this._elms.labelFontSize.forEach(item => {
+ item.value = v
+ })
+ }
+
+ get labelColor() {
+ return this.options.label.color
+ }
+ set labelColor(v) {
+ this.options.label.color = v || '#00ffff'
+ this.renewPoint()
+ if (this._elms.labelColor) {
+ this._elms.labelColor.forEach((item, i) => {
+ let colorPicker = new YJColorPicker({
+ el: item.el,
+ size: 'mini', //颜色box类型
+ alpha: true, //是否开启透明度
+ defaultColor: this.options.label.color,
+ disabled: false, //是否禁止打开颜色选择器
+ openPickerAni: 'opacity', //打开颜色选择器动画
+ sure: c => {
+ this.labelColor = c
+ }, //点击确认按钮事件回调
+ clear: () => {
+ this.labelColor = 'rgba(0,255,255,1)'
+ } //点击清空按钮事件回调
+ })
+ this._elms.labelColor[i] = colorPicker
+ })
+ }
+ }
+
+ set positionEditing(status) {
+ if (!this.sdk || !this.sdk.viewer || !this.entity || this.entity.values) {
+ return
+ }
+ this.operate.positionEditing = status
+ this.event && this.event.destroy()
+ this.event = new MouseEvent(this.sdk)
+ if (status === true) {
+ this.picking = false
+ this.tip && this.tip.destroy()
+ this.tip = new MouseTip('点击鼠标左键确认,右键取消', this.sdk)
+ this.previous = {
+ position: { ...this.options.position }
+ }
+ let moveEvent = (movement, cartesian) => {
+ this.entity.position = new Cesium.CallbackProperty(function () {
+ return cartesian
+ }, false)
+
+ this.tip.setPosition(
+ cartesian,
+ movement.endPosition.x,
+ movement.endPosition.y
+ )
+ }
+ let leftEvent = (movement, cartesian) => {
+ let positions = this.cartesian3Towgs84(cartesian, this.sdk.viewer)
+ this.position = { ...positions }
+ this.previous = {
+ position: { ...this.options.position }
+ }
+ this.event.mouse_move(() => { })
+ this.event.mouse_left(() => { })
+ this.event.mouse_right(() => { })
+ this.event.gesture_pinck_start(() => { })
+ this.event.gesture_pinck_end(() => { })
+ this.entity.position = new Cesium.CallbackProperty(function () {
+ return cartesian
+ }, false)
+ this.positionEditing = false
+ }
+ this.event.mouse_move(moveEvent)
+ this.event.mouse_left(leftEvent)
+ 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()
+ let pos = {
+ position: {
+ x: (movement.position1.x + movement.position2.x) / 2,
+ y: (movement.position1.y + movement.position2.y) / 2
+ }
+ }
+ if (endTime - startTime >= 500) {
+ // 长按取消
+ this.positionEditing = false
+ } else {
+ leftEvent(pos, cartesian)
+ }
+ })
+ })
+ } else {
+ 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.gesture_pinck_end(() => { })
+ this.event.destroy()
+ this.event = null
+ }
+ this.tip && this.tip.destroy()
+ this.position = { ...this.previous.position }
+ this.renewPoint()
+ }
+ }
+
+ get positionEditing() {
+ return this.operate.positionEditing
+ }
+
+ get labelOffset() {
+ return this.options.label.offset
+ }
+ set labelOffset(v) {
+ this.options.label.offset = v
+ this.renewPoint()
+ this._elms.labelOffsetX && (this._elms.labelOffsetX.value = this.options.label.offset.x)
+ this._elms.labelOffsetY && (this._elms.labelOffsetY.value = this.options.label.offset.y)
+ }
+
+
+
init() {
let url = this.replaceHost(this.options.url, this.options.host)
syncData(this.sdk, this.options.id)
@@ -830,7 +1245,8 @@ class GroundSvg extends Base {
this.hierarchys.push(array)
});
this.entity = new Cesium.EntityCollection()
-
+ this.createEntity()
+
syncSplitData(this.sdk, this.options.id)
let perPositionHeight = false
if (this.sdk.viewer._element.className === 'cesium-viewer 2d') {
@@ -840,7 +1256,7 @@ class GroundSvg extends Base {
for (let m = 0; m < this.hierarchys[i].length; m++) {
let id = this.options.id + `-${i}_${m}}`
let oldEntity = this.sdk.viewer.entities.getById(id)
- if(oldEntity) {
+ if (oldEntity) {
this.sdk.viewer.entities.remove(oldEntity)
}
let entity = this.sdk.viewer.entities.add({
@@ -893,6 +1309,186 @@ class GroundSvg extends Base {
})
}
+ async createEntity() {
+ let _this = this
+ let heightMode
+ let font = getFontFamily(this.labelFontFamily) || 'Helvetica'
+ if (this.entity) {
+ this.sdk.viewer.entities.remove(this.entity)
+ this.text && this.text.remove()
+ this.text = null
+ if (this.entity && this.entity.values) {
+ for (let i = this.entity.values.length; i >= 0; i--) {
+ this.sdk.viewer.entities.remove(this.entity.values[i])
+ }
+ }
+ if (this.mode) {
+ switch (this.options.heightMode) {
+ case 2:
+ case '2':
+ heightMode = Cesium.HeightReference.CLAMP_TO_GROUND
+ break
+ }
+ let url = this.replaceHost(this.options.url, this.options.host);
+ if (this.color) {
+ const response = await fetch(url);
+ if (!response.ok) {
+ throw new Error(`HTTP error! status: ${response.status}`);
+ }
+
+ const parser = new DOMParser()
+ const svg = parser.parseFromString(await response.text(), 'image/svg+xml').getElementsByTagName('svg')[0];
+ document.body.appendChild(svg)
+ svg.style.width = 0
+ svg.style.height = 0
+ const fillElements = svg.querySelectorAll('*');
+ fillElements.forEach(el => {
+ let style = window.getComputedStyle(el)
+ if (style.fill && style.fill != 'none') {
+ el.style.fill = this.color;
+ }
+ if (style.stroke && style.stroke != 'none') {
+ el.style.stroke = this.color;
+ }
+ });
+ document.body.removeChild(svg)
+ url = 'data:image/svg+xml;base64,' +
+ btoa(Array.from(new TextEncoder().encode(svg.outerHTML),
+ (byte) => String.fromCharCode(byte)).join(''));
+ }
+
+ const image = new Image();
+ image.crossOrigin = 'Anonymous';
+ image.src = url;
+ image.onload = function () {
+ let canvas = document.createElement('canvas')
+ let width = image.width
+ let height = image.height
+ const ctx = canvas.getContext('2d', { willReadFrequently: true })
+ canvas.width = width
+ canvas.height = height;
+ ctx.drawImage(image, 0, 0, width, height)
+ let billboardH = height * (128 / width)
+
+ let lablePixelOffset = new Cesium.Cartesian2(
+ 128 * _this.billboardScale * (0.5 - _this.options.offset.x) + _this.options.label.offset.x,
+ -billboardH * _this.billboardScale -
+ _this.options.label.fontSize / 2 -
+ 5 + _this.options.label.offset.y
+ )
+
+ _this.entity = new Cesium.Entity({
+ show: _this.options.show,
+ id: _this.options.id,
+ position: Cesium.Cartesian3.fromDegrees(
+ _this.options.position.lng,
+ _this.options.position.lat,
+ _this.options.position.alt || 0
+ ),
+ billboard: {
+ show: _this.mode ? true : false,
+ image: canvas,
+ scale: _this.billboardScale,
+ disableDepthTestDistance: new Cesium.CallbackProperty(function () {
+ return getGroundCover() ? undefined : Number.POSITIVE_INFINITY
+ }, false),
+ heightReference: heightMode,
+ width: 128,
+ height: billboardH,
+ horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
+ verticalOrigin: Cesium.VerticalOrigin.TOP,
+ // pixelOffset: { x: -128 * this.billboardScale * (this.flipeY ? (1-this.options.offset.x) : this.options.offset.x), y: -billboardH * this.billboardScale * (this.flipeX ? (1-this.options.offset.y) : this.options.offset.y) }
+ pixelOffset: { x: -128 * _this.billboardScale * _this.options.offset.x, y: -billboardH * _this.billboardScale * _this.options.offset.y }
+ },
+ label: {
+ show: _this.mode ? _this.options.label.show : false,
+ text: _this.options.label.text,
+ disableDepthTestDistance: new Cesium.CallbackProperty(function () {
+ return getGroundCover() ? undefined : Number.POSITIVE_INFINITY
+ }, false),
+ heightReference: heightMode,
+ font: _this.options.label.fontSize + 'px ' + font,
+ fillColor: Cesium.Color.fromCssColorString(_this.options.label.color),
+ // verticalOrigin : Cesium.VerticalOrigin.BOTTOM,
+ pixelOffset: lablePixelOffset,
+ outlineColor: Cesium.Color.BLACK,
+ outlineWidth: 1,
+ style: Cesium.LabelStyle.FILL_AND_OUTLINE
+ },
+ })
+ if (_this.billboardScaleByDistance) {
+ _this.entity.billboard.scaleByDistance = new Cesium.NearFarScalar(
+ _this.billboardNear,
+ 1,
+ _this.billboardFar,
+ 0
+ )
+ _this.entity.billboard.pixelOffsetScaleByDistance = new Cesium.NearFarScalar(
+ _this.billboardNear,
+ 1,
+ _this.billboardFar,
+ 0
+ )
+ }
+ _this.sdk.viewer.entities.add(_this.entity)
+
+ _this.renewPoint()
+
+ // if (_this.options.heightMode == 3) {
+ // _this.updateHeight()
+ // }
+ }
+ }
+ else {
+ this.entity = new Cesium.EntityCollection()
+ let perPositionHeight = false
+ if (this.sdk.viewer._element.className === 'cesium-viewer 2d') {
+ perPositionHeight = true
+ }
+ for (let i = 0; i < this.hierarchys.length; i++) {
+ for (let m = 0; m < this.hierarchys[i].length; m++) {
+ let entity = this.sdk.viewer.entities.add({
+ id: this.options.id + `-${i}_${m}`,
+ show: this.options.show,
+ polygon: {
+ hierarchy: new Cesium.CallbackProperty(() => {
+ let hierarchy = this.hierarchys[i][m]
+ let holes = []
+ for (let n = 0; n < hierarchy.holes.length; n++) {
+ holes.push({
+ positions: hierarchy.holes[n]
+ })
+ }
+ return {
+ positions: hierarchy.positions,
+ holes: holes
+ }
+ }, true),
+ perPositionHeight: perPositionHeight,
+ zIndex: this.sdk._entityZIndex,
+ material: new Cesium.CustomColorMaterialSource({
+ color: this.options.color || this.geojson.features[i].properties.color
+ })
+ },
+ properties: {
+ id: this.options.id
+ }
+ })
+ this.sdk._entityZIndex++
+ if (this.geojson.features[i].properties.color) {
+ entity.properties = {
+ id: this.options.id,
+ color: this.geojson.features[i].properties.color
+ }
+ }
+ this.entity.add(entity)
+ }
+ }
+ GroundSvg.createText(this)
+ }
+ }
+ }
+
static async createText(that) {
if (that.options.text.position) {
let height
@@ -937,7 +1533,12 @@ class GroundSvg extends Base {
this._DialogObject.close()
this._DialogObject = null
}
+ let _this = this
if (state) {
+ let anchorSetDialogObject
+ let canvas
+ let point
+ let billboardAnchorPosition
this._DialogObject = await new Dialog(this.sdk, this.originalOptions, {
title: '军标属性', left: '180px', top: '100px',
confirmCallBack: (options) => {
@@ -975,6 +1576,12 @@ class GroundSvg extends Base {
this.show = show
this.Dialog.showCallBack && this.Dialog.showCallBack()
},
+ translationalCallBack: () => {
+ this.positionEditing = !this.positionEditing
+ },
+ updateHeightCallBack: () => {
+ this.updateHeight()
+ },
addFootElm: [
{
tagName: 'button',
@@ -1017,6 +1624,128 @@ class GroundSvg extends Base {
await this._DialogObject.contentAppChild(contentElm)
this.attributeType = this.options.attributeType
+ let anchorBtn = contentElm.getElementsByClassName('anchor')[0]
+ anchorBtn.addEventListener('click', async () => {
+ if (anchorSetDialogObject && anchorSetDialogObject.close) {
+ anchorSetDialogObject.close()
+ }
+ document.body.addEventListener('mouseup', mouseupEvent)
+ let DialogClientRect = _this._DialogObject._element.body.getBoundingClientRect()
+ let _DialogObject = await new Dialog(this.sdk, this.originalOptions, {
+ title: '锚点设置', left: (DialogClientRect.left + 80) + 'px', top: (DialogClientRect.top + 200) + 'px',
+ confirmCallBack: (options) => {
+ _this.offset = { x: billboardAnchorPosition.x, y: billboardAnchorPosition.y }
+ _DialogObject.close()
+ },
+ closeCallBack: () => {
+ document.body.removeEventListener('mouseup', mouseupEvent)
+ },
+ }, false)
+ anchorSetDialogObject = _DialogObject
+ _DialogObject._element.body.className = _DialogObject._element.body.className + ' anchor-point'
+ let contentElm = document.createElement('div');
+ let image = new Image()
+ image.src = this.replaceHost(this.options.url, this.options.host)
+ image.onload = function () {
+ let ratio = image.width / image.height
+ canvas = document.createElement('canvas')
+ let width = 150
+ let height = 150 / ratio
+ const ctx = canvas.getContext('2d', { willReadFrequently: true })
+ canvas.width = width
+ canvas.height = height;
+ canvas.style.display = 'block';
+ ctx.drawImage(image, 0, 0, width, height)
+ contentElm.appendChild(canvas)
+ _DialogObject.contentAppChild(contentElm)
+
+ point = document.createElement('span')
+ point.className = 'point'
+ contentElm.appendChild(point)
+ billboardAnchorPosition = { x: _this.offset.x, y: _this.offset.y }
+ point.style.top = `calc(${Number(billboardAnchorPosition.y) * 100}% - 6px)`
+ point.style.left = `calc(${Number(billboardAnchorPosition.x) * 100}% - 6px)`
+
+ canvas.addEventListener('click', (e) => {
+ let x = e.offsetX
+ let y = e.offsetY
+ let anchor = { x: Number((x / canvas.width).toFixed(2)), y: Number((y / canvas.height).toFixed(2)) }
+ if (anchor.x < 0) {
+ anchor.x = 0
+ }
+ if (anchor.x > 1) {
+ anchor.x = 1
+ }
+ if (anchor.y < 0) {
+ anchor.y = 0
+ }
+ if (anchor.y > 1) {
+ anchor.y = 1
+ }
+ billboardAnchorPosition = { x: anchor.x, y: anchor.y }
+
+ point.style.top = `calc(${billboardAnchorPosition.y * 100}% - 5px)`
+ point.style.left = `calc(${billboardAnchorPosition.x * 100}% - 5px)`
+ })
+
+ point.addEventListener('mousedown', (e) => {
+ _DialogObject._element.body.addEventListener('mousemove', mousemoveEvent)
+ })
+ }
+ })
+ function mousemoveEvent(e) {
+ getDialogBodyElm(e.target)
+ function getDialogBodyElm(elm) {
+ if (!elm) {
+ return
+ }
+ else if (elm === anchorSetDialogObject._element.body) {
+ let x = e.x - elm.getBoundingClientRect().left
+ let y = e.y - elm.getBoundingClientRect().top
+ let anchor = { x: Number(((x - 42) / canvas.width).toFixed(2)), y: Number(((y - 71) / canvas.height).toFixed(2)) }
+ if (anchor.x < 0) {
+ anchor.x = 0
+ }
+ if (anchor.x > 1) {
+ anchor.x = 1
+ }
+ if (anchor.y < 0) {
+ anchor.y = 0
+ }
+ if (anchor.y > 1) {
+ anchor.y = 1
+ }
+ billboardAnchorPosition = { x: anchor.x, y: anchor.y }
+
+ point.style.top = `calc(${billboardAnchorPosition.y * 100}% - 5px)`
+ point.style.left = `calc(${billboardAnchorPosition.x * 100}% - 5px)`
+ }
+ else {
+ getDialogBodyElm(elm.offsetParent)
+ }
+ }
+ }
+ function mouseupEvent() {
+ if (anchorSetDialogObject) {
+ anchorSetDialogObject._element.body.removeEventListener('mousemove', mousemoveEvent)
+ }
+ }
+
+ let elms = [...contentElm.getElementsByClassName('div-item')]
+ let elms2 = [...contentElm.getElementsByClassName('custom-divider')]
+ elms.push(...elms2)
+ for (let i = 0; i < elms.length; i++) {
+ let mode = elms[i].getAttribute('mode')
+ if (mode !== null) {
+ if (mode == this.options.mode) {
+ elms[i].style.display = 'block'
+ }
+ else {
+ elms[i].style.display = 'none'
+ }
+ }
+ }
+
// 颜色组件
let colorPicker = new YJColorPicker({
el: contentElm.getElementsByClassName("color")[0],
@@ -1048,13 +1777,97 @@ class GroundSvg extends Base {
},//点击清空按钮事件回调
})
+ 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 all_elm = contentElm.getElementsByTagName("*")
this._EventBinding.on(this, all_elm)
this._elms = this._EventBinding.element
this._elms.color = [colorPicker]
this._elms.textColor = [textColorPicker]
+ this._elms.labelColor = [labelColorPicker]
+
+ let labelFontSizeElm = contentElm.getElementsByClassName('label-font-size')[0]
+ let labelOffsetXElm = contentElm.getElementsByClassName('label-offset-x')[0]
+ let labelOffsetYElm = contentElm.getElementsByClassName('label-offset-y')[0]
+ this._elms.labelFontSize = [labelFontSizeElm]
+ this._elms.labelOffsetX = labelOffsetXElm
+ this._elms.labelOffsetY = labelOffsetYElm
+ labelFontSizeElm.value = this.labelFontSize
+ labelOffsetXElm.value = this.labelOffset.x
+ labelOffsetYElm.value = this.labelOffset.y
+
+ labelFontSizeElm.addEventListener('input', (e) => {
+ if (e.target.value || e.target.value === 0) {
+ let value = Number(e.target.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)
+ }
+ if ((e.target.dataset.min) && v < Number(e.target.dataset.min)) {
+ value = Number(e.target.dataset.min)
+ }
+ this.labelFontSize = value
+ }
+ })
+ labelOffsetXElm.addEventListener('input', (e) => {
+ this.labelOffset = {
+ x: Number(e.target.value),
+ y: this.labelOffset.y
+ }
+ })
+ labelOffsetYElm.addEventListener('input', (e) => {
+ this.labelOffset = {
+ x: this.labelOffset.x,
+ y: Number(e.target.value)
+ }
+ })
+
setTimeout(async () => {
+ let updateHeightBtn = this._DialogObject._element.foot.getElementsByClassName('update-height')[0]
+ let translationalBtn = this._DialogObject._element.foot.getElementsByClassName('translational')[0]
+ // let anchorPointBtn = this._DialogObject._element.foot.getElementsByClassName('anchor-point')[0]
+ let flipeOverXBtn = this._DialogObject._element.foot.getElementsByClassName('flipe-over-x')[0]
+ let flipeOverYBtn = this._DialogObject._element.foot.getElementsByClassName('flipe-over-y')[0]
+ let dragBtn = this._DialogObject._element.foot.getElementsByClassName('drag')[0]
+ updateHeightBtn.setAttribute('mode', 1)
+ translationalBtn.setAttribute('mode', 1)
+ // anchorPointBtn.setAttribute('mode', 1)
+ flipeOverXBtn.setAttribute('mode', 0)
+ flipeOverYBtn.setAttribute('mode', 0)
+ dragBtn.setAttribute('mode', 0)
+ if (this.options.mode == 1) {
+ updateHeightBtn.style.display = 'block'
+ translationalBtn.style.display = 'block'
+ // anchorPointBtn.style.display = 'block'
+ flipeOverXBtn.style.display = 'none'
+ flipeOverYBtn.style.display = 'none'
+ dragBtn.style.display = 'none'
+ }
+ else {
+ updateHeightBtn.style.display = 'none'
+ translationalBtn.style.display = 'none'
+ // anchorPointBtn.style.display = 'none'
+ flipeOverXBtn.style.display = 'block'
+ flipeOverYBtn.style.display = 'block'
+ dragBtn.style.display = 'block'
+ }
+
if (this.sdk && this.sdk.tabHide && Array.isArray(this.sdk.tabHide)) {
for (let m = 0; m < this.sdk.tabHide.length; m++) {
if (this.sdk.tabHide[m] === '属性信息') {
@@ -1093,6 +1906,269 @@ class GroundSvg extends Base {
}
})
}
+
+
+ let modeData = [
+ {
+ name: '贴地',
+ value: '贴地',
+ key: 0
+ },
+ {
+ name: '立体',
+ value: '立体',
+ key: 1
+ }
+ ]
+ let modeDataLegpObject = legp(
+ this._DialogObject._element.content.getElementsByClassName(
+ 'mode-box'
+ )[0],
+ '.mode'
+ )
+ if (modeDataLegpObject) {
+ modeDataLegpObject.legp_search(modeData)
+ let modeDataLegpElm = this._DialogObject._element.content
+ .getElementsByClassName('mode')[0]
+ .getElementsByTagName('input')[0]
+ modeDataLegpElm.value = this.mode
+ for (let i = 0; i < modeData.length; i++) {
+ if (modeData[i].key === this.mode) {
+ modeDataLegpElm.value = modeData[i].value
+ modeDataLegpObject.legp_searchActive(modeData[i].value)
+ break
+ }
+ }
+ modeDataLegpElm.addEventListener('input', () => {
+ for (let i = 0; i < modeData.length; i++) {
+ if (modeData[i].value === modeDataLegpElm.value) {
+ this.mode = modeData[i].key
+ break
+ }
+ }
+ })
+ this._elms.mode = [modeDataLegpElm]
+ }
+
+
+ let heightBoxElm = this._DialogObject._element.content.getElementsByClassName('height-box')[0]
+ let heightElm = heightBoxElm.getElementsByClassName('height')[0]
+ let heightModeData = [
+ {
+ name: '海拔高度',
+ value: '海拔高度',
+ key: '0'
+ },
+ {
+ name: '相对地表',
+ value: '相对地表',
+ key: '1'
+ },
+ {
+ name: '依附地表',
+ value: '依附地表',
+ key: '2'
+ },
+ {
+ name: '依附模型',
+ value: '依附模型',
+ key: '3'
+ }
+ ]
+ let heightMode = this.heightMode
+
+ switch (heightMode) {
+ case 0:
+ case '0':
+ heightElm.value = this.options.position.alt
+ break
+ case 1:
+ case '1':
+ if (this.sdk.viewer.scene.terrainProvider.availability) {
+ Cesium.sampleTerrainMostDetailed(
+ this.sdk.viewer.scene.terrainProvider,
+ [
+ Cesium.Cartographic.fromDegrees(
+ this.options.position.lng,
+ this.options.position.lat
+ )
+ ]
+ ).then(position => {
+ heightElm.value = Number(
+ (this.options.position.alt - Number(position[0].height.toFixed(2))).toFixed(2)
+ )
+ })
+ } else {
+ heightElm.value = Number(this.options.position.alt.toFixed(2))
+ }
+ break
+ case 2:
+ case '2':
+ case 3:
+ case '3':
+ let objectsToExclude = []
+ for (let [key, value] of this.sdk.entityMap) {
+ if (value.type === 'RadarScanStereoscopic' && value.entity) {
+ objectsToExclude.push(value.entity)
+ }
+ }
+ this.getClampToHeight(this.options.position, objectsToExclude).then(h => {
+ this.options.position.alt = Number(h.toFixed(2))
+ this.coordinate = this.options.coordinate
+ this._elms.alt &&
+ this._elms.alt.forEach(item => {
+ item.value = this.options.position.alt
+ })
+ heightElm.value = this.options.position.alt
+ })
+ break
+ }
+ 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]
+ heightModeDataLegpElm.value = heightModeData[this.heightMode].value
+ for (let i = 0; i < heightModeData.length; i++) {
+ if (heightModeData[i].value == heightModeDataLegpElm.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) {
+ heightMode = heightModeData[i].key
+ switch (heightMode) {
+ case 0:
+ case '0':
+ this.options.position.alt = Number(heightElm.value)
+ this.heightMode = 0
+ // this.position = this.options.position
+ break
+ case 1:
+ case '1':
+ if (this.sdk.viewer.scene.terrainProvider.availability) {
+ Cesium.sampleTerrainMostDetailed(
+ this.sdk.viewer.scene.terrainProvider,
+ [
+ Cesium.Cartographic.fromDegrees(
+ this.options.position.lng,
+ this.options.position.lat
+ )
+ ]
+ ).then(position => {
+ this.options.position.alt =
+ Number(heightElm.value) +
+ Number(position[0].height.toFixed(2))
+ // this.position = this.options.position
+ })
+ } else {
+ this.options.position.alt = Number(heightElm.value)
+ // this.position = this.options.position
+ }
+ this.heightMode = 1
+ break
+ case 2:
+ case '2':
+ this.heightMode = 2
+ break
+ case 3:
+ case '3':
+ let objectsToExclude = []
+ for (let [key, value] of this.sdk.entityMap) {
+ if (value.type === 'RadarScanStereoscopic' && value.entity) {
+ objectsToExclude.push(value.entity)
+ }
+ }
+ this.getClampToHeight(this.options.position, objectsToExclude).then(h => {
+ this.options.position.alt = Number(h.toFixed(2))
+ // this.position = this.options.position
+ })
+ this.heightMode = 3
+ break
+ }
+ this.position = this.options.position
+ break
+ }
+ }
+ })
+
+ heightElm.addEventListener('blur', async () => {
+ switch (heightMode) {
+ case 0:
+ case '0':
+ this.options.position.alt = Number(
+ Number(heightElm.value).toFixed(2)
+ )
+ break
+ case 1:
+ case '1':
+ if (this.sdk.viewer.scene.terrainProvider.availability) {
+ let position = await Cesium.sampleTerrainMostDetailed(
+ this.sdk.viewer.scene.terrainProvider,
+ [
+ Cesium.Cartographic.fromDegrees(
+ this.options.position.lng,
+ this.options.position.lat
+ )
+ ]
+ )
+ this.options.position.alt =
+ Number(heightElm.value) +
+ Number(position[0].height.toFixed(2))
+ } else {
+ this.options.position.alt = Number(heightElm.value)
+
+ }
+ break
+ case 2:
+ case '2':
+ break
+ }
+ this.position = this.options.position
+ })
+ this._elms.height = heightBoxElm
+ this._elms.heightMode = heightModeDataLegpElm
+
+ this.heightMode = this.heightMode
+ }
+
+ 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)
let xElm = contentElm.getElementsByClassName('x-scale')[0]
@@ -1296,26 +2372,26 @@ class GroundSvg extends Base {
angleH = bearing2 - bearingH
if ((angleW > -360 && angleW < -90) || (angleW < 360 && angleW > 90)) {
angleW = angleW + 180
- flag=true
+ flag = true
}
if ((angleH > -360 && angleH < -90) || (angleH < 360 && angleH > 90)) {
angleH = angleH + 180
- flag2=true
+ flag2 = true
}
- if(flag && flag2) {
+ if (flag && flag2) {
this.pointEntityCollection.values[1].point.color = Cesium.Color.fromCssColorString('#00ff0a')
this.pointEntityCollection.values[3].point.color = Cesium.Color.fromCssColorString('#00ff0a')
this.pointEntityCollection.values[7].point.color = Cesium.Color.fromCssColorString('#00ff0a')
this.pointEntityCollection.values[9].point.color = Cesium.Color.fromCssColorString('#ff0000')
}
else {
- if(flag) {
+ if (flag) {
this.pointEntityCollection.values[1].point.color = Cesium.Color.fromCssColorString('#00ff0a')
this.pointEntityCollection.values[3].point.color = Cesium.Color.fromCssColorString('#ff0000')
this.pointEntityCollection.values[7].point.color = Cesium.Color.fromCssColorString('#00ff0a')
this.pointEntityCollection.values[9].point.color = Cesium.Color.fromCssColorString('#00ff0a')
}
- else if(flag2) {
+ else if (flag2) {
this.pointEntityCollection.values[1].point.color = Cesium.Color.fromCssColorString('#00ff0a')
this.pointEntityCollection.values[3].point.color = Cesium.Color.fromCssColorString('#00ff0a')
this.pointEntityCollection.values[7].point.color = Cesium.Color.fromCssColorString('#ff0000')
@@ -1368,26 +2444,26 @@ class GroundSvg extends Base {
if ((angleW > -360 && angleW < -90) || (angleW < 360 && angleW > 90)) {
angleW = angleW + 180
- flag=true
+ flag = true
}
if ((angleH > -360 && angleH < -90) || (angleH < 360 && angleH > 90)) {
angleH = angleH + 180
- flag2=true
+ flag2 = true
}
- if(flag && flag2) {
+ if (flag && flag2) {
this.pointEntityCollection.values[1].point.color = Cesium.Color.fromCssColorString('#00ff0a')
this.pointEntityCollection.values[3].point.color = Cesium.Color.fromCssColorString('#00ff0a')
this.pointEntityCollection.values[7].point.color = Cesium.Color.fromCssColorString('#ff0000')
this.pointEntityCollection.values[9].point.color = Cesium.Color.fromCssColorString('#00ff0a')
}
else {
- if(flag) {
+ if (flag) {
this.pointEntityCollection.values[1].point.color = Cesium.Color.fromCssColorString('#ff0000')
this.pointEntityCollection.values[3].point.color = Cesium.Color.fromCssColorString('#00ff0a')
this.pointEntityCollection.values[7].point.color = Cesium.Color.fromCssColorString('#00ff0a')
this.pointEntityCollection.values[9].point.color = Cesium.Color.fromCssColorString('#00ff0a')
}
- else if(flag2) {
+ else if (flag2) {
this.pointEntityCollection.values[1].point.color = Cesium.Color.fromCssColorString('#00ff0a')
this.pointEntityCollection.values[3].point.color = Cesium.Color.fromCssColorString('#00ff0a')
this.pointEntityCollection.values[7].point.color = Cesium.Color.fromCssColorString('#00ff0a')
@@ -1603,7 +2679,7 @@ class GroundSvg extends Base {
controlPoints[9] = turf.destination(point, wh, 0 + angle, options).geometry.coordinates
this.controlPoints = controlPoints
- if(!this.sdk || !this.sdk.viewer) {
+ if (!this.sdk || !this.sdk.viewer) {
return
}
for (let i = 0; i < this.controlPoints.length; i++) {
@@ -1846,7 +2922,7 @@ class GroundSvg extends Base {
})
this.hierarchys = [...hierarchys]
- if (!this.entity) {
+ if (!this.entity || !this.entity.values) {
return
}
@@ -2094,13 +3170,13 @@ class GroundSvg extends Base {
}
async remove() {
- this._worker.onmessage = (event) => {}
+ this._worker.onmessage = (event) => { }
await this.sdk.removeIncetance(this.options.id)
if (!this.entity) {
return
}
this.drag(false)
- if(!this.sdk || !this.sdk.viewer) {
+ if (!this.sdk || !this.sdk.viewer) {
return
}
this.sdk.viewer.entities.remove(this.entity)
@@ -2112,7 +3188,7 @@ class GroundSvg extends Base {
this._DialogObject.close()
this._DialogObject = null
}
-
+
await syncData(this.sdk, this.options.id)
}
@@ -2144,6 +3220,166 @@ class GroundSvg extends Base {
this.attributeLink = this.options.attribute.link.content
}
+ async updateHeight() {
+ let height
+ let height2
+ let point1 = new Cesium.Cartesian3.fromDegrees(
+ this.options.position.lng,
+ this.options.position.lat,
+ 0
+ )
+ let point2 = new Cesium.Cartesian3.fromDegrees(
+ this.options.position.lng,
+ this.options.position.lat,
+ 10000000000000
+ )
+
+ let objectsToExclude = []
+ for (let [key, value] of this.sdk.entityMap) {
+ if (value.type === 'RadarScanStereoscopic' && value.entity) {
+ objectsToExclude.push(value.entity)
+ }
+ }
+ let updatedCartesians = await this.sdk.viewer.scene.clampToHeightMostDetailed([point1], objectsToExclude)
+ if (updatedCartesians && updatedCartesians[0]) {
+ height = this.cartesian3Towgs84(updatedCartesians[0], this.sdk.viewer).alt
+ }
+
+ let direction = Cesium.Cartesian3.subtract(
+ point1,
+ point2,
+ new Cesium.Cartesian3()
+ )
+ let c = Cesium.Cartesian3.normalize(direction, new Cesium.Cartesian3())
+ let ray = new Cesium.Ray(point2, c)
+ let r = {}
+ let pickedObjects = this.sdk.viewer.scene.drillPickFromRay(ray)
+ for (let i = pickedObjects.length - 1; i >= 0; i--) {
+ if (pickedObjects[i].position) {
+ r = pickedObjects[i]
+ break
+ }
+ }
+ if (r && r.position) {
+ height2 = this.cartesian3Towgs84(r.position, this.sdk.viewer).alt
+ }
+ let promise
+ try {
+ promise = await Cesium.sampleTerrainMostDetailed(
+ this.sdk.viewer.terrainProvider,
+ [
+ Cesium.Cartographic.fromDegrees(
+ this.options.position.lng,
+ this.options.position.lat
+ )
+ ]
+ )
+ } catch (error) { }
+
+ if ((height2 === void 0 || height2 < promise[0].height) && promise) {
+ height2 = promise[0].height
+ }
+ if (height === void 0 || height < height2) {
+ height = height2
+ }
+ if (height !== undefined) {
+ this.options.position.alt = Number(Number(height).toFixed(2))
+ this._elms.alt &&
+ this._elms.alt.forEach(item => {
+ item.value = this.options.position.alt
+ })
+ this.coordinate = this.options.coordinate
+
+ if (this._elms.height) {
+ let heightElm = this._elms.height.getElementsByClassName('height')[0]
+ if (heightElm) {
+ switch (this._elms.heightMode.value) {
+ case '海拔高度':
+ heightElm.value = this.options.position.alt
+ break
+ case '相对地表':
+ if (this.sdk.viewer.scene.terrainProvider.availability) {
+ Cesium.sampleTerrainMostDetailed(
+ this.sdk.viewer.scene.terrainProvider,
+ [
+ Cesium.Cartographic.fromDegrees(
+ this.options.position.lng,
+ this.options.position.lat
+ )
+ ]
+ ).then(position => {
+ heightElm.value = Number(
+ (this.options.position.alt - position[0].height).toFixed(2)
+ )
+ })
+ } else {
+ heightElm.value = this.options.position.alt
+ }
+ break
+ case '依附地表':
+ break
+ case '依附模型':
+ heightElm.value = this.options.position.alt
+ break
+ }
+ }
+ }
+ }
+ }
+
+ renewPoint() {
+ if (this.entity && !this.entity.values && this.entity.billboard) {
+ let font = getFontFamily(this.labelFontFamily) || 'Helvetica'
+ this.entity.billboard.scale = this.billboardScale
+ if (this.billboardScaleByDistance) {
+ this.entity.billboard.scaleByDistance = new Cesium.NearFarScalar(
+ this.billboardNear,
+ 1,
+ this.billboardFar,
+ 0
+ )
+ this.entity.billboard.pixelOffsetScaleByDistance = new Cesium.NearFarScalar(
+ this.billboardNear,
+ 1,
+ this.billboardFar,
+ 0
+ )
+ this.entity.label.scaleByDistance = new Cesium.NearFarScalar(
+ this.billboardNear,
+ 1,
+ this.billboardFar,
+ 0
+ )
+ this.entity.label.pixelOffsetScaleByDistance = new Cesium.NearFarScalar(
+ this.billboardNear,
+ 1,
+ this.billboardFar,
+ 0
+ )
+ } else {
+ this.entity.billboard.scaleByDistance = undefined
+ this.entity.billboard.pixelOffsetScaleByDistance = undefined
+ this.entity.label.scaleByDistance = undefined
+ this.entity.label.pixelOffsetScaleByDistance = undefined
+ }
+ this.entity.label.font = this.options.label.fontSize + 'px ' + font
+ this.entity.label.fillColor = Cesium.Color.fromCssColorString(
+ this.options.label.color
+ )
+ let canvas = this.entity.billboard.image.getValue()
+ let billboardH = canvas.height * (128 / canvas.width)
+ this.entity.billboard.pixelOffset = { x: -128 * this.billboardScale * this.options.offset.x, y: -billboardH * this.billboardScale * this.options.offset.y }
+
+ let lablePixelOffset = new Cesium.Cartesian2(
+ 128 * this.billboardScale * (0.5 - this.options.offset.x) + this.options.label.offset.x,
+ -billboardH * this.billboardScale -
+ this.options.label.fontSize / 2 -
+ 5 + this.options.label.offset.y
+ )
+ this.entity.label.pixelOffset = lablePixelOffset
+ }
+ }
+
/**
* 打开富文本框
*/
@@ -2210,7 +3446,7 @@ class GroundSvg extends Base {
else {
let array = []
for (let i = 0; i < this.controlPoints.length; i++) {
- let height = await this.getClampToHeight({lng: this.controlPoints[i][0], lat: this.controlPoints[i][1]})
+ let height = await this.getClampToHeight({ lng: this.controlPoints[i][0], lat: this.controlPoints[i][1] })
let cartesian = Cesium.Cartesian3.fromDegrees(this.controlPoints[i][0], this.controlPoints[i][1], height)
array.push(cartesian.x, cartesian.y, cartesian.z)
}
diff --git a/src/Obj/Element/Dialog/index.js b/src/Obj/Element/Dialog/index.js
index aecd327..6ed25c4 100644
--- a/src/Obj/Element/Dialog/index.js
+++ b/src/Obj/Element/Dialog/index.js
@@ -78,6 +78,7 @@ class Dialog extends BaseDialog {
this.footAppChild(div)
if (this.options.updateHeightCallBack) {
let heightBtn = document.createElement('button');
+ heightBtn.className = 'update-height'
heightBtn.innerHTML = '更新高程'
heightBtn.style.width = 'auto'
heightBtn.addEventListener('click', () => {
diff --git a/static/custom/css/index.css b/static/custom/css/index.css
index ebb0d0d..6a18b7a 100644
--- a/static/custom/css/index.css
+++ b/static/custom/css/index.css
@@ -2718,7 +2718,7 @@
/* 贴地svg */
.YJ-custom-base-dialog.ground-svg>.content {
- width: 535px;
+ width: 560px;
}
.YJ-custom-base-dialog.ground-svg>.content>div .div-item:nth-of-type(2) .row .col .label {