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

SceneTransforms.wgs84ToWindowCoordinates returns undefined for certain camera angles #4098

Open
hpinkos opened this issue Jul 7, 2016 · 1 comment

Comments

@hpinkos
Copy link
Contributor

hpinkos commented Jul 7, 2016

Reported on the forum: https://groups.google.com/forum/?hl=en#!topic/cesium-dev/ALIPbA_LSqU

var viewer = new Cesium.Viewer('cesiumContainer');
viewer.camera.lookAt(Cesium.Cartesian3.fromDegrees(20.5, 54.7), 
new Cesium.Cartesian3(35000.0, -200000.0, 100000.0));
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
var scene = viewer.scene;
var ellipsoid = scene.globe.ellipsoid;
var position = Cesium.Cartesian3.fromDegrees(0.0, 0.0);
var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(movement) {
    console.log(Cesium.SceneTransforms.wgs84ToWindowCoordinates(scene, position));
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
@aneesha2890
Copy link

Hi ,
I saw this code that finds html coordinates from entity and place a div on that position
var scratch3dPosition = new Cesium.Cartesian3();
var scratch2dPosition = new Cesium.Cartesian2();

// Every animation frame, update the HTML element position from the entity.
viewer.clock.onTick.addEventListener(function(clock) {
var position3d;
var position2d;

// Not all entities have a position, need to check.
if (entity.position) {
    position3d = entity.position.getValue(clock.currentTime, scratch3dPosition);
}

// Moving entities don't have a position for every possible time, need to check.
if (position3d) {
    position2d = Cesium.SceneTransforms.wgs84ToWindowCoordinates(
        viewer.scene, position3d, scratch2dPosition);
}

// Having a position doesn't guarantee it's on screen, need to check.
if (position2d) {
    // Set the HTML position to match the entity's position.
    testElement.style.left = position2d.x + 'px';
    testElement.style.top = position2d.y + 'px';

    // Reveal HTML when entity comes on screen
    if (!isEntityVisible) {
        isEntityVisible = true;
        testElement.style.display = 'block';
    }
} else if (isEntityVisible) {
    // Hide HTML when entity goes off screen or loses its position.
    isEntityVisible = false;
    testElement.style.display = 'none';
}

});

here for me SceneTransforms is coming undefined inspite of having values in all the three arguments passed to it.
Can someone help here??

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

3 participants