铯 - 使用相机缩放多边形以匹配Lat-Lon位置,同时放大/缩小 [英] Cesium - using camera to scale a polygon to match Lat-Lon positions while zoom-in/zoom-out

查看:1034
本文介绍了铯 - 使用相机缩放多边形以匹配Lat-Lon位置,同时放大/缩小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力使用相机功能(我认为)会提供一种方法,以便在缩小,放大和旋转时(强制我的多边形贴在我的房子顶部相机移动)。



此问题出现在已解决的早期



结果如下:





这是我的问题,以使此代码工作:



1。为什么scratchDepthIntersection没有设置? c2position是Cartesian2,c2MousePosition是直接从mouse.click.position和scratchDepthIntersection是一个新的Cartesian3。

解决方案

mousePosition 的正确值是包含窗口坐标的 Cartesian2 ,而不是 Cartesian3 。这样的鼠标坐标通常来自 Cesium.ScreenSpaceEventHandler 的回调,但也可以从本地JavaScript鼠标/触摸事件构造。



如果你检查 mousePosition 的内容,你会发现 x y



我看到你编辑的问题包括 mousePosition ,它看起来像鼠标坐标已经转换为椭圆形 Cartesian3 坐标,这将防止此代码工作。您需要原始的鼠标坐标直接进入 scene.pickPosition 才能正常工作。


I am struggling with camera functionality that (I think) would provide a way to force my polygon to stick to the top of my house on zoom-out, zoom-in, and rotation (or camera move).

This question follows an earlier question that was resolved. Now I need a little help resolving my next issue.

The sample code I am trying to follow is located in the gold standard that appears to be baked into the existing camera controller here.

pickGlobe is executed with the parameters of the viewer, the correct mousePosition in world coordinates and a result parameter, which I don't care about right now. scene.pickPosition takes the c2position (Cartesian2) and should return the scratchDepthIntersection (Cartesian3). Instead, the returned value is undefined.

Here is my code:

function clickAction(click) {
    var cartesian = scene.camera.pickEllipsoid(click.position, ellipsoid);
    if (cartesian) {
        var setCartographic = ellipsoid.cartesianToCartographic(cartesian);
        collection.latlonalt.push(
            Cesium.Math.toDegrees(setCartographic.latitude).toFixed(15),
            Cesium.Math.toDegrees(setCartographic.longitude).toFixed(15),
            Cesium.Math.toDegrees(setCartographic.height).toFixed(15)
        );
        lla.push(Cesium.Math.toDegrees(setCartographic.longitude), Cesium.Math.toDegrees(setCartographic.latitude));
        if (lla.length >= 4) {
            console.log((lla.length / 2) + ' Points Added');
        }
        enableDoubleClick();
        enableDraw();

        testMe(click.position);  <--------------------- straight from the mouse click
    }
}

var pickedPosition;
var scratchZoomPickRay = new Cesium.Ray();
var scratchPickCartesian = new Cesium.Cartesian3();
function testMe(c2MousePosition) {  <--------------------- straight from the mouse click
    if (Cesium.defined(scene.globe)) { 
        if(scene.mode !== Cesium.SceneMode.SCENE2D) {
            pickedPosition = pickGlobe(viewer, c2MousePosition, scratchPickCartesian);
        } else {
            pickedPosition = camera.getPickRay(c2MousePosition, scratchZoomPickRay).origin;
        }
    }
}

var pickGlobeScratchRay = new Cesium.Ray();
var scratchRayIntersection = new Cesium.Cartesian3();    
var c2position = new Cesium.Cartesian2();
function pickGlobe(viewer, c2MousePosition, result) {   <--------------------- straight from the mouse click
    c2position = c2MousePosition;   <--------------------- setting to Cartesian2

    var scratchDepthIntersection = new Cesium.Cartesian3();
    if (scene.pickPositionSupported) {
        scratchDepthIntersection = scene.pickPosition(c2MousePosition);  <--------------------- neither works!
    }

}

Here are my variables:

Here is the result:

Here are my questions to get this code working:

1. Why is scratchDepthIntersection not getting set? c2position is a Cartesian2 and c2MousePosition is straight from the mouse.click.position and scratchDepthIntersection is a new Cartesian3.

解决方案

The correct value for mousePosition is a Cartesian2 containing window coordinates, not a Cartesian3. Such mouse coordinates usually come from a callback from Cesium.ScreenSpaceEventHandler, but can also be constructed from native JavaScript mouse/touch events.

If you inspect the contents of mousePosition, you should find x and y values in window pixel coordinates.

I see you edited the question to include the contents of mousePosition, and it looks like the mouse coordinates have already been converted into ellipsoid Cartesian3 coordinates, which will prevent this code from working. You want original mouse coordinates going directly into scene.pickPosition for this to work.

这篇关于铯 - 使用相机缩放多边形以匹配Lat-Lon位置,同时放大/缩小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆