IndexedBD & ImageProvider


Has anybody looked for storing requested tiles from the ImageProvider in IndexedDB ?

I’m trying to store localy some tile from my geoserver

I have writen a simple class to access IndexedDB with the forllowing prototype :
var data = TileCacheService.getTile(x,y,level)

The Idea is to create an IndexedDBImageryProvider with the same prototype that an ImageryProvider
This IndexedDBImageryProvider takes a defaultProvider as a parameter. (I’m using a WebMapServiceImageryProvider).

Here is the requestImage function I'm trying to write;

IndexedDBImageryProvider.prototype.requestImage = function(x, y, level) {

    // If the requested tile is in the TileCacheService then return it
    // Otherwise use _defaultProvider to request the tile 
     var that =this;
    var tileDataPromise=  this.tileCacheService.getTileData(x,y,level);
    var   retour = Cesium.when(tileDataPromise, function (tileData) {
        }).otherwise(function (evt) {
            var promises =  that._defaultProvider.requestImage(x,y,level);
            var retour2 = Cesium.when(promises, function (tileData) {
                        // tileData is a HTMLImageElement  ...
                        // we should convert HTMLImageElement   to a blob as it's done in the following sample
                        // ex
                        return tileData;
            return promises;
    return retour;       

I need to convert the HTMLImageElement into a blob before storing it in the indexedDB. Any idea how to do this ?
There is something like this in the following example :


offline-leaflet-map does this with leaflet maps. It shouldn't be too dissimilar from a Cesium version if adapted.