diff --git a/src/Draw/drawAttackArrow.js b/src/Draw/drawAttackArrow.js index 0cd20a4..c9208e2 100644 --- a/src/Draw/drawAttackArrow.js +++ b/src/Draw/drawAttackArrow.js @@ -59,12 +59,17 @@ export default class DrawAttackArrow extends Draw { return } into = '3D' + let pos84 = this.cartesian3Towgs84(cartesian, this.viewer) + let lastPos84 = cache_positions[cache_positions.length - 1] + if(lastPos84 && (lastPos84.lng === pos84.lng && lastPos84.lat === pos84.lat)) { + return + } if (!this.entityHasCreated) { let polyline_id = DrawAttackArrow.create_arrow_polygon(this) this.points_ids.push(polyline_id) } this.points_ids.push(this.create_point(cartesian)) - cache_positions.push(this.cartesian3Towgs84(cartesian, this.viewer)) + cache_positions.push(pos84) isMove = false }) this.event.mouse_right((movement, cartesian) => { diff --git a/src/Global/MapX/index.js b/src/Global/MapX/index.js index a96b34f..d16f0cd 100644 --- a/src/Global/MapX/index.js +++ b/src/Global/MapX/index.js @@ -124,7 +124,7 @@ function syncViewer() { if (height > 9000000) { height = 9000000 } - if (height < 100000) { + if (height < 400000) { this.entity.billboard.show = true this.entity.rectangle.show = false } diff --git a/src/Global/MouseCoordinate/index.js b/src/Global/MouseCoordinate/index.js index 0189c67..147f96a 100644 --- a/src/Global/MouseCoordinate/index.js +++ b/src/Global/MouseCoordinate/index.js @@ -4,18 +4,38 @@ import Tools from "../../Tools"; import { getCoordinateSystem } from "../../Global/global"; import MouseEvent from '../../Event/index' +import { getSdk as get2DSdk } from '../../Global/MultiViewportMode' +import { getSdk as getSplitScreenSdk } from "../../Global/SplitScreen"; let event +let event2 let MouseCoordinateElm let requestAnimationFrameEventId +let tmovement +let targetSdk +let sdkD const MouseCoordinate = (sdk, status) => { + if (!sdk || !sdk.viewer) { + return + } + targetSdk = sdk + sdkD = get2DSdk().sdkD + if(!sdkD) { + sdkD = getSplitScreenSdk().sdkD + } + let tools = new Tools(sdk) if (status) { if (event) { event.destroy() } + if (event2) { + event2.destroy() + event2 = undefined + } event = new MouseEvent(sdk) + tmovement = null let position = { x: '', y: '', @@ -40,22 +60,60 @@ const MouseCoordinate = (sdk, status) => { contentElm.style['background-size'] = `200% 200%`; MouseCoordinateElm = contentElm } - sdk.viewer._element.appendChild(contentElm) - let tmovement + sdk.viewer.container.appendChild(contentElm) + event.mouse_move((movement, cartesian) => { - tmovement = { ...movement } + targetSdk = sdk + tmovement = { ...movement.endPosition } }) const getPosition = () => { - if(!tmovement) { + if (!targetSdk) { return } let canvas = sdk.viewer._element.getElementsByTagName('canvas')[0] - let left = tmovement.endPosition.x; - let top = tmovement.endPosition.y; - let cartesian = event.getcartesian(tmovement) - contentElm.style['background-position-x'] = `${-canvas.width + left + 4}px`; - contentElm.style['background-position-y'] = `${-canvas.height + top - 2}px`; + sdkD = get2DSdk().sdkD + if(!sdkD) { + sdkD = getSplitScreenSdk().sdkD + } + if (!event2 && sdkD) { + event2 = new MouseEvent(sdkD) + event2.mouse_move((movement, cartesian) => { + targetSdk = sdkD + tmovement = { x: movement.endPosition.x, y: movement.endPosition.y } + }) + } + if (!tmovement) { + return + } + let left = tmovement.x; + let top = tmovement.y; + let cartesian + if (targetSdk.viewer.scene.mode === 2) { + left = left + canvas.width + cartesian = targetSdk.viewer.camera.pickEllipsoid(tmovement, targetSdk.viewer.scene.globe.ellipsoid) + } + else { + cartesian = targetSdk.viewer.scene.pickPosition(tmovement) + if (!cartesian) { + const ray = targetSdk.viewer.camera.getPickRay(position); //相交的射线 + let pickedObjects = targetSdk.viewer.scene.drillPickFromRay(ray, 10); + let result = {} + for (let i = 0; i < pickedObjects.length; i++) { + if (pickedObjects[i].position) { + result = pickedObjects[i] + break + } + } + cartesian = result.position + if (!cartesian) { + cartesian = targetSdk.viewer.scene.globe.pick(ray, targetSdk.viewer.scene); + } + } + } + contentElm.style['background-position-x'] = `${-sdk.viewer.container.clientWidth + left + 4}px`; + + contentElm.style['background-position-y'] = `${-sdk.viewer.container.clientHeight + top - 2}px`; // this.entity.position = cartesian if (cartesian) { let degrees = tools.cartesian3Towgs84(cartesian, sdk.viewer) @@ -97,10 +155,13 @@ const MouseCoordinate = (sdk, status) => { else { if (event) { event.destroy() - event = undefined + } + if (event2) { + event2.destroy() + event2 = undefined } if (MouseCoordinateElm) { - sdk.viewer._element.removeChild(MouseCoordinateElm) + sdk.viewer.container.removeChild(MouseCoordinateElm) MouseCoordinateElm = undefined } if (requestAnimationFrameEventId) { diff --git a/src/Global/MultiViewportMode/index.js b/src/Global/MultiViewportMode/index.js index 5d3c600..53ec9c0 100644 --- a/src/Global/MultiViewportMode/index.js +++ b/src/Global/MultiViewportMode/index.js @@ -50,6 +50,11 @@ async function init(sdk) { for (let i = 0; i < imageryLayers.length; i++) { let entity = sdk2D.viewer.imageryLayers.addImageryProvider(imageryLayers[i].imageryProvider, imageryLayers[i]._layerIndex) entity.show = imageryLayers[i].show + if (imageryLayers[i]._objectState) { + if (imageryLayers[i]._showView == 3) { + entity.show = false + } + } } // sdk.viewer.entities.collectionChanged.addEventListener(syncEntities) // sdk.viewer.dataSources.dataSourceAdded.addEventListener(syncDataSources) @@ -61,6 +66,12 @@ async function init(sdk) { JwwStatusSwitch(sdk2, true) } + sdk.entityMap.forEach((item, key) => { + if (item.showView == 2) { + item.showView = 2 + } + }) + } async function on(sdk) { if (sdk2D) { @@ -95,9 +106,10 @@ function off(sdk) { syncObject = {} } sdk.entityMap.forEach((item, key) => { - item.showView = undefined + if (item.showView) { + item.show = item.show + } }) - } async function syncData2(sdk, id, entityId) { @@ -123,10 +135,10 @@ async function syncData2(sdk, id, entityId) { options.heightMode = 0 options.height = 0 } - + if (!that.type || (that.type !== 'tileset' && that.type !== 'bim' && that.type !== 'glb' && that.type !== 'layer')) { - if(that.showView==3) { - options.show=false + if (that.showView == 3) { + options.show = false } let newObject = await new that.constructor(sdk2D, options) newObject.onClick = that.onClick @@ -216,7 +228,14 @@ async function syncData2(sdk, id, entityId) { } let options = syncObject.tools.deepCopyObj(obj.options) if (!obj.type || (obj.type !== 'tileset' && obj.type !== 'bim' && obj.type !== 'glb' && obj.type !== 'layer')) { - let target = await new obj.constructor(sdk2D, options) + if (obj.showView == 3) { + options.show = false + } + let target = await sdk2D.entityMap.get(options.id) + if(target) { + await target.remove() + } + target = await new obj.constructor(sdk2D, options) target.onClick = obj.onClick target.onRightClick = obj.onRightClick target.onMouseMove = obj.onMouseMove @@ -409,11 +428,25 @@ function syncImageryLayerRemoved(layer, index) { sdk2D.viewer.imageryLayers.remove(layer2d) } function syncImageryLayerShownOrHidden(layer, index, state) { + return let layer2d = sdk2D.viewer.imageryLayers._layers[index] + let layer3d = sdk3D.viewer.imageryLayers._layers[index] + console.log('layer2d', layer2d, sdk2D, layer3d) + if (!layer2d) { return } - layer2d.show = state + if (layer3d._objectState) { + if (!layer3d._showView || layer3d._showView == 2) { + layer2d.show = true + } + if (layer3d._showView == 3) { + layer2d.show = false + } + } + else { + layer2d.show = state + } } async function syncPrimitives(primitive) { @@ -543,6 +576,7 @@ function syncViewer() { } + function get2DView() { return sdk2D } diff --git a/src/Global/mouseRightMenu/index.js b/src/Global/mouseRightMenu/index.js index 0fd350e..8b9a223 100644 --- a/src/Global/mouseRightMenu/index.js +++ b/src/Global/mouseRightMenu/index.js @@ -121,6 +121,9 @@ function MouseRightMenu(sdk, status, callBack) { + ${addedMenu} ` _element.appendChild(menuElm) @@ -175,6 +178,7 @@ function MouseRightMenu(sdk, status, callBack) { break case '文本框': object.position = position + key = 'textBox' break } eventListener[sdk.div_id].callBack(key, object) diff --git a/src/Measure/MeasureDistance/index.js b/src/Measure/MeasureDistance/index.js index 7bb3749..52755af 100644 --- a/src/Measure/MeasureDistance/index.js +++ b/src/Measure/MeasureDistance/index.js @@ -91,7 +91,7 @@ class MeasureDistance extends Measure { //暂时固定取20个点 - if (d > 20) {//大于20m时,固定取20个点 + if (d > 2) {//大于20m时,固定取20个点 meters = d / 20 await start(meters) } else if (d < 1) { @@ -106,8 +106,8 @@ class MeasureDistance extends Measure { async sampleHeight(p1, index) { - let p2 = await this.sampleHeightMostDetailed([p1]) - p1.alt = p2[0].height + let height = await this.getClampToHeight(p1, [...this.sdk.viewer.entities.values]) + p1.alt = height return {position: p1, index} } diff --git a/src/Obj/Analysis/Visibility/index.js b/src/Obj/Analysis/Visibility/index.js index a7e44cd..0f115ce 100644 --- a/src/Obj/Analysis/Visibility/index.js +++ b/src/Obj/Analysis/Visibility/index.js @@ -63,11 +63,15 @@ class VisibilityAnalysis extends Tools { that.tip.set_text("左键创建视角终点,右键结束通视分析") if (!that.resultObject.viewPoint) { let pos84 = that.cartesian3Towgs84(cartesian, that.viewer) - let positions = await Cesium.sampleTerrainMostDetailed( - that.sdk.viewer.terrainProvider, - [Cesium.Cartographic.fromDegrees(pos84.lng, pos84.lat)] - ); - if (positions[0].height > pos84.alt) { + let positions + if(that.sdk.viewer.terrainProvider.availability) + { + positions = await Cesium.sampleTerrainMostDetailed( + that.sdk.viewer.terrainProvider, + [Cesium.Cartographic.fromDegrees(pos84.lng, pos84.lat)] + ); + } + if (positions && positions[0].height > pos84.alt) { pos84.alt = positions[0].height } pos84.alt = pos84.alt + that.viewPointHeight diff --git a/src/Obj/Base/BillboardObject/index.js b/src/Obj/Base/BillboardObject/index.js index b637a4f..8ce5099 100644 --- a/src/Obj/Base/BillboardObject/index.js +++ b/src/Obj/Base/BillboardObject/index.js @@ -548,11 +548,11 @@ class BillboardObject extends Base { value: '链接', key: 'link' }, - // { - // name: 'IP摄像头', - // value: 'IP摄像头', - // key: 'camera' - // }, + { + name: 'IP摄像头', + value: 'IP摄像头', + key: 'camera' + }, // { // name: 'ISC摄像头', // value: 'ISC摄像头', @@ -563,16 +563,16 @@ class BillboardObject extends Base { // value: '传感器', // key: 'sensor' // }, - // { - // name: '全景图', - // value: '全景图', - // key: 'vr' - // }, - // { - // name: '物资', - // value: '物资', - // key: 'goods' - // } + { + name: '全景图', + value: '全景图', + key: 'vr' + }, + { + name: '物资', + value: '物资', + key: 'goods' + } ] } diff --git a/src/Obj/Base/CircleDiffuse/index.js b/src/Obj/Base/CircleDiffuse/index.js index d7fe430..36acfa4 100644 --- a/src/Obj/Base/CircleDiffuse/index.js +++ b/src/Obj/Base/CircleDiffuse/index.js @@ -6,7 +6,7 @@ import EventBinding from '../../Element/Dialog/eventBinding'; import richText from "../../Element/richText"; import MouseEvent from '../../../Event/index' import LabelObject from '../LabelObject' -import { syncData } from '../../../Global/MultiViewportMode' +import { syncData, getSdk as get2DSdk } from '../../../Global/MultiViewportMode' import { legp } from '../../Element/datalist'; import { getFontList, getFontFamilyName } from '../../Element/fontSelect' import MouseTip from '../../../MouseTip' @@ -223,10 +223,11 @@ class CircleDiffuse extends Base { set show(v) { if (typeof v === "boolean") { - if (!this.isShowView) { + let sdkD = get2DSdk().sdkD + if (!this.isShowView || !sdkD) { this.options.show = v } - if (!this.showView || this.showView == 3) { + if (!this.showView || this.showView == 3 || !sdkD) { this.entity.show = this.options.show if (this.options.label.show) { this.label.show = this.options.show @@ -442,8 +443,9 @@ class CircleDiffuse extends Base { return this.options.label.show } set labelShow(v) { + let sdkD = get2DSdk().sdkD this.options.label.show = v - if (this.show && (!this.showView || this.showView == 3)) { + if (this.show && (!this.showView || this.showView == 3 || !sdkD)) { this.label.show = v } else { @@ -1336,7 +1338,7 @@ class CircleDiffuse extends Base { } async remove() { - this.label.remove() + this.label && this.label.remove() this.entity && this.sdk.viewer.entities.remove(this.entity) this.entity2 && this.sdk.viewer.entities.remove(this.entity2) this.entity = null diff --git a/src/Obj/Base/GeoJson/index.js b/src/Obj/Base/GeoJson/index.js index 43e4b25..02a0bbe 100644 --- a/src/Obj/Base/GeoJson/index.js +++ b/src/Obj/Base/GeoJson/index.js @@ -8,6 +8,8 @@ import { getHost, getToken } from "../../../on"; import Base from '../index' import Tools from '../../../Tools' +import { syncSplitData } from "../../../Global/SplitScreen"; +import { syncData, getSdk as get2DSdk } from '../../../Global/MultiViewportMode' import { setActiveViewer, closeRotateAround, closeViewFollow} from '../../../Global/global' class GeoJson extends Base { @@ -26,6 +28,7 @@ class GeoJson extends Base { this.primitive = undefined this.positions = [] + this.loading = true } @@ -48,6 +51,27 @@ class GeoJson extends Base { return this.options.show } + // set show(status) { + // let sdkD = get2DSdk().sdkD + // if (!this.isShowView || !sdkD) { + // this.options.show = status + // } + // if (this.entity) { + // if (!this.showView || this.showView == 3 || !sdkD) { + // for (let i = 0; i < this.entity.entities.values.length; i++) { + // this.entity.entities.values[i].show = this.options.show + // } + // } + // else { + // for (let i = 0; i < this.entity.entities.values.length; i++) { + // this.entity.entities.values[i].show = false + // } + // } + // } + // syncData(this.sdk, this.options.id) + // syncSplitData(this.sdk, this.options.id) + // this.isShowView = false + // } set show(status) { this.options.show = status if (this.entity) { @@ -74,6 +98,7 @@ class GeoJson extends Base { }) let json = await rsp.json() this.geojson = json + // this.sdk.addIncetance(this.options.id, this) return GeoJson.addDataToGlobe(this, json.features) } diff --git a/src/Obj/Base/GroundImage/_element.js b/src/Obj/Base/GroundImage/_element.js index 95acf9f..0edeb1e 100644 --- a/src/Obj/Base/GroundImage/_element.js +++ b/src/Obj/Base/GroundImage/_element.js @@ -1,5 +1,5 @@ function html() { - return ` + return `
@@ -7,14 +7,21 @@ function html() { 名称
-
- -
+
+
+ +
+
+ 军标模式 +
+
+
+
旋转角度 @@ -25,7 +32,7 @@ function html() {
-
+
调整大小 @@ -35,6 +42,75 @@ function html() {
+
+
+ 高度模式 +
+
+
+
+ 高度 +
+ + m + +
+
+
+
+ 图标倍数 +
+ + + +
+
+
+
+
+ 视野缩放 + +
+
+ 最近距离 +
+ + m + +
+
+
+ 最远距离 +
+ + m + +
+
+
+

文字设置

+
+
+ 显隐 + +
+
+ 字体选择 +
+
+
+ 文字大小 +
+ + px + +
+
+
+ 文字颜色 +
+
+
` diff --git a/src/Obj/Base/GroundImage/index.js b/src/Obj/Base/GroundImage/index.js index df7f882..cf53684 100644 --- a/src/Obj/Base/GroundImage/index.js +++ b/src/Obj/Base/GroundImage/index.js @@ -4,8 +4,11 @@ import { html } from "./_element"; import EventBinding from '../../Element/Dialog/eventBinding'; import Base from "../index"; import MouseEvent from '../../../Event/index' +import { legp } from '../../Element/datalist' import { syncData } from '../../../Global/MultiViewportMode' +import { getGroundCover } from '../../../Global/global' import MouseTip from '../../../MouseTip' +import { getFontList, getFontFamily, getFontFamilyName } from '../../Element/fontSelect' import { setSplitDirection, syncSplitData, setActiveId } from '../../../Global/SplitScreen' import { setActiveViewer, closeRotateAround, closeViewFollow } from '../../../Global/global' @@ -36,11 +39,31 @@ class GroundImage extends Base { this.options.angle = options.angle || 0 this.options.scale = (options.scale || options.scale === 0) ? options.scale : 1 this.options.position = options.position - this.options.offset = options.offset || { x: 0.5, y: 0.5 } + 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.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 this.entity = { id: this.options.id @@ -48,6 +71,7 @@ class GroundImage extends Base { this._positionEditing = false this.Dialog = _Dialog this._elms = {}; + this._proj = this.sdk.proj this.previous = { position: { ...this.options.position } } @@ -57,6 +81,136 @@ class GroundImage extends Base { this.create() } + get name() { + return this.options.name + } + + set name(v) { + super.name = v + this.options.label.text = this.options.name + this.entity && (this.entity.label.text = this.options.label.text) + } + + get mode() { + return this.options.mode + } + set mode(v) { + this.options.mode = v ? 1 : 0 + 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 + } + } + if (this._DialogObject && this._DialogObject._element && this._DialogObject._element.body) { + let elms = this._DialogObject._element.body.getElementsByClassName('row') + let elms2 = this._DialogObject._element.foot.getElementsByTagName('button') + let elms3 = this._DialogObject._element.foot.getElementsByTagName('h4') + 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 = 'flex' + } + else { + elms[i].style.display = 'none' + } + } + } + for (let i = 0; i < elms2.length; i++) { + let mode = elms2[i].getAttribute('mode') + if (mode !== null) { + if (mode == this.options.mode) { + elms2[i].style.display = 'block' + } + else { + elms2[i].style.display = 'none' + } + } + } + for (let i = 0; i < elms3.length; i++) { + let mode = elms3[i].getAttribute('mode') + if (mode !== null) { + if (mode == this.options.mode) { + elms3[i].style.display = 'block' + } + else { + elms3[i].style.display = 'none' + } + } + } + } + + const img = new Image(); + img.crossOrigin = 'Anonymous'; + img.src = this.replaceHost(this.options.url, this.options.host); + img.onload = () => { + const canvas = document.createElement('canvas'); + const ctx = canvas.getContext('2d'); + + if (this.mode) { + // canvas.width = img.width + // canvas.height = img.height; + // let billboardH = img.height * (128 / img.width) + + // if (this.flipeX) { + // ctx.scale(1, -1); + // ctx.translate(0, -canvas.height) + // } + // if (this.flipeY) { + // ctx.scale(-1, 1); + // ctx.translate(-canvas.width, 0); + // } + // ctx.drawImage(img, 0, 0, img.width, img.height) + // this.entity.billboard.image = canvas + // this.entity.billboard.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) } + 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 } + this.entity.billboard.show = true + this.labelShow && (this.entity.label.show = true) + this.entity.rectangle.show = false + } + else { + // 设置画布大小 + canvas.width = img.width * 2; + canvas.height = img.height * 2; + + // 绘制图像 + if (this.flipeX) { + ctx.scale(1, -1); + ctx.translate(0, -canvas.height) + } + if (this.flipeY) { + ctx.scale(-1, 1); + ctx.translate(-canvas.width, 0); + } + ctx.drawImage(img, img.width - (img.width * this.options.offset.x), img.height - (img.height * this.options.offset.y)); + this.entity.rectangle.material = new Cesium.ImageMaterialProperty({ + image: canvas, + transparent: true + }) + this.entity.billboard.show = false + this.entity.label.show = false + this.entity.rectangle.show = true + } + } + } + get offset() { return this.options.offset } @@ -69,24 +223,52 @@ class GroundImage extends Base { const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); - // 设置画布大小 - canvas.width = img.width * 2; - canvas.height = img.height * 2; + if (this.mode) { + // canvas.width = img.width + // canvas.height = img.height; + // let billboardH = img.height * (128 / img.width) - // 绘制图像 - if (this.flipeX) { - ctx.scale(1, -1); - ctx.translate(0, -canvas.height) + // if (this.flipeX) { + // ctx.scale(1, -1); + // ctx.translate(0, -canvas.height) + // } + // if (this.flipeY) { + // ctx.scale(-1, 1); + // ctx.translate(-canvas.width, 0); + // } + // ctx.drawImage(img, 0, 0, img.width, img.height) + // this.entity.billboard.image = canvas + // this.entity.billboard.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) } + 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 } + this.entity.billboard.show = true + this.labelShow && (this.entity.label.show = true) + this.entity.rectangle.show = false } - if (this.flipeY) { - ctx.scale(-1, 1); - ctx.translate(-canvas.width, 0); + else { + // 设置画布大小 + canvas.width = img.width * 2; + canvas.height = img.height * 2; + + // 绘制图像 + if (this.flipeX) { + ctx.scale(1, -1); + ctx.translate(0, -canvas.height) + } + if (this.flipeY) { + ctx.scale(-1, 1); + ctx.translate(-canvas.width, 0); + } + ctx.drawImage(img, img.width - (img.width * this.options.offset.x), img.height - (img.height * this.options.offset.y)); + this.entity.rectangle.material = new Cesium.ImageMaterialProperty({ + image: canvas, + transparent: true + }) + this.entity.billboard.show = false + this.entity.label.show = false + this.entity.rectangle.show = true } - ctx.drawImage(img, img.width - (img.width * this.options.offset.x), img.height - (img.height * this.options.offset.y)); - this.entity.rectangle.material = new Cesium.ImageMaterialProperty({ - image: canvas, - transparent: true - }) } } @@ -112,6 +294,70 @@ class GroundImage extends Base { }) } + 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 flipeY() { return this.options.flipe.y } @@ -129,28 +375,47 @@ class GroundImage extends Base { const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); - // 设置画布大小 - canvas.width = img.width * 2; - canvas.height = img.height * 2; + if (this.mode) { + // canvas.width = img.width + // canvas.height = img.height; + // let billboardH = img.height * (128 / img.width) + // if (this.flipeX) { + // ctx.scale(1, -1); + // ctx.translate(0, -canvas.height) + // } + // if (this.flipeY) { + // ctx.scale(-1, 1); + // ctx.translate(-canvas.width, 0); + // } + // ctx.drawImage(img, 0, 0, img.width, img.height) + // this.entity.billboard.image = canvas + // this.entity.billboard.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) } + // this.entity.billboard.show = true + // this.entity.rectangle.show = false + } + else { + // 设置画布大小 + canvas.width = img.width * 2; + canvas.height = img.height * 2; - // 绘制图像 - if (this.flipeX) { - ctx.scale(1, -1); - ctx.translate(0, -canvas.height) + // 绘制图像 + if (this.flipeX) { + ctx.scale(1, -1); + ctx.translate(0, -canvas.height) + } + if (this.flipeY) { + ctx.scale(-1, 1); + ctx.translate(-canvas.width, 0); + } + ctx.drawImage(img, img.width - (img.width * this.options.offset.x), img.height - (img.height * this.options.offset.y)); + this.entity.rectangle.material = new Cesium.ImageMaterialProperty({ + image: canvas, + transparent: true + }) + this.entity.billboard.show = false + this.entity.label.show = false + this.entity.rectangle.show = true } - if (this.flipeY) { - ctx.scale(-1, 1); - ctx.translate(-canvas.width, 0); - } - ctx.drawImage(img, img.width - (img.width * this.options.offset.x), img.height - (img.height * this.options.offset.y)); - this.entity && (this.entity.rectangle.material = new Cesium.ImageMaterialProperty({ - image: canvas, - transparent: true - })) - // this.offset = { - // x: Math.abs(this.offset.x - 1), - // y: this.offset.y, - // } } } else { console.error("参数必须为boolean") @@ -173,24 +438,48 @@ class GroundImage extends Base { const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); - // 设置画布大小 - canvas.width = img.width * 2; - canvas.height = img.height * 2; + if (this.mode) { + // canvas.width = img.width + // canvas.height = img.height; + // let billboardH = img.height * (128 / img.width) + // if (this.flipeX) { + // ctx.scale(1, -1); + // ctx.translate(0, -canvas.height) + // } + // if (this.flipeY) { + // ctx.scale(-1, 1); + // ctx.translate(-canvas.width, 0); + // } + // ctx.drawImage(img, 0, 0, img.width, img.height) + // this.entity.billboard.image = canvas + // this.entity.billboard.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) } + // this.entity.billboard.show = true + // this.entity.rectangle.show = false + } + else { + // 设置画布大小 + canvas.width = img.width * 2; + canvas.height = img.height * 2; - // 绘制图像 - if (this.flipeX) { - ctx.scale(1, -1); - ctx.translate(0, -canvas.height) + // 绘制图像 + if (this.flipeX) { + ctx.scale(1, -1); + ctx.translate(0, -canvas.height) + } + if (this.flipeY) { + ctx.scale(-1, 1); + ctx.translate(-canvas.width, 0); + } + ctx.drawImage(img, img.width - (img.width * this.options.offset.x), img.height - (img.height * this.options.offset.y)); + this.entity.rectangle.material = new Cesium.ImageMaterialProperty({ + image: canvas, + transparent: true + }) + this.entity.billboard.show = false + this.entity.label.show = false + this.entity.rectangle.show = true } - if (this.flipeY) { - ctx.scale(-1, 1); - ctx.translate(-canvas.width, 0); - } - ctx.drawImage(img, img.width - (img.width * this.options.offset.x), img.height - (img.height * this.options.offset.y)); - this.entity.rectangle.material = new Cesium.ImageMaterialProperty({ - image: canvas, - transparent: true - }) + // this.offset = { // x: this.offset.x, // y: Math.abs(this.offset.y - 1), @@ -201,6 +490,265 @@ class GroundImage extends Base { } } + 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 coordinate() { + return this.options.coordinate + } + set coordinate(v) { + this.options.coordinate = v + // let position = this._proj.convert( + // [ + // { + // x: this.options.position.lng, + // y: this.options.position.lat, + // z: this.options.position.alt + // } + // ], + // 'EPSG:4326', + // v + // ).points + // if ( + // this._DialogObject && + // this._DialogObject._element && + // this._DialogObject._element.content && + // position[0] + // ) { + // this._DialogObject._element.content.getElementsByClassName( + // 'convert-x' + // )[0].value = position[0].x + // this._DialogObject._element.content.getElementsByClassName( + // 'convert-y' + // )[0].value = position[0].y + // this._DialogObject._element.content.getElementsByClassName( + // 'convert-z' + // )[0].value = position[0].z + // } + // this._elms.coordinate && + // this._elms.coordinate.forEach(item => { + // item.value = v + // }) + } + + get position() { + return this.options.position + } + + set position(v) { + this.options.position = v + + this.coordinate = this.options.coordinate + + if (this._textToCenter) { + let point = turf.point([this.options.position.lng, this.options.position.lat]) + let targetPoint = turf.destination(point, this._textToCenter.distance, this._textToCenter.angle, { units: 'kilometers' }).geometry.coordinates + this.getClampToHeight({ lng: targetPoint[0], lat: targetPoint[1] }).then((height) => { + let textPosition = [targetPoint[0], targetPoint[1], height] + this.options.text.position = { lng: targetPoint[0], lat: targetPoint[1], alt: height } + this.text && (this.text.position = textPosition) + }) + } + + this._elms.lng && + this._elms.lng.forEach(item => { + item.value = this.options.position.lng + }) + this._elms.lat && + this._elms.lat.forEach(item => { + item.value = this.options.position.lat + }) + + 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) + ) + this._elms.alt && + this._elms.alt.forEach(item => { + item.value = this.options.position.alt + }) + }) + } else { + heightElm.value = Number( + Number(this.options.position.alt).toFixed(2) + ) + this._elms.alt && + this._elms.alt.forEach(item => { + item.value = this.options.position.alt + }) + } + break + case '依附地表': + case '依附地表': + break + case '依附模型': + this.updateHeight() + break + } + } + } + } + + 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 + }) + } + } + async create() { // let gap = Math.abs(Math.cos(Math.PI/180 * this.options.position.lat)) * (0.0001*this.options.scale) // let fromDegreesArray = [ @@ -209,6 +757,15 @@ class GroundImage extends Base { // this.options.position.lng + 0.05, this.options.position.lat + 0.05, // this.options.position.lng - 0.05, this.options.position.lat + 0.05, // ] + let _this = this + let heightMode + let font = getFontFamily(this.labelFontFamily) || 'Helvetica' + switch (this.options.heightMode) { + case 2: + case '2': + heightMode = Cesium.HeightReference.CLAMP_TO_GROUND + break + } let response = await fetch(this.replaceHost(this.options.url, this.options.host), { method: 'get', headers: { @@ -225,6 +782,13 @@ class GroundImage extends Base { img.onload = () => { const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); + const canvas2 = document.createElement('canvas'); + const ctx2 = canvas2.getContext('2d'); + let width = img.width + let height = img.height + canvas2.width = width + canvas2.height = height; + ctx2.drawImage(img, 0, 0, width, height) // 设置画布大小 canvas.width = img.width * 2; @@ -240,10 +804,65 @@ class GroundImage extends Base { } ctx.drawImage(img, img.width - (img.width * this.options.offset.x), img.height - (img.height * this.options.offset.y)); + + let billboardH = height * (128 / width) + this.entity = this.sdk.viewer.entities.add({ id: this.options.id, show: this.options.show, + position: new Cesium.CallbackProperty(() => { + return Cesium.Cartesian3.fromDegrees( + this.options.position.lng, + this.options.position.lat, + this.options.position.alt || 0 + ) + }), + billboard: { + show: this.mode ? true : false, + image: canvas2, + 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: new Cesium.CallbackProperty(function () { + if (_this.options.show) { + return new Cesium.Cartesian2( + 0, + -billboardH * _this.billboardScale - + _this.options.label.fontSize / 2 - + 5 + ) + } else { + return new Cesium.Cartesian2( + 0, + -_this.options.label.fontSize / 2 - 5 + ) + } + }, false), + outlineColor: Cesium.Color.BLACK, + outlineWidth: 1, + style: Cesium.LabelStyle.FILL_AND_OUTLINE + }, rectangle: { + show: this.mode ? false : true, coordinates: new Cesium.CallbackProperty(() => { let gap = Math.abs(Math.cos(Math.PI / 180 * this.options.position.lat)) * (0.0001 * this.options.scale) let offset = { @@ -293,6 +912,8 @@ class GroundImage extends Base { }, false) }, }) + + this.renewPoint() if (this.sdk.viewer._element.className === 'cesium-viewer 2d') { this.entity.rectangle.height = 0 } @@ -340,8 +961,8 @@ class GroundImage extends Base { 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) + // syncData(this.sdk, this.options.id) + // syncSplitData(this.sdk, this.options.id) }, resetCallBack: () => { this.reset() @@ -357,7 +978,7 @@ class GroundImage extends Base { // color: "color('rgba(255,255,255," + this.newData.transparency + ")')", // show: true, // }); - + if (anchorSetDialogObject && anchorSetDialogObject.close) { anchorSetDialogObject.close() } @@ -513,6 +1134,440 @@ class GroundImage extends Base { } } + // let coordinateData = [] + // this.epsg_map.forEach((value, key) => { + // coordinateData.push({ + // name: `${value.name}(${value.epsg})`, + // value: key + // }) + // }) + // let coordinateDataLegpObject = legp( + // this._DialogObject._element.content.getElementsByClassName( + // 'coordinate-select-box' + // )[0], + // '.coordinate-select' + // ) + // if (coordinateDataLegpObject) { + // coordinateDataLegpObject.legp_search(coordinateData) + // let coordinateDataLegpElm = this._DialogObject._element.content + // .getElementsByClassName('coordinate-select')[0] + // .getElementsByTagName('input')[0] + // if (!this.coordinate) { + // this.coordinate = coordinateData[0].value + // } else { + // this.coordinate = this.coordinate + // } + // coordinateDataLegpElm.value = this.coordinate + // for (let i = 0; i < coordinateData.length; i++) { + // if (coordinateData[i].value === coordinateData.value) { + // coordinateDataLegpObject.legp_searchActive( + // coordinateData[i].value + // ) + // break + // } + // } + // coordinateDataLegpElm.addEventListener('input', () => { + // for (let i = 0; i < coordinateData.length; i++) { + // if (coordinateData[i].value === coordinateDataLegpElm.value) { + // this.coordinate = coordinateData[i].value + // break + // } + // } + // }) + // } + + let elms = contentElm.getElementsByClassName('row') + let elms2 = contentElm.getElementsByTagName('h4') + 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 = 'flex' + } + else { + elms[i].style.display = 'none' + } + } + } + for (let i = 0; i < elms2.length; i++) { + let mode = elms2[i].getAttribute('mode') + if (mode !== null) { + if (mode == this.options.mode) { + elms2[i].style.display = 'block' + } + else { + elms2[i].style.display = 'none' + } + } + } + + // let lng = contentElm.getElementsByClassName("lng")[0] + // let lat = contentElm.getElementsByClassName("lat")[0] + // let alt = contentElm.getElementsByClassName("alt")[0] + // lng.value = this.options.position.lng + // lat.value = this.options.position.lat + // alt.value = this.options.position.alt + // this._elms.lng = [lng] + // this._elms.lat = [lat] + // this._elms.alt = [alt] + // lng.addEventListener('blur', (e) => { + // let value = e.target.value + // if (e.target.value || (e.target.dataset.null !== 'undefined' && e.target.dataset.null !== '' && !Boolean(e.target.dataset.null))) { + // 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) + // } + // if ((e.target.dataset.min) && value < Number(e.target.dataset.min)) { + // value = Number(e.target.dataset.min) + // } + // } + // // this.position = { + // // lng: value, + // // lat: this.position.lat, + // // alt: this.position.alt + // // } + // this.options.position.lng = value + // this.coordinate = this.options.coordinate + // }) + // lat.addEventListener('blur', (e) => { + // let value = e.target.value + // if (e.target.value || (e.target.dataset.null !== 'undefined' && e.target.dataset.null !== '' && !Boolean(e.target.dataset.null))) { + // 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) + // } + // if ((e.target.dataset.min) && value < Number(e.target.dataset.min)) { + // value = Number(e.target.dataset.min) + // } + // } + // // this.position = { + // // lng: this.position.lng, + // // lat: value, + // // alt: this.position.alt + // // } + // this.options.position.lat = value + // this.coordinate = this.options.coordinate + // }) + // alt.addEventListener('blur', (e) => { + // let value = e.target.value + // if (e.target.value || (e.target.dataset.null !== 'undefined' && e.target.dataset.null !== '' && !Boolean(e.target.dataset.null))) { + // 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) + // } + // if ((e.target.dataset.min) && value < Number(e.target.dataset.min)) { + // value = Number(e.target.dataset.min) + // } + // } + // // this.position = { + // // lng: this.position.lng, + // // lat: this.position.lat, + // // alt: value + // // } + // this.options.position.alt = value + // this.coordinate = this.options.coordinate + // }) + + let colorPicker = 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)' + } //点击清空按钮事件回调 + }) + this._elms.labelColor = [colorPicker] + + setTimeout(async () => { + let flipeOverXBtn = this._DialogObject._element.foot.getElementsByClassName('flipe-over-x')[0] + let flipeOverYBtn = this._DialogObject._element.foot.getElementsByClassName('flipe-over-y')[0] + flipeOverXBtn.setAttribute('mode', 0) + flipeOverYBtn.setAttribute('mode', 0) + if (this.options.mode) { + flipeOverXBtn.style.display = 'none' + flipeOverYBtn.style.display = 'none' + } + else { + flipeOverXBtn.style.display = 'block' + flipeOverYBtn.style.display = 'block' + } + 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); } else { if (this._DialogObject && this._DialogObject.remove) { @@ -610,12 +1665,7 @@ class GroundImage extends Base { position: { ...this.options.position } } } - else { - this.options.position.lng = this.previous.position.lng - this.options.position.lat = this.previous.position.lat - this.options.position.alt = this.previous.position.alt - } - + this.position = { ...this.previous.position } } } @@ -727,6 +1777,167 @@ class GroundImage extends Base { } } + 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 + } + } + } + } + + // if (!this.entity.values) { + // this.entity.position = Cesium.Cartesian3.fromDegrees( + // this.options.position.lng, + // this.options.position.lat, + // this.options.position.alt + // ) + // } + } + + renewPoint() { + if (!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 } + // this.entity.billboard.pixelOffset = { x: -width * this.billboardScale * (this.flipeY ? (1 - this.options.offset.x) : this.options.offset.x), y: -height * this.billboardScale * (this.flipeX ? (1 - this.options.offset.y) : this.options.offset.y) } + } + } + reset() { if (!this.entity) { return @@ -739,6 +1950,10 @@ class GroundImage extends Base { this.flipeX = this.options.flipe.x this.flipeY = this.options.flipe.y this.show = this.options.show + this.mode = this.options.mode + this.heightMode = this.options.heightMode + this.billboardScale = this.options.billboard.scale + this.labelShow = this.options.label.show } async remove() { diff --git a/src/Obj/Base/GroundSvg/_element.js b/src/Obj/Base/GroundSvg/_element.js index 1f16498..1766d91 100644 --- a/src/Obj/Base/GroundSvg/_element.js +++ b/src/Obj/Base/GroundSvg/_element.js @@ -54,7 +54,7 @@ function html(that) {
文字内容 - +