文本框添加flyto定位方法
This commit is contained in:
@ -2,6 +2,7 @@
|
|||||||
* 文本框
|
* 文本框
|
||||||
*/
|
*/
|
||||||
import Base from "../index";
|
import Base from "../index";
|
||||||
|
import { setActiveViewer, closeRotateAround, closeViewFollow } from '../../../Global/global'
|
||||||
class TextBox extends Base {
|
class TextBox extends Base {
|
||||||
constructor(sdk, options = {}) {
|
constructor(sdk, options = {}) {
|
||||||
// this.sdk = { ...sdk }
|
// this.sdk = { ...sdk }
|
||||||
@ -39,10 +40,12 @@ class TextBox extends Base {
|
|||||||
const position = Cesium.SceneTransforms.wgs84ToWindowCoordinates(
|
const position = Cesium.SceneTransforms.wgs84ToWindowCoordinates(
|
||||||
viewer.scene, posi
|
viewer.scene, posi
|
||||||
);
|
);
|
||||||
let width = dom.clientWidth * 1
|
if (position) {
|
||||||
let height = dom.clientHeight * 1
|
let width = dom.clientWidth * 1
|
||||||
dom.style.left = `${position.x - width / 2}px`;
|
let height = dom.clientHeight * 1
|
||||||
dom.style.top = `${position.y - height}px`;
|
dom.style.left = `${position.x - width / 2}px`;
|
||||||
|
dom.style.top = `${position.y - height}px`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
viewer.scene.postRender.addEventListener(that.handler);
|
viewer.scene.postRender.addEventListener(that.handler);
|
||||||
that.textDom = dom
|
that.textDom = dom
|
||||||
@ -68,10 +71,12 @@ class TextBox extends Base {
|
|||||||
const position = Cesium.SceneTransforms.wgs84ToWindowCoordinates(
|
const position = Cesium.SceneTransforms.wgs84ToWindowCoordinates(
|
||||||
that.sdk.viewer.scene, posi
|
that.sdk.viewer.scene, posi
|
||||||
);
|
);
|
||||||
let width = that.textDom.clientWidth * 1
|
if (position) {
|
||||||
let height = that.textDom.clientHeight * 1
|
let width = that.textDom.clientWidth * 1
|
||||||
that.textDom.style.left = `${position.x - width / 2}px`;
|
let height = that.textDom.clientHeight * 1
|
||||||
that.textDom.style.top = `${position.y - height}px`;
|
that.textDom.style.left = `${position.x - width / 2}px`;
|
||||||
|
that.textDom.style.top = `${position.y - height}px`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
that.sdk.viewer.scene.postRender.addEventListener(that.handler);
|
that.sdk.viewer.scene.postRender.addEventListener(that.handler);
|
||||||
}
|
}
|
||||||
@ -92,6 +97,80 @@ class TextBox extends Base {
|
|||||||
set positions(v) {
|
set positions(v) {
|
||||||
this.options.positions = v
|
this.options.positions = v
|
||||||
}
|
}
|
||||||
|
async flyTo(options = {}) {
|
||||||
|
setActiveViewer(0)
|
||||||
|
closeRotateAround(this.sdk)
|
||||||
|
closeViewFollow(this.sdk)
|
||||||
|
|
||||||
|
if (this.options.customView && this.options.customView.relativePosition && this.options.customView.orientation) {
|
||||||
|
let orientation = {
|
||||||
|
heading: Cesium.Math.toRadians(this.options.customView.orientation.heading || 0.0),
|
||||||
|
pitch: Cesium.Math.toRadians(this.options.customView.orientation.pitch || -60.0),
|
||||||
|
roll: Cesium.Math.toRadians(this.options.customView.orientation.roll || 0.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
let lng = this.options.customView.relativePosition.lng
|
||||||
|
let lat = this.options.customView.relativePosition.lat
|
||||||
|
let alt = this.options.customView.relativePosition.alt
|
||||||
|
let destination = Cesium.Cartesian3.fromDegrees(lng, lat, alt)
|
||||||
|
|
||||||
|
let position = { lng: 0, lat: 0 }
|
||||||
|
if (this.options.position) {
|
||||||
|
position = { ...this.options.position }
|
||||||
|
}
|
||||||
|
else if (this.options.positions) {
|
||||||
|
position = { ...this.options.positions[0] }
|
||||||
|
}
|
||||||
|
else if (this.options.center) {
|
||||||
|
position = { ...this.options.center }
|
||||||
|
}
|
||||||
|
else if (this.options.start) {
|
||||||
|
position = { ...this.options.start }
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (this.options.hasOwnProperty('lng')) {
|
||||||
|
position.lng = this.options.lng
|
||||||
|
}
|
||||||
|
if (this.options.hasOwnProperty('lat')) {
|
||||||
|
position.lat = this.options.lat
|
||||||
|
}
|
||||||
|
if (this.options.hasOwnProperty('alt')) {
|
||||||
|
position.alt = this.options.alt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 如果没有高度值,则获取紧贴高度计算
|
||||||
|
// if (!position.hasOwnProperty('alt')) {
|
||||||
|
// position.alt = await this.getClampToHeight(position)
|
||||||
|
// }
|
||||||
|
lng = this.options.customView.relativePosition.lng + position.lng
|
||||||
|
lat = this.options.customView.relativePosition.lat + position.lat
|
||||||
|
alt = this.options.customView.relativePosition.alt + position.alt
|
||||||
|
destination = Cesium.Cartesian3.fromDegrees(lng, lat, alt)
|
||||||
|
this.sdk.viewer.camera.flyTo({
|
||||||
|
destination: destination,
|
||||||
|
orientation: orientation
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let positionArray = []
|
||||||
|
let a = Cesium.Cartesian3.fromDegrees(
|
||||||
|
this.positions.lng,
|
||||||
|
this.positions.lat,
|
||||||
|
this.positions.alt
|
||||||
|
)
|
||||||
|
positionArray.push(a.x, a.y, a.z)
|
||||||
|
|
||||||
|
let BoundingSphere = Cesium.BoundingSphere.fromVertices(positionArray)
|
||||||
|
this.viewer.camera.flyToBoundingSphere(BoundingSphere, {
|
||||||
|
offset: {
|
||||||
|
heading: Cesium.Math.toRadians(0.0),
|
||||||
|
pitch: Cesium.Math.toRadians(-20.0),
|
||||||
|
roll: Cesium.Math.toRadians(0.0)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async remove() {
|
async remove() {
|
||||||
if (this.handler) {
|
if (this.handler) {
|
||||||
|
Reference in New Issue
Block a user