CesiumJS is switching from when.js to native promises-- Which will be a breaking change in 1.92

Hi, is it possible that some of the ImageryProviders may have been broken by this change? I notice that the GridImageryProvider no longer seems to work on Sandcastle.Cesium.com with the following error message: ‘TypeError: imagePromise.then is not a function’

Hi robbo1975,

Thanks for letting us know! That was previously reported, and fixed. It will be published as part of the release on Monday, May 2.

1 Like

Hi ! Gabby,
I’m developing screenshot function recently. Can you help me with this
export function captureScreenshot(viewer) {

const { when } = Cesium;

const deferred = when.defer();

const { scene } = viewer;

const removeCallback = scene.postRender.addEventListener(() => {

removeCallback();

try {

const cesiumCanvas = viewer.scene.canvas;

// If we’re using the splitter, draw the split position as a vertical white line.

const canvas = cesiumCanvas;

canvas.toBlob((blod) => {

​ deferred.resolve(blod);

}, “image/png”);

// deferred.resolve(canvas.toDataURL(“image/png”));

} catch (e) {

deferred.reject(e);

}

}, this);

scene.render(viewer.clock.currentTime);

return deferred.promise;

}

Hi Pandada,

I would omit the use of defer and create a Promise directly with the constructor–

export function captureScreenshot(viewer) {
const { scene } = viewer;
return new Promise(function (resolve, reject) {
    const removeCallback = scene.postRender.addEventListener(() => {
        removeCallback();
        try {
            const cesiumCanvas = viewer.scene.canvas;
            // If we’re using the splitter, draw the split position as a vertical white line.
            const canvas = cesiumCanvas;
            canvas.toBlob((blod) => {
​                resolve(blob);
            }, “image/png”);
           // resolve(canvas.toDataURL(“image/png”));
        } catch (e) {
            reject(e);
        }
    }, this);
    scene.render(viewer.clock.currentTime);
});
}

Hi Gabby, it works ,thanks

Hi Gabby, can you help me switch this

Cesium3DTilesDataLayer.prototype.addToCesium = function (cesiumViewer) {
        var that = this;
        this._cesiumViewer = cesiumViewer;
        var deferred = Cesium.when.defer();

        this._tileset = new Cesium.Cesium3DTileset({
            url: this._url
        });

        this._tileset.readyPromise.then(function (tileset) {
            cesiumViewer.scene.primitives.add(tileset);
            tileset.show = that._active;
            that.registerTilesLoadedEventHandler();
            that.registerMouseEventHandlers();
            deferred.resolve(that);
        }).otherwise(function () {
            deferred.reject(new Cesium.DeveloperError('Failed to load: ' + that._url));
        });

        return deferred.promise;
    }

Sure. You can wrap the majority of this function in a new Promise callback:

Cesium3DTilesDataLayer.prototype.addToCesium = function (cesiumViewer) {
var that = this;
this._cesiumViewer = cesiumViewer;
return new Promise(function (resolve, reject) {
this._tileset = new Cesium.Cesium3DTileset({
url: this._url
});

    this._tileset.readyPromise.then(function (tileset) {
        cesiumViewer.scene.primitives.add(tileset);
        tileset.show = that._active;
        that.registerTilesLoadedEventHandler();
        that.registerMouseEventHandlers();
        resolve(that);
    }).otherwise(function () {
        reject(new Cesium.DeveloperError('Failed to load: ' + that._url));
    });
    });
}

Hi Gabby,

We’ve run into a problem updating the textures on our aircraft models. At this point I’m assuming this is related to the change with promises as the code has been working for years and the models and textures have not changed. But I’m not sure why this code is a problem.

Would you take a look and let me know if/how this code should be modified?

This is the code we’ve been using for several years. We recently changed to ‘.catch’ from ‘.otherwise’. Nothing else has changed for several years. But for some reason the textures are no longer being updated when this code executes.

this.Model.readyPromise.then(function(model) {

    // Replace texture
    var textureIndexToReplace = 0;
    var textures = model._rendererResources.textures;
    var texture = textures[textureIndexToReplace];
                        
    Cesium.Resource.fetchImage({
        url: "resources/liveries/" + model['ModelId'] + "_" + model['Airline'] + ".jpg"
    }).then(function(image) {
        texture.copyFrom(image);
        texture.generateMipmap(); // Also replaces textures in mipmap
    })
    .catch (function() {
        console.log("Error finding livery 'resources/liveries/" +  model['ModelId'] + '_' + model['Airline'] + ".jpg");
    });

});

Hi Rob,

What’s the error when in the catch block?

You can use the debugger or add this line:

    .catch (function(e) {
        console.log(e);
        console.log("Error finding livery 'resources/liveries/" +  model['ModelId'] + '_' + model['Airline'] + ".jpg");
    });

Sorry, I should have provided that…

Event {isTrusted: true, type: 'error', target: img, currentTarget: img, eventPhase: 2, …}
isTrusted: true
bubbles: false
cancelBubble: false
cancelable: false
composed: false
currentTarget: null
defaultPrevented: false
eventPhase: 0
path: [img]
returnValue: true
srcElement: null
target: null
timeStamp: 7405.899999991059
type: "error"
[[Prototype]]: Event

TypeError: Cannot read properties of undefined (reading 'width')
    at Texture.copyFrom (Cesium.js:48:301956)
    at BNCoreFlightTrack.js:617:37

Line 617 in BNCoreFlightTrack.js is from the function in the first post:
texture.copyFrom(image);

Has there been a somewhat recent change that would prevent the code I posted above from updating the texture of a model?

I was wrong about always ending up in the ‘catch’. It seems I’m only ending up in the ‘catch’ when trying to retrieve a texture that doesn’t exist. And this is legitimate because we don’t have textures for every aircraft/airline combination.

I think the errors distracted from the real issue. The real problem is that for some reason the textures are no longer being updated when this code executes.

@Gabby_Getz I think the issue has to do with recent changes to models. I was able to get in touch with Sean Lilley who provided the original code to update the texture. He suggested a new approach with the new ModelExperimental. We’re still working to get it sorted out.

Thanks for the help!

1 Like

Gabby Is there any chance that this EGM96 functionality could get bundled into the cesium engine, or better yet an ion terrain source that is orthometric rather than ellipsoid elevations.
Ion Asset Request, orthometric world terrain

I’m going through this same exercise as Rob changing my copy of this code when updating from cesium 1.85 to 1.100

Hi,

There are no near term plans to add EGM96 functionality to CesiumJS at this time. Can you help me understand what all would be involved in supporting this?

The crux of the issue, as that Rob originally mentioned in his first post, is trying to work with data that uses orthometric elevations ( “MSL” Mean Sea Level) .

With “Cesium World Terrain” being an ellipsoid height terrain model, a geoid offset needs to be determined and applied to data so that entities render at the at the proper elevations.

Having an Ion Asset such as “Cesium World Terrain Orthometric” would solve a lot of issues.

On a side note, KML spec defines elevations as being Orthometric, WGS84 EGM96 Geoid when using absolute OGC 12-007r2