CesiumGS / cesium

An open-source JavaScript library for world-class 3D globes and maps :earth_americas:
https://cesium.com/cesiumjs/
Apache License 2.0
12.81k stars 3.46k forks source link

Picking problems in 2D when tracking an entity #3242

Open emackey opened 8 years ago

emackey commented 8 years ago

Here's a combination of our Sandcastle Picking + CZML demos:

var viewer = new Cesium.Viewer('cesiumContainer');
viewer.dataSources.add(Cesium.CzmlDataSource.load('../../SampleData/simple.czml'));

var scene = viewer.scene;
var entity = viewer.entities.add({ label: { show: false }});

// Mouse over the globe to see the cartographic position
var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(movement) {
    var cartesian = viewer.camera.pickEllipsoid(movement.endPosition, scene.globe.ellipsoid);
    if (cartesian) {
        var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
        var longitudeString = Cesium.Math.toDegrees(cartographic.longitude).toFixed(2);
        var latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(2);

        entity.position = cartesian;
        entity.label.show = true;
        entity.label.text = '(' + longitudeString + ', ' + latitudeString + ')';
    } else {
        entity.label.show = false;
    }
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

The picking appears to work fine in 3D and Columbus View, and works in 2D as long as you're not tracking a CZML Entity. If you're tracking in 2D however, picking has an unexplained offset, large enough that you have to zoom out to most of the map to see the spot picked.

via StackOverflow.

hpinkos commented 7 years ago

possibly related to #3247?

hpinkos commented 7 years ago

Also reported here: https://groups.google.com/forum/?hl=en#!topic/cesium-dev/pp-vskchuVY

ItayBa commented 2 years ago

Did anyone fixed this?

ebogo1 commented 2 years ago

Related bug found here - https://github.com/CesiumGS/cesium/issues/9916.

timeichfeld-msa commented 2 months ago

hello, I am still seeing this using the following code:

viewer.scene.canvas.addEventListener('mousemove', function (e) { var ellipsoid = viewer.scene.globe.ellipsoid; // Mouse over to get lat/lng var cartesian = viewer.camera.pickEllipsoid(new Cesium.Cartesian3(e.clientX, e.clientY), ellipsoid); if (cartesian) { var cartographic = ellipsoid.cartesianToCartographic(cartesian); var longitudeString = Cesium.Math.toDegrees(cartographic.longitude).toFixed(6); var latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(6); document.getElementById("latLngDisplay").innerHTML = 'Lat,Lng: ' + longitudeString + ', ' + latitudeString; } });

is there a workaround?

the values I am getting seem to be from (0.0, 0.0) when an entity is tracked.

looking at function Qat in Cesium.js (bp @ line 12407, column 219352) In the debugger, when I do not have an entity tracked, I get e: en:: _position { "x": -17809439.158786256, "y": 2529375.7111355397, "z": 12756274 } e: en:: _positionWC { "x": 12756274, "y": -17809402.829757854, "z": 2529595.748431439 } -=-=-=- when I have an entity tracked, I get e: en:: _position { "x": 0, "y": 0, "z": 12756365.13519999 } e: en:: _positionWC { "x": 12756274, "y": -17809402.829757854, "z": 2529595.748431439 }

looks like viewer.camera.positionCartographic is correct when an entity is tracked, but the viewer.camera.position is at 0,0.

ggetz commented 2 months ago

Hi @timeichfeld-msa, there hasn't been any activity on this item recently.

If you'd like to add more information about your use case, that may help us prioritize. If you are interesting in contributing, please let us know and we'd be happy to discuss implementation or review a PR. Thanks!

timeichfeld-msa commented 2 months ago

Hi ggetz. I just put together a sandcastle item to explain the problem I am seeing.

Please have a look at: https://sandcastle.cesium.com/#c=nVZrT+M4FP0rV/1CMlOcMgzLbKFomVK0SIUiWvalSCs3cVprXLtjO0BnNf99r+O8ChTtLB9K6tzHOec+3OhdLGfMWLjVKmHG9GMZywMSwko9MLBLhg+5YUC1ymVaHMxFzsB8zalmBGK5D1JZbzqmtgtjuegDl8VBvl4zDYJlFhKlJdNkh71mNFW5xVNqIVNCqEfTZEevDwjJMMES+xwDzDeQCJ584XIBSgK3aH6I5lbT5Mub1u5dQldMU+CJc/WoU27Wgm5grp4w1EcM9U2pFTh8FAS3VjhER/9ZJCfp3ej8YnI/g9HTGjmwFBmbXFiU21lX9HfJBmapcpEWdoWFQOWE45u10q+V4ZYruZXwPLE5FXD3o+lQf4qGmIgjR6ES6kJDplGJXrfnUlxP7qcjeMFs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9Usmne1LNu+5bP/9i8

timeichfeld-msa commented 2 months ago

here is the javascript code: /* Test Process:

1.) move the mouse around the blue square.

READOUT Expected result: the readout in the upper left corner should read the lat,lng of the mouse position.

READOUT Actual Result: the readout in the upper left corner shows a relative location from 0,0

MOUSE READOUT Expected Result: the mouse readout should show the label above the mouse position with the lat,lng

MOUSE POSITION Actual Result: the mouse readout is displayed at the (0,0) position (Zoom out to view off the coast of Africa.)

*/

const viewer = new Cesium.Viewer("cesiumContainer",{ sceneMode: Cesium.SceneMode.SCENE2D, });

//readout viewer.entities.add({ id: 'mouseReadout', label: { show: false, eyeOffset: new Cesium.Cartesian3(0, 500, -1000) } });

var entity = viewer.entities.add({ position : Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883), box : { dimensions : new Cesium.Cartesian3(1000.0, 1000.0, 100.0), material : Cesium.Color.CORNFLOWERBLUE }, name: "blue square" });

viewer.camera.flyTo( { destination: Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883, 10000.0) } );

viewer.scene.canvas.addEventListener('mousemove', function (e) {

//TODO: Picking when an entity is tracked in the camera yields incorrect results
var entity = viewer.entities.getById('mouseReadout');
var ellipsoid = viewer.scene.globe.ellipsoid;

// Mouse over the globe to see the cartographic position 
var cartesian = viewer.camera.pickEllipsoid(new Cesium.Cartesian3(e.clientX, e.clientY), ellipsoid);
if (cartesian) {
    var cartographic = ellipsoid.cartesianToCartographic(cartesian);
    var longitudeString = Cesium.Math.toDegrees(cartographic.longitude).toFixed(6);
    var latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(6);
    //NOTE: For label at mouse position
    entity.position = cartesian;
    entity.label.show = true;
    entity.label.font_style = 12;
    entity.label.text = 'Lat,Lng: ' + latitudeString + ', ' + longitudeString;
    var result = entity.label.text;
    document.getElementById("readout").innerHTML = entity.label.text;
}

});

Here is the css/html:

<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar">
  <div id="readout"></div>
</div>

Thanks much :)

timeichfeld-msa commented 2 months ago

@ggetz

Hello, I have not seen any additional activity since I posted the code. Was the Cesium Team able to have a look? Should I file a new bug to be prioritized?

Thanks much, -Timothy

ggetz commented 2 months ago

Thanks for the test case @timeichfeld-msa!

There hasn't been any activity on this item recently. We'd ask that you keep conversation for a single issue in one place.

If you are interesting in contributing, please let us know and we'd be happy to discuss implementation or review a PR. Thanks!

timeichfeld-msa commented 2 months ago

@ggetz Hi Gabby, what kind of contribution is needed, do you mean financial or code development? Please let me know how to proceed.

Thanks much, -Timothy

ggetz commented 2 months ago

@timeichfeld-msa I was referring to code contributions. But we do consider service work for roadmap-aligned services. For that, email sales@cesium.com.

timeichfeld-msa commented 2 months ago

@ggetz
Hi Gabby, Understood :) Thank you for the clarification.

We are just beginning to explore the CesiumJS API to satisfy our use-cases and requirements. As we are still in learning mode, I think it would be premature for us to contribute good workable code that would help make Cesium better. We are just not up to speed with Cesium internal design, dependencies and requirements to be efficient with both our development investigation and in helping make Cesium better.

What I am able to do now is investigate our use-cases and look to the Cesium Team for API guidance and advice on resolving issues that we may encounter. Please let me know how to proceed.

Thanks much, -Timothy