Only set frameState.animate true if in transition and alpha < 1

This commit is contained in:
Tim Schaub
2019-08-15 10:25:05 -06:00
parent 2c69ad2bb4
commit e94c7b6c39
3 changed files with 75 additions and 3 deletions

View File

@@ -377,7 +377,8 @@ class CanvasTileLayerRenderer extends CanvasLayerRenderer {
return;
}
const uid = getUid(this);
const alpha = opacity * (transition ? tile.getAlpha(uid, frameState.time) : 1);
const tileAlpha = transition ? tile.getAlpha(uid, frameState.time) : 1;
const alpha = opacity * tileAlpha;
const alphaChanged = alpha !== this.context.globalAlpha;
if (alphaChanged) {
this.context.save();
@@ -389,7 +390,7 @@ class CanvasTileLayerRenderer extends CanvasLayerRenderer {
if (alphaChanged) {
this.context.restore();
}
if (alpha !== 1) {
if (tileAlpha !== 1) {
frameState.animate = true;
} else if (transition) {
tile.endTransition(uid);

View File

@@ -1,5 +1,6 @@
import {Map, View} from '../../../../src/ol/index.js';
import TileLayer from '../../../../src/ol/layer/Tile.js';
import OSM from '../../../../src/ol/source/OSM.js';
import {OSM, XYZ} from '../../../../src/ol/source.js';
describe('ol.layer.Tile', function() {
@@ -32,4 +33,73 @@ describe('ol.layer.Tile', function() {
});
describe('frameState.animate after tile transition with layer opacity', function() {
let target, map;
beforeEach(function(done) {
target = document.createElement('div');
Object.assign(target.style, {
position: 'absolute',
left: '-1000px',
top: '-1000px',
width: '256px',
height: '256px'
});
document.body.appendChild(target);
map = new Map({
target: target,
view: new View({center: [0, 0], zoom: 1})
});
map.once('rendercomplete', function() {
done();
});
});
afterEach(function() {
map.dispose();
document.body.removeChild(target);
});
it('sets frameState.animate to false when opacity is 1', function(done) {
let lastFrameState;
const layer = new TileLayer({
opacity: 1,
source: new XYZ({
url: 'spec/ol/data/osm-0-0-0.png'
})
});
layer.on('postrender', function(event) {
lastFrameState = event.frameState;
});
map.once('rendercomplete', function() {
expect(lastFrameState.animate).to.be(false);
done();
});
map.addLayer(layer);
});
it('sets frameState.animate to false when opacity is 0.5', function(done) {
let lastFrameState;
const layer = new TileLayer({
opacity: 0.5,
source: new XYZ({
url: 'spec/ol/data/osm-0-0-0.png'
})
});
layer.on('postrender', function(event) {
lastFrameState = event.frameState;
});
map.once('rendercomplete', function() {
expect(lastFrameState.animate).to.be(false);
done();
});
map.addLayer(layer);
});
});
});

View File

@@ -203,6 +203,7 @@ describe('ol.Map', function() {
target: target,
layers: [
new TileLayer({
opacity: 0.5,
source: new XYZ({
url: 'spec/ol/data/osm-{z}-{x}-{y}.png'
})