Ver código fonte

坐标转换

DESKTOP-CRQ4N2U\jintian 1 ano atrás
pai
commit
6c5277c5bc
1 arquivos alterados com 88 adições e 0 exclusões
  1. 88 0
      src/jtMap3d/Widgets/common/CoordTransform.js

+ 88 - 0
src/jtMap3d/Widgets/common/CoordTransform.js

@@ -328,6 +328,94 @@ class CoordTransform {
 		let _double = parseFloat(DMS.degrees) + parseFloat(DMS.minutes) / 60 + parseFloat(DMS.seconds) / 3600;
 		return parseFloat(_double).toFixed(6);
 	}
+	
+	/**
+	 * 世界坐标转换为经纬度坐标
+	 * @ignore 生成方法时不对外公开
+	 * @param {Cesium.Cartesian3} position 点
+	 */
+	static _cartesian3ToGeo(position) {
+		let g = Cesium.Ellipsoid.WGS84.cartesianToCartographic(position);
+		return {
+			longitude: Cesium.Math.toDegrees(g.longitude),
+			latitude: Cesium.Math.toDegrees(g.latitude),
+			height: g.height,
+		}
+	}
+	
+	/**
+	 * 弧度转度
+	 * @ignore
+	 * @param {Number} arc 弧度
+	 * @return {Number} 角度
+	 */
+	static _arcToDegree(arc) {
+		return arc / Math.PI * 180;
+	}
+	
+	/**
+	 * 根据地形或实景或模型检测当前屏幕位置的经纬度及高度
+	 * @ignore
+	 * @param {JSON} screenPoint 屏幕坐标
+	 * @param {Number} screenPoint.x 屏幕坐标x
+	 * @param {Number} screenPoint.y 屏幕坐标y
+	 * @return {JSON} 位置信息{lng,lat,height}
+	 */
+	static _getScreenClickPositionAndHeight(viewer,screenPoint) {
+		this._viewer=viewer;
+		
+		var lng = undefined,
+			lat = undefined,
+			height = undefined;
+	
+		/* 从相机位置到 windowPosition 处的像素创建射线在世界坐标系中 */
+		var ray = this._viewer.scene.camera.getPickRay(screenPoint);
+		/* 找到射线与渲染的地球表面之间的交点 */
+		var position = this._viewer.scene.globe.pick(ray, this._viewer.scene);
+		/* 获取地理位置的制图表达 */
+		var cartographic = Cesium.Ellipsoid.WGS84.cartesianToCartographic(position);
+	
+		/* 查询屏幕位置的要素 */
+		var feature = this._viewer.scene.pick(screenPoint);
+		if (feature == undefined) {
+			lng = this._arcToDegree(cartographic.longitude);
+			lat = this._arcToDegree(cartographic.latitude);
+			height = cartographic.height;
+		} else {
+			var cartesian = this._viewer.scene.pickPosition(screenPoint);
+			if (Cesium.defined(cartesian)) {
+				var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
+				lng = this._arcToDegree(cartographic.longitude);
+				lat = this._arcToDegree(cartographic.latitude);
+				height = cartographic.height;
+			}
+		}
+		/* 返回结果 */
+		return {
+			lng: lng,
+			lat: lat,
+			height: height,
+		}
+	}
+	
+	/**
+	 * 屏幕位置转换为经纬度位置及空间位置
+	 * @ignore
+	 * @param {Object} viewer 三维场景
+	 * @param {Cesium.Cartesian2} screenPosition 屏幕位置
+	 * @return {JSON} 经纬度位置及空间位置
+	 */
+	static _transfromFromScreenPoint(viewer,screenPosition) {
+		/* 根据屏幕位置获取经度、纬度和高度信息 */
+		let location = this._getScreenClickPositionAndHeight(viewer,screenPosition);
+		/* 经纬度位置转换为三维坐标 */
+		var cartesian = Cesium.Cartesian3.fromDegrees(location.lng, location.lat, location.height);
+		/* 返回 */
+		return {
+			gLocation: location,
+			sLocation: cartesian,
+		}
+	}
 }
 
 export default CoordTransform;