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

Adding entity after delay causes entities to not display #2514

Closed
asimps opened this issue Feb 25, 2015 · 3 comments · Fixed by #2537
Closed

Adding entity after delay causes entities to not display #2514

asimps opened this issue Feb 25, 2015 · 3 comments · Fixed by #2537
Assignees

Comments

@asimps
Copy link

asimps commented Feb 25, 2015

Entities do not appear if an entity is added after a short delay following viewer creation. If an entity is added after a delay of 5ms or so, it causes one or all of the other entities to not appear. With a very large delay (like 5000ms), things seem to work correctly.

In our environment, the delay happens because we make an AJAX request to the server to retrieve additional data points.

Paste the following code into sandcastle. We’re simulating our scenario by adding a delay with setTimeout to the creation of one of the polylines. We’ve been able to elicit this problem on Windows/Chrome, Mac/Chrome, and Mac/Firefox.

Vary the delay variable. The results we get are:

delay = 0 ---- both lines appear
delay = 5 (or so) --- no lines appear
delay = 5000 --- both lines appear

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

// zero delay: both lines show
// small delay (5 or so), none
// large delay (5000 or so), both 
var delay = 5;

// a zero value: both lines are shown
if (delay == 0) {
    line(30, Cesium.Color.RED);
    line(37, Cesium.Color.BLUE);
}

// a >0 value: none, one, or both
else {
    window.setTimeout(function () {
        line(30, Cesium.Color.RED);
    }, delay);
    line(37, Cesium.Color.BLUE);
}

viewer.zoomTo(viewer.entities);

function line(lat,color) {
    viewer.entities.add({
        polyline : {
            positions : Cesium.Cartesian3.fromDegreesArray([-75, lat, -125, lat]),
            width : 5,
            material : color
       }
    })
}
@mramato
Copy link
Contributor

mramato commented Feb 25, 2015

Thanks for the report. This is definitely a bug and related to a similar issue I cam across recently that involves updating static data in quick succession. I'll try and see if I can fix it for the next release (but I can't garuantee anything until I look more into it). (But I'm leaning towards a simple fix).

In the mean time, if you know when your updates are about to start and finish, then you should call viewer.entities.suspendEvents(); and the beginning and viewer.entities.resumeEvents(); at the end, this will avoid the race condition and everything should work.

Here's a slightly modified version of your example that does this. Comment out the two calls and the problem reappears.

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

function line(lat,color) {
    viewer.entities.add({
        polyline : {
            positions : Cesium.Cartesian3.fromDegreesArray([-75, lat, -125, lat]),
            width : 5,
            material : color
       }
    });
}

// zero delay: both lines show
// small delay (5 or so), none
// large delay (5000 or so), both 
var delay = 5;

// a zero value: both lines are shown
if (delay === 0) {
    line(30, Cesium.Color.RED);
    line(37, Cesium.Color.BLUE);
    viewer.zoomTo(viewer.entities);
}

// a >0 value: none, one, or both
else {
    viewer.entities.suspendEvents();
    window.setTimeout(function () {
        line(30, Cesium.Color.RED);
        viewer.entities.resumeEvents();
        viewer.zoomTo(viewer.entities);
    }, delay);
    line(37, Cesium.Color.BLUE);
}

@mramato mramato self-assigned this Feb 25, 2015
mramato added a commit that referenced this issue Mar 2, 2015
Fixes #2514 (and other related issues as discussed
[on the forum](https://groups.google.com/d/msg/cesium-dev/JOUCjnqeFKg/q5aAZb2faAMJ)).

The problem was that when static entities were updated, we would
create a primitive to batch them. However, if the entities were updated
again before the primitive was ready, we didn't remove it.
@pjcozzi
Copy link
Contributor

pjcozzi commented Mar 2, 2015

@asimps thanks again for the report. The fix will be in Cesium 1.7, which will be released shortly.

@asimps
Copy link
Author

asimps commented Mar 2, 2015

Many thanks to you guys!

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

Successfully merging a pull request may close this issue.

3 participants