Git Product home page Git Product logo

Comments (5)

ahocevar avatar ahocevar commented on May 27, 2024

Please note that ImageTile#setImage() is not an API method. We could change that, but first I'd be curious to hear more about your use case. Internally, that method is used to set an already loaded image as a tile's image.

from openlayers.

mgurzixo avatar mgurzixo commented on May 27, 2024

Thanks @ahocevar for the quick answer.

I am using a multilevel tile cache for improving performance, and I am "sometime" able to precalculate bitmaps in advance: bitmap = await createImageBitmap(blob);. I am also thinking about creating a worker thread for bitmap rendering.

So I looked at OL code and found that nice setImage() function which was doing exactly what I wanted ;)

Doing it the "official way":

let imageUrl = URL.createObjectURL(blob); 
imageTile.getImage().src = imageUrl;

is convoluted, slow, and uses a lot of CPU.

from openlayers.

mike-000 avatar mike-000 commented on May 27, 2024

You are getting the error because setImage() takes an image or canvas element, ImageBitmap is not supported and would need to be included in typedefs.

However I think the suggested change is valid as where setImage() is currently used (as in TileDebug) the code is needlessly setting a listener on a canvas. Also the statement order in setImage should be the same as that in handleImageError_ so any listener is removed before updating this.image_.

from openlayers.

ahocevar avatar ahocevar commented on May 27, 2024

A sensible change would be a bit more involved. Currently, ol/ImageTile already creates a HTMLImageElement at construction time, which is not needed for the use case described here. ol/source/Image and ol/source/DataTile have a configurable loader, and this is what we should be aiming for. See #14258.

from openlayers.

mgurzixo avatar mgurzixo commented on May 27, 2024

Thanks @ahocevar for hinting me to #14258. It looks like #14262 is really the right direction to follow in the long term.

Meanwhile, in an attempt to squeeze now the last drop of power from limited devices, I have subclassed XYZ, and overloaded getTileInternal() to intercept tile requests and stuff new tiles from my cache in OL's .

This is definitely not "casher", but works like a charm as long as I use my forked version of OL:

  getTileInternal(z, x, y, pixelRatio, projection) {
    const tileCoordKey = getKeyZXY(z, x, y);
    const olKey = this.getKey();
    const myKey = makeKey2(provider.id, x, y, z);
    if (this.tileCache.containsKey(tileCoordKey)) {
      // Tile already in OL cache
      const olTile = this.tileCache.get(tileCoordKey);
      if (olTile.key == olKey) {
        return XYZ.prototype.getTileInternal.call(this, z, x, y, pixelRatio, projection);
      }
    }
    const rr = tcPrefetch.read(myKey);
    if (rr === null) {
      // Tile not available in prefetch cache
      return XYZ.prototype.getTileInternal.call(this, z, x, y, pixelRatio, projection);
    }
    // Create new tile and stuff it in OL cache
    const tile = this.createTile_(z, x, y, pixelRatio, projection, olKey);
    // Plagiarized from ImageTile#setImage()
    tile.image_ = rr.value.bitmap;
    tile.state = TileState.LOADED;
    this.tileCache.set(tileCoordKey, tile);
    this.changed();
    return tile;
  }
}

Thanks again

Michel

from openlayers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.