Merge pull request #9131 from fredj/opacity_cmp
Don't use strict comparison with style.opacity
This commit is contained in:
@@ -91,7 +91,7 @@ class BaseLayer extends BaseObject {
|
|||||||
layer: this,
|
layer: this,
|
||||||
managed: true
|
managed: true
|
||||||
});
|
});
|
||||||
state.opacity = clamp(this.getOpacity(), 0, 1);
|
state.opacity = clamp(Math.round(this.getOpacity() * 100) / 100, 0, 1);
|
||||||
state.sourceState = this.getSourceState();
|
state.sourceState = this.getSourceState();
|
||||||
state.visible = this.getVisible();
|
state.visible = this.getVisible();
|
||||||
state.extent = this.getExtent();
|
state.extent = this.getExtent();
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import SourceState from '../source/State.js';
|
|||||||
/**
|
/**
|
||||||
* @typedef {Object} State
|
* @typedef {Object} State
|
||||||
* @property {import("./Base.js").default} layer
|
* @property {import("./Base.js").default} layer
|
||||||
* @property {number} opacity
|
* @property {number} opacity Opacity, the value is rounded to two digits to appear after the decimal point.
|
||||||
* @property {SourceState} sourceState
|
* @property {SourceState} sourceState
|
||||||
* @property {boolean} visible
|
* @property {boolean} visible
|
||||||
* @property {boolean} managed
|
* @property {boolean} managed
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ class CanvasImageLayerRenderer extends CanvasLayerRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const opacity = layerState.opacity;
|
const opacity = layerState.opacity;
|
||||||
if (opacity !== canvas.style.opacity) {
|
if (opacity !== parseFloat(canvas.style.opacity)) {
|
||||||
canvas.style.opacity = opacity;
|
canvas.style.opacity = opacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -303,7 +303,7 @@ class CanvasTileLayerRenderer extends CanvasLayerRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const opacity = layerState.opacity;
|
const opacity = layerState.opacity;
|
||||||
if (opacity !== canvas.style.opacity) {
|
if (opacity !== parseFloat(canvas.style.opacity)) {
|
||||||
canvas.style.opacity = opacity;
|
canvas.style.opacity = opacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ class CanvasVectorLayerRenderer extends CanvasLayerRenderer {
|
|||||||
this.postRender(context, frameState);
|
this.postRender(context, frameState);
|
||||||
|
|
||||||
const opacity = layerState.opacity;
|
const opacity = layerState.opacity;
|
||||||
if (opacity !== canvas.style.opacity) {
|
if (opacity !== parseFloat(canvas.style.opacity)) {
|
||||||
canvas.style.opacity = opacity;
|
canvas.style.opacity = opacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -508,7 +508,7 @@ class CanvasVectorTileLayerRenderer extends CanvasTileLayerRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const opacity = layerState.opacity;
|
const opacity = layerState.opacity;
|
||||||
if (opacity !== canvas.style.opacity) {
|
if (opacity !== parseFloat(canvas.style.opacity)) {
|
||||||
canvas.style.opacity = opacity;
|
canvas.style.opacity = opacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -252,7 +252,7 @@ class WebGLPointsLayerRenderer extends LayerRenderer {
|
|||||||
const canvas = this.helper_.getCanvas();
|
const canvas = this.helper_.getCanvas();
|
||||||
|
|
||||||
const opacity = layerState.opacity;
|
const opacity = layerState.opacity;
|
||||||
if (opacity !== canvas.style.opacity) {
|
if (opacity !== parseFloat(canvas.style.opacity)) {
|
||||||
canvas.style.opacity = opacity;
|
canvas.style.opacity = opacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -162,14 +162,14 @@ describe('ol.layer.Layer', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns a layerState from the properties values', function() {
|
it('returns a layerState from the properties values', function() {
|
||||||
layer.setOpacity(0.3);
|
layer.setOpacity(1 / 3);
|
||||||
layer.setVisible(false);
|
layer.setVisible(false);
|
||||||
layer.setMaxResolution(500);
|
layer.setMaxResolution(500);
|
||||||
layer.setMinResolution(0.25);
|
layer.setMinResolution(0.25);
|
||||||
layer.setZIndex(10);
|
layer.setZIndex(10);
|
||||||
expect(layer.getLayerState()).to.eql({
|
expect(layer.getLayerState()).to.eql({
|
||||||
layer: layer,
|
layer: layer,
|
||||||
opacity: 0.3,
|
opacity: 0.33,
|
||||||
visible: false,
|
visible: false,
|
||||||
managed: true,
|
managed: true,
|
||||||
sourceState: 'ready',
|
sourceState: 'ready',
|
||||||
|
|||||||
Reference in New Issue
Block a user