Make code prettier
This updates ESLint and our shared eslint-config-openlayers to use Prettier. Most formatting changes were automatically applied with this:
npm run lint -- --fix
A few manual changes were required:
* In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
* In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason. While editing this, I reworked `ExampleBuilder` to be a class.
* In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
import {parseLiteralStyle, ShaderBuilder} from '../../../../src/ol/webgl/ShaderBuilder.js';
|
||||
import {arrayToGlsl, colorToGlsl, numberToGlsl} from '../../../../src/ol/style/expressions.js';
|
||||
import {
|
||||
ShaderBuilder,
|
||||
parseLiteralStyle,
|
||||
} from '../../../../src/ol/webgl/ShaderBuilder.js';
|
||||
import {
|
||||
arrayToGlsl,
|
||||
colorToGlsl,
|
||||
numberToGlsl,
|
||||
} from '../../../../src/ol/style/expressions.js';
|
||||
|
||||
describe('ol.webgl.ShaderBuilder', function() {
|
||||
|
||||
describe('getSymbolVertexShader', function() {
|
||||
it('generates a symbol vertex shader (with varying)', function() {
|
||||
describe('ol.webgl.ShaderBuilder', function () {
|
||||
describe('getSymbolVertexShader', function () {
|
||||
it('generates a symbol vertex shader (with varying)', function () {
|
||||
const builder = new ShaderBuilder();
|
||||
builder.addVarying('v_opacity', 'float', numberToGlsl(0.4));
|
||||
builder.addVarying('v_test', 'vec3', arrayToGlsl([1, 2, 3]));
|
||||
@@ -61,7 +67,7 @@ void main(void) {
|
||||
v_test = vec3(1.0, 2.0, 3.0);
|
||||
}`);
|
||||
});
|
||||
it('generates a symbol vertex shader (with uniforms and attributes)', function() {
|
||||
it('generates a symbol vertex shader (with uniforms and attributes)', function () {
|
||||
const builder = new ShaderBuilder();
|
||||
builder.addUniform('float u_myUniform');
|
||||
builder.addAttribute('vec2 a_myAttr');
|
||||
@@ -116,7 +122,7 @@ void main(void) {
|
||||
|
||||
}`);
|
||||
});
|
||||
it('generates a symbol vertex shader (with rotateWithView)', function() {
|
||||
it('generates a symbol vertex shader (with rotateWithView)', function () {
|
||||
const builder = new ShaderBuilder();
|
||||
builder.setSizeExpression(`vec2(${numberToGlsl(6)})`);
|
||||
builder.setSymbolOffsetExpression(arrayToGlsl([5, -7]));
|
||||
@@ -170,10 +176,11 @@ void main(void) {
|
||||
|
||||
}`);
|
||||
});
|
||||
it('generates a symbol vertex shader for hitDetection', function() {
|
||||
it('generates a symbol vertex shader for hitDetection', function () {
|
||||
const builder = new ShaderBuilder();
|
||||
|
||||
expect(builder.getSymbolVertexShader(true)).to.eql(`precision mediump float;
|
||||
expect(builder.getSymbolVertexShader(true)).to
|
||||
.eql(`precision mediump float;
|
||||
uniform mat4 u_projectionMatrix;
|
||||
uniform mat4 u_offsetScaleMatrix;
|
||||
uniform mat4 u_offsetRotateMatrix;
|
||||
@@ -219,7 +226,7 @@ void main(void) {
|
||||
v_hitColor = a_hitColor;
|
||||
}`);
|
||||
});
|
||||
it('generates a symbol vertex shader (with a rotation expression)', function() {
|
||||
it('generates a symbol vertex shader (with a rotation expression)', function () {
|
||||
const builder = new ShaderBuilder();
|
||||
builder.setSizeExpression(`vec2(${numberToGlsl(6)})`);
|
||||
builder.setSymbolOffsetExpression(arrayToGlsl([5, -7]));
|
||||
@@ -273,8 +280,8 @@ void main(void) {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getSymbolFragmentShader', function() {
|
||||
it('generates a symbol fragment shader (with varying)', function() {
|
||||
describe('getSymbolFragmentShader', function () {
|
||||
it('generates a symbol fragment shader (with varying)', function () {
|
||||
const builder = new ShaderBuilder();
|
||||
builder.addVarying('v_opacity', 'float', numberToGlsl(0.4));
|
||||
builder.addVarying('v_test', 'vec3', arrayToGlsl([1, 2, 3]));
|
||||
@@ -299,7 +306,7 @@ void main(void) {
|
||||
|
||||
}`);
|
||||
});
|
||||
it('generates a symbol fragment shader (with uniforms)', function() {
|
||||
it('generates a symbol fragment shader (with uniforms)', function () {
|
||||
const builder = new ShaderBuilder();
|
||||
builder.addUniform('float u_myUniform');
|
||||
builder.addUniform('vec2 u_myUniform2');
|
||||
@@ -325,10 +332,11 @@ void main(void) {
|
||||
|
||||
}`);
|
||||
});
|
||||
it('generates a symbol fragment shader for hit detection', function() {
|
||||
it('generates a symbol fragment shader for hit detection', function () {
|
||||
const builder = new ShaderBuilder();
|
||||
|
||||
expect(builder.getSymbolFragmentShader(true)).to.eql(`precision mediump float;
|
||||
expect(builder.getSymbolFragmentShader(true)).to
|
||||
.eql(`precision mediump float;
|
||||
uniform float u_time;
|
||||
uniform float u_zoom;
|
||||
uniform float u_resolution;
|
||||
@@ -345,54 +353,74 @@ void main(void) {
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseSymbolStyle', function() {
|
||||
it('parses a style without expressions', function() {
|
||||
describe('parseSymbolStyle', function () {
|
||||
it('parses a style without expressions', function () {
|
||||
const result = parseLiteralStyle({
|
||||
symbol: {
|
||||
symbolType: 'square',
|
||||
size: [4, 8],
|
||||
color: '#ff0000',
|
||||
rotateWithView: true
|
||||
}
|
||||
rotateWithView: true,
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.builder.uniforms).to.eql([]);
|
||||
expect(result.builder.attributes).to.eql([]);
|
||||
expect(result.builder.varyings).to.eql([]);
|
||||
expect(result.builder.colorExpression).to.eql(
|
||||
'vec4(vec4(1.0, 0.0, 0.0, 1.0).rgb, vec4(1.0, 0.0, 0.0, 1.0).a * 1.0 * 1.0)');
|
||||
'vec4(vec4(1.0, 0.0, 0.0, 1.0).rgb, vec4(1.0, 0.0, 0.0, 1.0).a * 1.0 * 1.0)'
|
||||
);
|
||||
expect(result.builder.sizeExpression).to.eql('vec2(vec2(4.0, 8.0))');
|
||||
expect(result.builder.offsetExpression).to.eql('vec2(0.0, 0.0)');
|
||||
expect(result.builder.texCoordExpression).to.eql('vec4(0.0, 0.0, 1.0, 1.0)');
|
||||
expect(result.builder.texCoordExpression).to.eql(
|
||||
'vec4(0.0, 0.0, 1.0, 1.0)'
|
||||
);
|
||||
expect(result.builder.rotateWithView).to.eql(true);
|
||||
expect(result.attributes).to.eql([]);
|
||||
expect(result.uniforms).to.eql({});
|
||||
});
|
||||
|
||||
it('parses a style with expressions', function() {
|
||||
it('parses a style with expressions', function () {
|
||||
const result = parseLiteralStyle({
|
||||
symbol: {
|
||||
symbolType: 'square',
|
||||
size: ['get', 'attr1'],
|
||||
color: [255, 127.5, 63.75, 0.25],
|
||||
textureCoord: [0.5, 0.5, 0.5, 1],
|
||||
offset: ['match', ['get', 'attr3'], 'red', [6, 0], 'green', [3, 0], [0, 0]]
|
||||
}
|
||||
offset: [
|
||||
'match',
|
||||
['get', 'attr3'],
|
||||
'red',
|
||||
[6, 0],
|
||||
'green',
|
||||
[3, 0],
|
||||
[0, 0],
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.builder.uniforms).to.eql([]);
|
||||
expect(result.builder.attributes).to.eql(['float a_attr1', 'float a_attr3']);
|
||||
expect(result.builder.varyings).to.eql([{
|
||||
name: 'v_attr1',
|
||||
type: 'float',
|
||||
expression: 'a_attr1'
|
||||
}]);
|
||||
expect(result.builder.attributes).to.eql([
|
||||
'float a_attr1',
|
||||
'float a_attr3',
|
||||
]);
|
||||
expect(result.builder.varyings).to.eql([
|
||||
{
|
||||
name: 'v_attr1',
|
||||
type: 'float',
|
||||
expression: 'a_attr1',
|
||||
},
|
||||
]);
|
||||
expect(result.builder.colorExpression).to.eql(
|
||||
'vec4(vec4(1.0, 0.5, 0.25, 0.25).rgb, vec4(1.0, 0.5, 0.25, 0.25).a * 1.0 * 1.0)'
|
||||
);
|
||||
expect(result.builder.sizeExpression).to.eql('vec2(a_attr1)');
|
||||
expect(result.builder.offsetExpression).to.eql('(a_attr3 == 1.0 ? vec2(6.0, 0.0) : (a_attr3 == 0.0 ? vec2(3.0, 0.0) : vec2(0.0, 0.0)))');
|
||||
expect(result.builder.texCoordExpression).to.eql('vec4(0.5, 0.5, 0.5, 1.0)');
|
||||
expect(result.builder.offsetExpression).to.eql(
|
||||
'(a_attr3 == 1.0 ? vec2(6.0, 0.0) : (a_attr3 == 0.0 ? vec2(3.0, 0.0) : vec2(0.0, 0.0)))'
|
||||
);
|
||||
expect(result.builder.texCoordExpression).to.eql(
|
||||
'vec4(0.5, 0.5, 0.5, 1.0)'
|
||||
);
|
||||
expect(result.builder.rotateWithView).to.eql(false);
|
||||
expect(result.attributes.length).to.eql(2);
|
||||
expect(result.attributes[0].name).to.eql('attr1');
|
||||
@@ -400,15 +428,15 @@ void main(void) {
|
||||
expect(result.uniforms).to.eql({});
|
||||
});
|
||||
|
||||
it('parses a style with a uniform (texture)', function() {
|
||||
it('parses a style with a uniform (texture)', function () {
|
||||
const result = parseLiteralStyle({
|
||||
symbol: {
|
||||
symbolType: 'image',
|
||||
src: '../data/image.png',
|
||||
size: 6,
|
||||
color: '#336699',
|
||||
opacity: 0.5
|
||||
}
|
||||
opacity: 0.5,
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.builder.uniforms).to.eql(['sampler2D u_texture']);
|
||||
@@ -419,33 +447,48 @@ void main(void) {
|
||||
);
|
||||
expect(result.builder.sizeExpression).to.eql('vec2(6.0)');
|
||||
expect(result.builder.offsetExpression).to.eql('vec2(0.0, 0.0)');
|
||||
expect(result.builder.texCoordExpression).to.eql('vec4(0.0, 0.0, 1.0, 1.0)');
|
||||
expect(result.builder.texCoordExpression).to.eql(
|
||||
'vec4(0.0, 0.0, 1.0, 1.0)'
|
||||
);
|
||||
expect(result.builder.rotateWithView).to.eql(false);
|
||||
expect(result.attributes).to.eql([]);
|
||||
expect(result.uniforms).to.have.property('u_texture');
|
||||
});
|
||||
|
||||
it('parses a style with variables', function() {
|
||||
it('parses a style with variables', function () {
|
||||
const result = parseLiteralStyle({
|
||||
variables: {
|
||||
lower: 100,
|
||||
higher: 400
|
||||
higher: 400,
|
||||
},
|
||||
symbol: {
|
||||
symbolType: 'square',
|
||||
size: ['interpolate', ['linear'], ['get', 'population'], ['var', 'lower'], 4, ['var', 'higher'], 8],
|
||||
size: [
|
||||
'interpolate',
|
||||
['linear'],
|
||||
['get', 'population'],
|
||||
['var', 'lower'],
|
||||
4,
|
||||
['var', 'higher'],
|
||||
8,
|
||||
],
|
||||
color: '#336699',
|
||||
opacity: 0.5
|
||||
}
|
||||
opacity: 0.5,
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.builder.uniforms).to.eql(['float u_lower', 'float u_higher']);
|
||||
expect(result.builder.uniforms).to.eql([
|
||||
'float u_lower',
|
||||
'float u_higher',
|
||||
]);
|
||||
expect(result.builder.attributes).to.eql(['float a_population']);
|
||||
expect(result.builder.varyings).to.eql([{
|
||||
name: 'v_population',
|
||||
type: 'float',
|
||||
expression: 'a_population'
|
||||
}]);
|
||||
expect(result.builder.varyings).to.eql([
|
||||
{
|
||||
name: 'v_population',
|
||||
type: 'float',
|
||||
expression: 'a_population',
|
||||
},
|
||||
]);
|
||||
expect(result.builder.colorExpression).to.eql(
|
||||
'vec4(vec4(0.2, 0.4, 0.6, 1.0).rgb, vec4(0.2, 0.4, 0.6, 1.0).a * 0.5 * 1.0)'
|
||||
);
|
||||
@@ -453,7 +496,9 @@ void main(void) {
|
||||
'vec2(mix(4.0, 8.0, pow(clamp((a_population - u_lower) / (u_higher - u_lower), 0.0, 1.0), 1.0)))'
|
||||
);
|
||||
expect(result.builder.offsetExpression).to.eql('vec2(0.0, 0.0)');
|
||||
expect(result.builder.texCoordExpression).to.eql('vec4(0.0, 0.0, 1.0, 1.0)');
|
||||
expect(result.builder.texCoordExpression).to.eql(
|
||||
'vec4(0.0, 0.0, 1.0, 1.0)'
|
||||
);
|
||||
expect(result.builder.rotateWithView).to.eql(false);
|
||||
expect(result.attributes.length).to.eql(1);
|
||||
expect(result.attributes[0].name).to.eql('population');
|
||||
@@ -461,41 +506,55 @@ void main(void) {
|
||||
expect(result.uniforms).to.have.property('u_higher');
|
||||
});
|
||||
|
||||
it('parses a style with a filter', function() {
|
||||
it('parses a style with a filter', function () {
|
||||
const result = parseLiteralStyle({
|
||||
filter: ['between', ['get', 'attr0'], 0, 10],
|
||||
symbol: {
|
||||
symbolType: 'square',
|
||||
size: 6,
|
||||
color: '#336699'
|
||||
}
|
||||
color: '#336699',
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.builder.attributes).to.eql(['float a_attr0']);
|
||||
expect(result.builder.varyings).to.eql([{
|
||||
name: 'v_attr0',
|
||||
type: 'float',
|
||||
expression: 'a_attr0'
|
||||
}]);
|
||||
expect(result.builder.varyings).to.eql([
|
||||
{
|
||||
name: 'v_attr0',
|
||||
type: 'float',
|
||||
expression: 'a_attr0',
|
||||
},
|
||||
]);
|
||||
expect(result.builder.colorExpression).to.eql(
|
||||
'vec4(vec4(0.2, 0.4, 0.6, 1.0).rgb, vec4(0.2, 0.4, 0.6, 1.0).a * 1.0 * 1.0)'
|
||||
);
|
||||
expect(result.builder.sizeExpression).to.eql('vec2(6.0)');
|
||||
expect(result.builder.offsetExpression).to.eql('vec2(0.0, 0.0)');
|
||||
expect(result.builder.texCoordExpression).to.eql('vec4(0.0, 0.0, 1.0, 1.0)');
|
||||
expect(result.builder.discardExpression).to.eql('!(v_attr0 >= 0.0 && v_attr0 <= 10.0)');
|
||||
expect(result.builder.texCoordExpression).to.eql(
|
||||
'vec4(0.0, 0.0, 1.0, 1.0)'
|
||||
);
|
||||
expect(result.builder.discardExpression).to.eql(
|
||||
'!(v_attr0 >= 0.0 && v_attr0 <= 10.0)'
|
||||
);
|
||||
expect(result.builder.rotateWithView).to.eql(false);
|
||||
expect(result.attributes.length).to.eql(1);
|
||||
expect(result.attributes[0].name).to.eql('attr0');
|
||||
});
|
||||
|
||||
it('parses a style with a color interpolation', function() {
|
||||
it('parses a style with a color interpolation', function () {
|
||||
const result = parseLiteralStyle({
|
||||
symbol: {
|
||||
symbolType: 'square',
|
||||
size: 6,
|
||||
color: ['interpolate', ['linear'], ['var', 'ratio'], 0, [255, 255, 0], 1, 'red']
|
||||
}
|
||||
color: [
|
||||
'interpolate',
|
||||
['linear'],
|
||||
['var', 'ratio'],
|
||||
0,
|
||||
[255, 255, 0],
|
||||
1,
|
||||
'red',
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.builder.attributes).to.eql([]);
|
||||
@@ -505,19 +564,21 @@ void main(void) {
|
||||
);
|
||||
expect(result.builder.sizeExpression).to.eql('vec2(6.0)');
|
||||
expect(result.builder.offsetExpression).to.eql('vec2(0.0, 0.0)');
|
||||
expect(result.builder.texCoordExpression).to.eql('vec4(0.0, 0.0, 1.0, 1.0)');
|
||||
expect(result.builder.texCoordExpression).to.eql(
|
||||
'vec4(0.0, 0.0, 1.0, 1.0)'
|
||||
);
|
||||
expect(result.builder.rotateWithView).to.eql(false);
|
||||
expect(result.attributes).to.eql([]);
|
||||
expect(result.uniforms).to.have.property('u_ratio');
|
||||
});
|
||||
|
||||
it('parses a style with a rotation expression using an attribute', function() {
|
||||
it('parses a style with a rotation expression using an attribute', function () {
|
||||
const result = parseLiteralStyle({
|
||||
symbol: {
|
||||
symbolType: 'square',
|
||||
size: 6,
|
||||
rotation: ['get', 'heading']
|
||||
}
|
||||
rotation: ['get', 'heading'],
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.builder.attributes).to.eql(['float a_heading']);
|
||||
@@ -525,29 +586,29 @@ void main(void) {
|
||||
expect(result.builder.rotationExpression).to.eql('a_heading');
|
||||
});
|
||||
|
||||
it('correctly adds string variables to the string literals mapping', function() {
|
||||
it('correctly adds string variables to the string literals mapping', function () {
|
||||
const result = parseLiteralStyle({
|
||||
variables: {
|
||||
mySize: 'abcdef'
|
||||
mySize: 'abcdef',
|
||||
},
|
||||
symbol: {
|
||||
symbolType: 'square',
|
||||
size: ['match', ['var', 'mySize'], 'abc', 10, 'def', 20, 30],
|
||||
color: 'red'
|
||||
}
|
||||
color: 'red',
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.uniforms['u_mySize']()).to.be.greaterThan(0);
|
||||
});
|
||||
|
||||
it('throws when a variable is requested but not present in the style', function(done) {
|
||||
it('throws when a variable is requested but not present in the style', function (done) {
|
||||
const result = parseLiteralStyle({
|
||||
variables: {},
|
||||
symbol: {
|
||||
symbolType: 'square',
|
||||
size: ['var', 'mySize'],
|
||||
color: 'red'
|
||||
}
|
||||
color: 'red',
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -558,13 +619,13 @@ void main(void) {
|
||||
done(true);
|
||||
});
|
||||
|
||||
it('throws when a variable is requested but the style does not have a variables dict', function(done) {
|
||||
it('throws when a variable is requested but the style does not have a variables dict', function (done) {
|
||||
const result = parseLiteralStyle({
|
||||
symbol: {
|
||||
symbolType: 'square',
|
||||
size: ['var', 'mySize'],
|
||||
color: 'red'
|
||||
}
|
||||
color: 'red',
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -575,5 +636,4 @@ void main(void) {
|
||||
done(true);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user