Comments (5)
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.
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.
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.
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.
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)
- GeoTiff reprojection from WGS84 to Mercator HOT 8
- COG -> GeoTIFF() + normalize:false -> TileLayer is broken on many newer Android phones HOT 3
- The distance measured by the circle and line segment in OpenLayers is not the same. HOT 6
- Save the rendered size of Icons (and other style content) when the View fit is changed HOT 2
- The new Google Maps source in v9 doesn't comply with Google's policies by default (missing logo and attribution) HOT 10
- hi
- Flickering map when using webview on a NOTHING phone HOT 25
- WebGLBaseTileLayerRenderer causes flickering when source or source key changes.
- Default Styles for Modifying Feature Broke in Upgrade from 8.2 to 9.0 HOT 9
- this.fill_.loading is not a function in ol/style/RegularShape.js HOT 1
- Reload individual tile HOT 2
- Type 'WebGLTileLayer' is not generic. HOT 1
- The rendering of highlighted stroke on the map is inconsistent HOT 2
- Add setter method for the View.projection_ field. HOT 3
- setOpacity on Vector Layer with 'declutter' set causes layer to disappear. HOT 3
- Move attributionsCollapsible to collapseAttributions HOT 1
- Add https://github.com/openlayers/openlayers/pull/15448 to breaking changes of OL `v9.0.0` HOT 2
- small (<256x256 size), multi-band, colored GeoTIFF fails to be displayed
- GML format always returns 3d geometries HOT 6
- WebGL rendering of large data sets is not without memory and performance issues (OpenLayers 9).. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openlayers.