| let scene = this._viewer.scene | let scene = this._viewer.scene | ||||
| let target = scene.pick(position) | let target = scene.pick(position) | ||||
| let cartesian = undefined | let cartesian = undefined | ||||
| let surfaceCartesian = undefined | |||||
| let wgs84Position = undefined | |||||
| let wgs84SurfacePosition = undefined | |||||
| if (scene.pickPositionSupported) { | if (scene.pickPositionSupported) { | ||||
| cartesian = scene.pickPosition(position) | cartesian = scene.pickPosition(position) | ||||
| } | } | ||||
| let surfaceCartesian | |||||
| if (cartesian) { | |||||
| let c = Cesium.Ellipsoid.WGS84.cartesianToCartographic(cartesian) | |||||
| if (c) { | |||||
| wgs84Position = { | |||||
| lng: Cesium.Math.toDegrees(c.longitude), | |||||
| lat: Cesium.Math.toDegrees(c.latitude), | |||||
| alt: c.height | |||||
| } | |||||
| } | |||||
| } | |||||
| if ( | if ( | ||||
| scene.mode === Cesium.SceneMode.SCENE3D && | scene.mode === Cesium.SceneMode.SCENE3D && | ||||
| !(this._viewer.terrainProvider instanceof Cesium.EllipsoidTerrainProvider) | !(this._viewer.terrainProvider instanceof Cesium.EllipsoidTerrainProvider) | ||||
| Cesium.Ellipsoid.WGS84 | Cesium.Ellipsoid.WGS84 | ||||
| ) | ) | ||||
| } | } | ||||
| if (surfaceCartesian) { | |||||
| let c = Cesium.Ellipsoid.WGS84.cartesianToCartographic(surfaceCartesian) | |||||
| if (c) { | |||||
| wgs84SurfacePosition = { | |||||
| lng: Cesium.Math.toDegrees(c.longitude), | |||||
| lat: Cesium.Math.toDegrees(c.latitude), | |||||
| alt: c.height | |||||
| } | |||||
| } | |||||
| } | |||||
| return { | return { | ||||
| target: target, | target: target, | ||||
| windowPosition: position, | windowPosition: position, | ||||
| position: cartesian, | position: cartesian, | ||||
| surfacePosition: surfaceCartesian | |||||
| wgs84Position: wgs84Position, | |||||
| surfacePosition: surfaceCartesian, | |||||
| wgs84SurfacePosition: wgs84SurfacePosition | |||||
| } | } | ||||
| } | } | ||||
| */ | */ | ||||
| static parsePosition(position) { | static parsePosition(position) { | ||||
| let result = new Position() | let result = new Position() | ||||
| if (!position) { | |||||
| return result | |||||
| } | |||||
| if (typeof position === 'string') { | if (typeof position === 'string') { | ||||
| result = Position.fromCoordString(position) | |||||
| result = Position.fromString(position) | |||||
| } else if (Array.isArray(position)) { | } else if (Array.isArray(position)) { | ||||
| result = Position.fromCoordArray(position) | |||||
| } else if (position instanceof Position) { | |||||
| result = Position.fromArray(position) | |||||
| } else if ( | |||||
| !(Object(position) instanceof Position) && | |||||
| Object(position).hasOwnProperty('lng') && | |||||
| Object(position).hasOwnProperty('lat') | |||||
| ) { | |||||
| result = Position.fromObject(position) | |||||
| } else if (Object(position) instanceof Position) { | |||||
| result = position | result = position | ||||
| } | } | ||||
| return result | return result | ||||
| positions = positions.split(';') | positions = positions.split(';') | ||||
| } | } | ||||
| return positions.map(item => { | return positions.map(item => { | ||||
| if (Array.isArray(item) && item.length) { | |||||
| return Position.fromCoordArray(item) | |||||
| } else if (item instanceof Position) { | |||||
| if (typeof item === 'string') { | |||||
| return Position.fromString(item) | |||||
| } else if (Array.isArray(item)) { | |||||
| return Position.fromArray(item) | |||||
| } else if ( | |||||
| !(Object(item) instanceof Position) && | |||||
| Object(item).hasOwnProperty('lng') && | |||||
| Object(item).hasOwnProperty('lat') | |||||
| ) { | |||||
| return Position.fromObject(item) | |||||
| } else if (Object(item) instanceof Position) { | |||||
| return item | return item | ||||
| } else if (typeof item === 'string' && item) { | |||||
| return Position.fromCoordString(item) | |||||
| } | } | ||||
| }) | }) | ||||
| } | } |
| return `${this.lng},${this.lat},${this.alt},${this.heading},${this.pitch},${this.roll}` | return `${this.lng},${this.lat},${this.alt},${this.heading},${this.pitch},${this.roll}` | ||||
| } | } | ||||
| /** | |||||
| * | |||||
| * @returns {{lng, heading, alt, roll, pitch, lat}} | |||||
| */ | |||||
| toObject() { | |||||
| return { | |||||
| lng: this.lng, | |||||
| lat: this.lat, | |||||
| alt: this.alt, | |||||
| heading: this.heading, | |||||
| pitch: this.pitch, | |||||
| roll: this.roll | |||||
| } | |||||
| } | |||||
| /** | /** | ||||
| * | * | ||||
| * @param arr | * @param arr | ||||
| return position | return position | ||||
| } | } | ||||
| /** | |||||
| * | |||||
| * @param obj | |||||
| * @returns {Position} | |||||
| */ | |||||
| static fromObject(obj) { | |||||
| return new Position( | |||||
| obj.lng, | |||||
| obj.lat, | |||||
| obj.alt, | |||||
| obj.heading, | |||||
| obj.pitch, | |||||
| obj.roll | |||||
| ) | |||||
| } | |||||
| /** | /** | ||||
| * Deserialize | * Deserialize | ||||
| * @param valStr | * @param valStr | ||||
| static fromCoordString(str) { | static fromCoordString(str) { | ||||
| let position = new Position() | let position = new Position() | ||||
| if (str && typeof str === 'string') { | if (str && typeof str === 'string') { | ||||
| position = this.fromCoordArray(str.split(',')) | |||||
| position = this.fromArray(str.split(',')) | |||||
| } | } | ||||
| return position | return position | ||||
| } | } |
| this._handler = undefined | this._handler = undefined | ||||
| this._overlay = undefined | this._overlay = undefined | ||||
| this._position = undefined | this._position = undefined | ||||
| this._wgs84Position = undefined | |||||
| this._surfacePosition = undefined | this._surfacePosition = undefined | ||||
| this._wgs84SurfacePosition = undefined | |||||
| this._windowPosition = undefined | this._windowPosition = undefined | ||||
| this._config = {} | this._config = {} | ||||
| this._defaultMenu = [ | this._defaultMenu = [ | ||||
| if (scene.pickPositionSupported) { | if (scene.pickPositionSupported) { | ||||
| this._position = scene.pickPosition(movement.position) | this._position = scene.pickPosition(movement.position) | ||||
| } | } | ||||
| if (this._position) { | |||||
| let c = Cesium.Ellipsoid.WGS84.cartesianToCartographic(this._position) | |||||
| if (c) { | |||||
| this._wgs84Position = { | |||||
| lng: Cesium.Math.toDegrees(c.longitude), | |||||
| lat: Cesium.Math.toDegrees(c.latitude), | |||||
| alt: c.height | |||||
| } | |||||
| } | |||||
| } | |||||
| if (scene.mode === Cesium.SceneMode.SCENE3D) { | if (scene.mode === Cesium.SceneMode.SCENE3D) { | ||||
| let ray = scene.camera.getPickRay(movement.position) | let ray = scene.camera.getPickRay(movement.position) | ||||
| this._surfacePosition = scene.globe.pick(ray, scene) | this._surfacePosition = scene.globe.pick(ray, scene) | ||||
| Cesium.Ellipsoid.WGS84 | Cesium.Ellipsoid.WGS84 | ||||
| ) | ) | ||||
| } | } | ||||
| if (this._surfacePosition) { | |||||
| let c = Cesium.Ellipsoid.WGS84.cartesianToCartographic( | |||||
| this._surfacePosition | |||||
| ) | |||||
| if (c) { | |||||
| this._wgs84SurfacePosition = { | |||||
| lng: Cesium.Math.toDegrees(c.longitude), | |||||
| lat: Cesium.Math.toDegrees(c.latitude), | |||||
| alt: c.height | |||||
| } | |||||
| } | |||||
| } | |||||
| // for Entity | // for Entity | ||||
| if (target && target.id && target.id instanceof Cesium.Entity) { | if (target && target.id && target.id instanceof Cesium.Entity) { | ||||
| let layer = this._viewer | let layer = this._viewer | ||||
| if (method) { | if (method) { | ||||
| a.onclick = () => { | a.onclick = () => { | ||||
| method.call(context, { | method.call(context, { | ||||
| position: self._position, | |||||
| windowPosition: self._windowPosition, | windowPosition: self._windowPosition, | ||||
| position: self._position, | |||||
| wgs84Position: self._wgs84Position, | |||||
| surfacePosition: self._surfacePosition, | surfacePosition: self._surfacePosition, | ||||
| wgs84SurfacePosition: self._wgs84SurfacePosition, | |||||
| overlay: self._overlay | overlay: self._overlay | ||||
| }) | }) | ||||
| self.hide() | self.hide() |