Merge pull request #12962 from ahocevar/opacity-no-sharing

No context sharing when layer opacity is set
This commit is contained in:
Andreas Hocevar
2021-11-05 23:09:36 +01:00
committed by GitHub
8 changed files with 50 additions and 16 deletions

View File

@@ -17,7 +17,6 @@ import {
getTopRight,
} from '../../extent.js';
import {createCanvasContext2D} from '../../dom.js';
import {cssOpacity} from '../../css.js';
/**
* @abstract
@@ -95,8 +94,9 @@ class CanvasLayerRenderer extends LayerRenderer {
let container, context;
if (
target &&
target.style.opacity === cssOpacity(opacity) &&
target.className === layerClassName
target.className === layerClassName &&
target.style.opacity === '' &&
opacity === 1
) {
const canvas = target.firstElementChild;
if (canvas instanceof HTMLCanvasElement) {

View File

@@ -150,19 +150,6 @@ class CanvasVectorLayerRenderer extends CanvasLayerRenderer {
this.clipping = true;
}
/**
* Get a rendering container from an existing target, if compatible.
* @param {HTMLElement} target Potential render target.
* @param {string} transform CSS Transform.
* @param {number} opacity Opacity.
*/
useContainer(target, transform, opacity) {
if (opacity < 1) {
target = null;
}
super.useContainer(target, transform, opacity);
}
/**
* @param {ExecutorGroup} executorGroup Executor group.
* @param {import("../../PluggableMap.js").FrameState} frameState Frame state.

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

View File

@@ -0,0 +1,47 @@
import Map from '../../../../src/ol/Map.js';
import TileLayer from '../../../../src/ol/layer/Tile.js';
import View from '../../../../src/ol/View.js';
import XYZ from '../../../../src/ol/source/XYZ.js';
import {fromLonLat} from '../../../../src/ol/proj.js';
const center = fromLonLat([-80.4, 32.49]);
const layer1 = new TileLayer({
source: new XYZ({
url: '/data/tiles/south-carolina/{z}/{x}/1-{y}.png',
transition: 0,
}),
});
const layer2 = new TileLayer({
source: new XYZ({
url: '/data/tiles/south-carolina/{z}/{x}/2-{y}.png',
transition: 0,
}),
opacity: 0.5,
});
const layer3 = new TileLayer({
source: new XYZ({
url: '/data/tiles/south-carolina/{z}/{x}/3-{y}.png',
transition: 0,
}),
opacity: 0.5,
});
const layer4 = new TileLayer({
source: new XYZ({
url: '/data/tiles/south-carolina/{z}/{x}/4-{y}.png',
transition: 0,
}),
opacity: 0.5,
});
new Map({
pixelRatio: 1,
layers: [layer1, layer2, layer3, layer4],
target: 'map',
view: new View({
center: center,
zoom: 11.4,
}),
});
render();

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB