Detect Bing Tile request failure?

Thanks to Patrick and Kevin, I now have my satellites mapped to ECF coordinates; thanks guys!

I sometimes do development when on transit. I’m trying to figure out how to make the CentralBody.dayTileProvider detect if it can’t pull from Bing, and use the SingleTileProvider instead.

When I spec my Bing provider, I set ‘onerror’ but never see it invoked:

var bing = new Cesium.BingMapsTileProvider({

    onerror : function () { console.log("ZOMG, a Bing error"); },

    server : 'dev.virtualearth.net',

    mapStyle : Cesium.BingMapsStyle.AERIAL 

});

var cb = new Cesium.CentralBody(ellipsoid);

cb.dayTileProvider      = bing;

I do see the GET fail in Chrome’s Javascript console:

  1. GET http://dev.virtualearth.net/REST/v1/Imagery/Metadata/Aerial?key=AquXz3981-1ND5jGs8qQn7R7YUP8qkWi77yZSVM7o3nIvzb-Mg0W2Ta57xuUyywX&jsonp=jsonp973179 cesium.js:55519

  2. jsonpcesium.js:55519

  3. BingMapsTileProvider._requestTemplatecesium.js:56014

  4. BingMapsTileProvidercesium.js:55930

  5. (anonymous function)index.js:45

  6. (anonymous function)

Is there a different way I should be detecting this? I was hoping to be able to do something like the following but if onerror’s not called, I don’t know how to hook the 404.

var bin = new Cesium.BingMapsTileProvider({

onerror : function () { bing = new CesiumSingleTileProvider(‘Images/NE2_50M_SR_W_4096.jpg’);},

Thanks.

Hi Chris,

Currently we don’t any API in place for responding to tile load failure, which is all handled internally inside the tile providers.

You could do some simple checking yourself to see whether you have access to the Bing imagery, and set the dayTileProvider accordingly:

var image = new Image();

image.onload = function() {

// success, use Bing provider

cb.dayTileProvider = bing;

}

image.onerror = function() {

// failure, fall back to single tile provider

cb.dayTileProvider = singleTile;

}

image.src = ‘http://ecn.t0.tiles.virtualearth.net/tiles/a0.jpeg?g=1041’;

In the imagery_layers branch which should be integrated into master “soon” ™, you could add the SingleTile provider as the base layer underneath Bing, though your console would still fill up with errors.