| @@ -50,10 +50,22 @@ class MouseEvent extends Event { | |||
| let scene = this._viewer.scene | |||
| let target = scene.pick(position) | |||
| let cartesian = undefined | |||
| let surfaceCartesian = undefined | |||
| let wgs84Position = undefined | |||
| let wgs84SurfacePosition = undefined | |||
| if (scene.pickPositionSupported) { | |||
| 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 ( | |||
| scene.mode === Cesium.SceneMode.SCENE3D && | |||
| !(this._viewer.terrainProvider instanceof Cesium.EllipsoidTerrainProvider) | |||
| @@ -66,11 +78,24 @@ class MouseEvent extends Event { | |||
| 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 { | |||
| target: target, | |||
| windowPosition: position, | |||
| position: cartesian, | |||
| surfacePosition: surfaceCartesian | |||
| wgs84Position: wgs84Position, | |||
| surfacePosition: surfaceCartesian, | |||
| wgs84SurfacePosition: wgs84SurfacePosition | |||
| } | |||
| } | |||
| @@ -13,11 +13,20 @@ class Parse { | |||
| */ | |||
| static parsePosition(position) { | |||
| let result = new Position() | |||
| if (!position) { | |||
| return result | |||
| } | |||
| if (typeof position === 'string') { | |||
| result = Position.fromCoordString(position) | |||
| result = Position.fromString(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 | |||
| } | |||
| return result | |||
| @@ -36,12 +45,18 @@ class Parse { | |||
| positions = positions.split(';') | |||
| } | |||
| 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 | |||
| } else if (typeof item === 'string' && item) { | |||
| return Position.fromCoordString(item) | |||
| } | |||
| }) | |||
| } | |||
| @@ -123,6 +123,21 @@ class Position { | |||
| 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 | |||
| @@ -155,6 +170,22 @@ class 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 | |||
| * @param valStr | |||
| @@ -182,7 +213,7 @@ class Position { | |||
| static fromCoordString(str) { | |||
| let position = new Position() | |||
| if (str && typeof str === 'string') { | |||
| position = this.fromCoordArray(str.split(',')) | |||
| position = this.fromArray(str.split(',')) | |||
| } | |||
| return position | |||
| } | |||
| @@ -17,7 +17,9 @@ class ContextMenu extends Widget { | |||
| this._handler = undefined | |||
| this._overlay = undefined | |||
| this._position = undefined | |||
| this._wgs84Position = undefined | |||
| this._surfacePosition = undefined | |||
| this._wgs84SurfacePosition = undefined | |||
| this._windowPosition = undefined | |||
| this._config = {} | |||
| this._defaultMenu = [ | |||
| @@ -139,6 +141,16 @@ class ContextMenu extends Widget { | |||
| if (scene.pickPositionSupported) { | |||
| 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) { | |||
| let ray = scene.camera.getPickRay(movement.position) | |||
| this._surfacePosition = scene.globe.pick(ray, scene) | |||
| @@ -148,6 +160,19 @@ class ContextMenu extends Widget { | |||
| 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 | |||
| if (target && target.id && target.id instanceof Cesium.Entity) { | |||
| let layer = this._viewer | |||
| @@ -224,9 +249,11 @@ class ContextMenu extends Widget { | |||
| if (method) { | |||
| a.onclick = () => { | |||
| method.call(context, { | |||
| position: self._position, | |||
| windowPosition: self._windowPosition, | |||
| position: self._position, | |||
| wgs84Position: self._wgs84Position, | |||
| surfacePosition: self._surfacePosition, | |||
| wgs84SurfacePosition: self._wgs84SurfacePosition, | |||
| overlay: self._overlay | |||
| }) | |||
| self.hide() | |||