Skip to content

Commit

Permalink
Merge pull request openlayers#16067 from mike-000/cog-setstyle
Browse files Browse the repository at this point in the history
Reset layer style when new GeoTIFF source is ready
  • Loading branch information
ahocevar committed Sep 21, 2024
2 parents f6ddf79 + 3ffd442 commit 3c940fb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/ol/layer/WebGLTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,19 @@ class WebGLTileLayer extends BaseTileLayer {
if (this.hasRenderer()) {
this.getRenderer().clearCache();
}
if (this.getSource()) {
this.setStyle(this.style_);
const source = this.getSource();
if (source) {
if (source.getState() === 'loading') {
const onChange = () => {
if (source.getState() === 'ready') {
source.removeEventListener('change', onChange);
this.setStyle(this.style_);
}
};
source.addEventListener('change', onChange);
} else {
this.setStyle(this.style_);
}
}
}

Expand Down
Binary file added test/rendering/cases/cog-setsource/expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions test/rendering/cases/cog-setsource/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import GeoTIFF from '../../../../src/ol/source/GeoTIFF.js';
import Map from '../../../../src/ol/Map.js';
import TileLayer from '../../../../src/ol/layer/WebGLTile.js';
import View from '../../../../src/ol/View.js';

const layer = new TileLayer({
style: {
color: ['array', ['band', 1], ['band', 1], ['band', 1], ['band', 2]],
},
});

const map = new Map({
target: 'map',
layers: [layer],
view: new View({
center: [0, 0],
zoom: 0,
}),
});

fetch('/data/raster/sentinel-b08.tif')
.then((response) => response.blob())
.then((blob) => {
const source = new GeoTIFF({
sources: [{blob: blob}],
transition: 0,
});

layer.setSource(source);
source.getView().then((options) => {
map.setView(new View(options));
});

render({
message: 'alpha styled from band 2',
});
});

0 comments on commit 3c940fb

Please sign in to comment.