Cesium 获取当前场景坐标范围

getCesiumViewerExtend() {
			debugger;
			let params = {};
			let extend = window.cesiumViewer.camera.computeViewRectangle();
			if (typeof extend === "undefined") {
				//2D下会可能拾取不到坐标,extend返回undefined,所以做以下转换
				let canvas = window.cesiumViewer.scene.canvas;
				let upperLeft = new Cesium.Cartesian2(0, 0); //canvas左上角坐标转2d坐标
				let lowerRight = new Cesium.Cartesian2(canvas.clientWidth, canvas.clientHeight); //canvas右下角坐标转2d坐标

				let ellipsoid = window.cesiumViewer.scene.globe.ellipsoid;
				let upperLeft3 = window.cesiumViewer.camera.pickEllipsoid(upperLeft, ellipsoid); //2D转3D世界坐标

				let lowerRight3 = window.cesiumViewer.camera.pickEllipsoid(lowerRight, ellipsoid); //2D转3D世界坐标

				let upperLeftCartographic = window.cesiumViewer.scene.globe.ellipsoid.cartesianToCartographic(upperLeft3); //3D世界坐标转弧度
				let lowerRightCartographic = window.cesiumViewer.scene.globe.ellipsoid.cartesianToCartographic(lowerRight3); //3D世界坐标转弧度

				let minx = Cesium.Math.toDegrees(upperLeftCartographic.longitude); //弧度转经纬度
				let maxx = Cesium.Math.toDegrees(lowerRightCartographic.longitude); //弧度转经纬度

				let miny = Cesium.Math.toDegrees(lowerRightCartographic.latitude); //弧度转经纬度
				let maxy = Cesium.Math.toDegrees(upperLeftCartographic.latitude); //弧度转经纬度

				console.log("经度:" + minx + "----" + maxx);
				console.log("纬度:" + miny + "----" + maxy);

				params.minx = minx;
				params.maxx = maxx;
				params.miny = miny;
				params.maxy = maxy;
			} else {
				//3D获取方式
				params.maxx = Cesium.Math.toDegrees(extend.east);
				params.maxy = Cesium.Math.toDegrees(extend.north);

				params.minx = Cesium.Math.toDegrees(extend.west);
				params.miny = Cesium.Math.toDegrees(extend.south);
			}
			return params; //返回屏幕所在经纬度范围
		}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值