Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Either getPickRay or globe.pick does not work in 2D. #2480

Closed
mramato opened this issue Feb 10, 2015 · 19 comments
Closed

Either getPickRay or globe.pick does not work in 2D. #2480

mramato opened this issue Feb 10, 2015 · 19 comments

Comments

@mramato
Copy link
Contributor

mramato commented Feb 10, 2015

Paste the below into Sandcastle. Clicking on the globe has no effect. Clicking off the globe alerts a failure. In 2D, it fails because globe.pick always returns undefined even when the map is picked,

var viewer = new Cesium.Viewer('cesiumContainer');

var handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas, false);
handler.setInputAction(
    function(movement) {
        var ray = viewer.camera.getPickRay(movement.position);
        var position = viewer.scene.globe.pick(ray, viewer.scene);
        if (!Cesium.defined(position)) {
            window.alert('FAILED');
        }
    },
    Cesium.ScreenSpaceEventType.LEFT_CLICK
);
@WarpDrive
Copy link

Update: my equation I wrote here is wrong for latitude. Latitude projection apparently has a logarithmic relationship rather than linear. WebMercatorProjection.prototype.project calls WebMercatorProjection.geodeticLatitudeToMercatorAngle for proper log conversion.

For 2D it seems that ray already contains the clicked position without calling globe.pick

var viewer = new Cesium.Viewer('cesiumContainer');

var handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas, false);
handler.setInputAction(
    function(movement) {
        var ray = viewer.camera.getPickRay(movement.position);
        if(viewer.camera._mode==2)
        {
            var equator_length = 2*Math.PI*6378137;
            var sideScale = equator_length/2;
            var vertScale = equator_length/4;
            console.log((ray.origin.x/sideScale*180)+","+(ray.origin.y/vertScale*90));  //lon-lat
        }
        else
        {
            var position = viewer.scene.globe.pick(ray, viewer.scene);
            if (!Cesium.defined(position)) {
            window.alert('FAILED');
            }
        }
    },
    Cesium.ScreenSpaceEventType.LEFT_CLICK
);

Though this might depend on HPR being (0,-90,0) while in the 2D mode.

@WarpDrive
Copy link

Just noticed that the SandCastle pick demo uses pickEllipsoid rather than getPickray for all 3 projection modes. (though getPickray is used as a sub-function of pickEllipsoid.)
http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Picking.html&label=Showcases

var cartesian = viewer.camera.pickEllipsoid(movement.endPosition, ellipsoid);
var cartographic = ellipsoid.cartesianToCartographic(cartesian);

pickEllipsoid calls the pick function for the current mode. Looking at pickMap2D it only cares about ray.origin from getPickRay as ray.origin is the same as the ray's destination (the x & y components.) pickMap2D then unprojects then converts from Cartographic to Cartesian.

I noticed that pickEllipsoid handles heading changes just fine in 2DMode, but not pitch changes (only -90deg.) However I suppose pitch changes aren't officially supported in 2DMode anyhow as setView always sets pitch -90deg and roll 0 for 2DMode.

@WarpDrive
Copy link

Camera.prototype.pickEllipsoid in 3D calls IntersectionTests.rayEllipsoid which picks an ellipsoid with no regard for terrain. Globe.prototype.pick on the other hand does have regard for terrain, but 2D doesn't seem to have terrain as it's -90deg pitch only with an orthographic projection which wouldn't notice terrain even if it was enabled.

@tlpinney
Copy link

@slysnake
Maybe it needs to check the projection mode and use Globe.prototype.pick for 3D and the pickEllipsoid for 2D?

I added a pull request that illustrates this at #2492
It is kind of hacky but I think it solves the issue with 2D and works with terrain in 3D mode.

@WarpDrive
Copy link

UPDATE: Initially I mistakenly thought you meant ImageryLayerCollection.prototype.pickImageryLayerFeatures was called by viewer.scene.globe.pick, but rather you were comparing to a similar situation.

I posted some more about this on a topic called 'camera.lookAt.range' (as Hyper Sonic.) on Cesium's forum (forum won't create a working link.) I believe the calling order is set up like this (is there a good call graph for Cesium available?)

viewer.scene.globe.pick
-collects a list of tiles whom's sphere got intersected by the ray
-then calls GlobeSurfaceTile.prototype.pick on each of these tiles

GlobeSurfaceTile.prototype.pick
-Goes through the list of all triangles in the tile using IntersectionTests.rayTriangle
-IntersectionTests.rayTriangle calls rayTriangle
-If rayTriangle returns a number, not only is that a hit, but is also the range of the hit

@hpinkos
Copy link
Contributor

hpinkos commented Feb 22, 2017

@mramato
Copy link
Contributor Author

mramato commented May 31, 2017

Mentioned again in the above linked issue. This comes up all of the time so I marked it priority.

@xiangjg
Copy link

xiangjg commented Jun 1, 2017

What can I use instead of this pickImageryLayerFeatures function in the 2D state?

@hpinkos
Copy link
Contributor

hpinkos commented Jul 18, 2017

Also reported by @thw0rted in #5076

@thw0rted
Copy link
Contributor

Hey @pjcozzi , could you please add category - picking? I missed this because it's not tagged.

@hpinkos
Copy link
Contributor

hpinkos commented Jul 18, 2017

Got it, thanks @thw0rted!

@krheinwald
Copy link

FYI: This bug also effects the Navigation Mixin: The Distance Legend is not showing in 2D as it uses getPickRay().

@hpinkos
Copy link
Contributor

hpinkos commented Jan 25, 2018

Thanks @krheinwald, but the Cesium team doesn't support a Navigation Mixin. I would make a comment in whichever repository you're using the mixing from.

@krheinwald
Copy link

It was not my intention to get support for the Navigation Mixin. More like showing the far reaching effects of this 4yr old bug :p

@hpinkos
Copy link
Contributor

hpinkos commented Jan 25, 2018

3yr old bug =P
Gotcha, thanks @krheinwald! I hope we're able to address this before it becomes a 4yr old bug.
As always, if anyone has time to look into it, we're always happy to review pull requests!

@krheinwald
Copy link

Touchéz ;)

@thw0rted
Copy link
Contributor

I don't have the expertise to tell, is this maybe related to #4368 ?

@cesium-concierge
Copy link

Congratulations on closing the issue! I found these Cesium forum links in the comments above:

https://groups.google.com/d/msg/cesium-dev/PnM8vOhALfY/-OCjHEU7DgAJ

If this issue affects any of these threads, please post a comment like the following:

The issue at #2480 has just been closed and may resolve your issue. Look for the change in the next stable release of Cesium or get it now in the master branch on GitHub https://github.com/AnalyticalGraphicsInc/cesium.


I am a bot who helps you make Cesium awesome! Contributions to my configuration are welcome.

🌍 🌎 🌏

@hpinkos
Copy link
Contributor

hpinkos commented Aug 8, 2018

Happy to say that this bug is finally fixed! #6859
The fix will be included in the Cesium 1.49 release available September 3rd.

@krheinwald @thw0rted @xiangjg @WarpDrive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants