-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Comments
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. |
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.) 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. |
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. |
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 GlobeSurfaceTile.prototype.pick |
Also reported here: https://groups.google.com/d/msg/cesium-dev/PnM8vOhALfY/-OCjHEU7DgAJ |
Mentioned again in the above linked issue. This comes up all of the time so I marked it priority. |
What can I use instead of this pickImageryLayerFeatures function in the 2D state? |
Hey @pjcozzi , could you please add |
Got it, thanks @thw0rted! |
FYI: This bug also effects the Navigation Mixin: The Distance Legend is not showing in 2D as it uses getPickRay(). |
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. |
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 |
3yr old bug =P |
Touchéz ;) |
I don't have the expertise to tell, is this maybe related to #4368 ? |
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:
I am a bot who helps you make Cesium awesome! Contributions to my configuration are welcome. 🌍 🌎 🌏 |
Happy to say that this bug is finally fixed! #6859 |
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 returnsundefined
even when the map is picked,The text was updated successfully, but these errors were encountered: