From db57d9bf89757f0118627d824869caf5be3c7fe8 Mon Sep 17 00:00:00 2001 From: Seba Kerckhof Date: Tue, 27 Jul 2021 18:54:08 +0200 Subject: [PATCH 1/3] Handle named colors as string in equal operator --- src/ol/style/expressions.js | 6 ++++++ test/browser/spec/ol/style/expressions.test.js | 3 +++ 2 files changed, 9 insertions(+) diff --git a/src/ol/style/expressions.js b/src/ol/style/expressions.js index cb13025692..f66162cbe1 100644 --- a/src/ol/style/expressions.js +++ b/src/ol/style/expressions.js @@ -606,6 +606,12 @@ function getEqualOperator(operator) { ); } + if (type === (ValueTypes.COLOR | ValueTypes.STRING)) { + // It's not possible to compare attributes with color values + // So force it to be treated as a string + type = ValueTypes.STRING; + } + return `(${expressionToGlsl( context, args[0], diff --git a/test/browser/spec/ol/style/expressions.test.js b/test/browser/spec/ol/style/expressions.test.js index 63878458b9..fad983292e 100644 --- a/test/browser/spec/ol/style/expressions.test.js +++ b/test/browser/spec/ol/style/expressions.test.js @@ -250,6 +250,9 @@ describe('ol.style.expressions', function () { expect(expressionToGlsl(context, ['==', 10, ['get', 'attr4']])).to.eql( '(10.0 == a_attr4)' ); + expect(expressionToGlsl(context, ['==', 'red', ['get', 'attr4']])).to.eql( + '(0.0 == a_attr4)' + ); expect(expressionToGlsl(context, ['!=', 10, ['get', 'attr4']])).to.eql( '(10.0 != a_attr4)' ); From 25af938a83b168f8c8d1df844c30cd2e332980f8 Mon Sep 17 00:00:00 2001 From: Seba Kerckhof Date: Wed, 28 Jul 2021 09:17:10 +0200 Subject: [PATCH 2/3] Update test/browser/spec/ol/style/expressions.test.js Co-authored-by: Andreas Hocevar --- test/browser/spec/ol/style/expressions.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/browser/spec/ol/style/expressions.test.js b/test/browser/spec/ol/style/expressions.test.js index fad983292e..caabe63156 100644 --- a/test/browser/spec/ol/style/expressions.test.js +++ b/test/browser/spec/ol/style/expressions.test.js @@ -251,7 +251,7 @@ describe('ol.style.expressions', function () { '(10.0 == a_attr4)' ); expect(expressionToGlsl(context, ['==', 'red', ['get', 'attr4']])).to.eql( - '(0.0 == a_attr4)' + `(${stringToGlsl(context, 'red')} == a_attr4)` ); expect(expressionToGlsl(context, ['!=', 10, ['get', 'attr4']])).to.eql( '(10.0 != a_attr4)' From fec6fee83cac4183aaeebc418daaae82587d1f12 Mon Sep 17 00:00:00 2001 From: Seba Kerckhof Date: Wed, 28 Jul 2021 09:26:29 +0200 Subject: [PATCH 3/3] Remove color from value type in equal operator --- src/ol/style/expressions.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/ol/style/expressions.js b/src/ol/style/expressions.js index f66162cbe1..ff29c14dfd 100644 --- a/src/ol/style/expressions.js +++ b/src/ol/style/expressions.js @@ -606,11 +606,9 @@ function getEqualOperator(operator) { ); } - if (type === (ValueTypes.COLOR | ValueTypes.STRING)) { - // It's not possible to compare attributes with color values - // So force it to be treated as a string - type = ValueTypes.STRING; - } + // Since it's not possible to have color types here, we can leave it out + // This fixes issues in case the value type is ambiguously detected as a color (e.g. the string 'red') + type = type ^ ValueTypes.COLOR; return `(${expressionToGlsl( context,