Renaming fill and stroke attributes and shaders
This commit is contained in:
@@ -16,7 +16,7 @@ class WebGLLayer extends Layer {
|
|||||||
createRenderer() {
|
createRenderer() {
|
||||||
return new WebGLVectorLayerRenderer(this, {
|
return new WebGLVectorLayerRenderer(this, {
|
||||||
className: this.getClassName(),
|
className: this.getClassName(),
|
||||||
polygonShader: {
|
fill: {
|
||||||
attributes: {
|
attributes: {
|
||||||
[DefaultAttributes.COLOR]: function (feature, properties) {
|
[DefaultAttributes.COLOR]: function (feature, properties) {
|
||||||
const color = asArray(properties.COLOR || '#eee');
|
const color = asArray(properties.COLOR || '#eee');
|
||||||
@@ -28,7 +28,7 @@ class WebGLLayer extends Layer {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
lineStringShader: {
|
stroke: {
|
||||||
attributes: {
|
attributes: {
|
||||||
[DefaultAttributes.COLOR]: function (feature, properties) {
|
[DefaultAttributes.COLOR]: function (feature, properties) {
|
||||||
const color = [...asArray(properties.COLOR || '#eee')];
|
const color = [...asArray(properties.COLOR || '#eee')];
|
||||||
|
|||||||
@@ -10,13 +10,13 @@ import VectorEventType from '../../source/VectorEventType.js';
|
|||||||
import ViewHint from '../../ViewHint.js';
|
import ViewHint from '../../ViewHint.js';
|
||||||
import WebGLLayerRenderer from './Layer.js';
|
import WebGLLayerRenderer from './Layer.js';
|
||||||
import {
|
import {
|
||||||
DEFAULT_LINESTRING_FRAGMENT,
|
|
||||||
DEFAULT_LINESTRING_VERTEX,
|
|
||||||
DEFAULT_POINT_FRAGMENT,
|
|
||||||
DEFAULT_POINT_VERTEX,
|
|
||||||
DEFAULT_POLYGON_FRAGMENT,
|
|
||||||
DEFAULT_POLYGON_VERTEX,
|
|
||||||
DefaultAttributes,
|
DefaultAttributes,
|
||||||
|
FILL_FRAGMENT_SHADER,
|
||||||
|
FILL_VERTEX_SHADER,
|
||||||
|
POINT_FRAGMENT_SHADER,
|
||||||
|
POINT_VERTEX_SHADER,
|
||||||
|
STROKE_FRAGMENT_SHADER,
|
||||||
|
STROKE_VERTEX_SHADER,
|
||||||
packColor,
|
packColor,
|
||||||
} from './shaders.js';
|
} from './shaders.js';
|
||||||
import {DefaultUniform} from '../../webgl/Helper.js';
|
import {DefaultUniform} from '../../webgl/Helper.js';
|
||||||
@@ -43,9 +43,9 @@ import {listen, unlistenByKey} from '../../events.js';
|
|||||||
/**
|
/**
|
||||||
* @typedef {Object} Options
|
* @typedef {Object} Options
|
||||||
* @property {string} [className='ol-layer'] A CSS class name to set to the canvas element.
|
* @property {string} [className='ol-layer'] A CSS class name to set to the canvas element.
|
||||||
* @property {ShaderProgram} [polygonShader] Vertex shaders for polygons; using default shader if unspecified
|
* @property {ShaderProgram} [fill] Attributes and shaders for filling polygons.
|
||||||
* @property {ShaderProgram} [lineStringShader] Vertex shaders for line strings; using default shader if unspecified
|
* @property {ShaderProgram} [stroke] Attributes and shaders for line strings and polygon strokes.
|
||||||
* @property {ShaderProgram} [pointShader] Vertex shaders for points; using default shader if unspecified
|
* @property {ShaderProgram} [point] Attributes and shaders for points.
|
||||||
* @property {Object<string,import("../../webgl/Helper").UniformValue>} [uniforms] Uniform definitions.
|
* @property {Object<string,import("../../webgl/Helper").UniformValue>} [uniforms] Uniform definitions.
|
||||||
* @property {Array<import("./Layer").PostProcessesOptions>} [postProcesses] Post-processes definitions
|
* @property {Array<import("./Layer").PostProcessesOptions>} [postProcesses] Post-processes definitions
|
||||||
*/
|
*/
|
||||||
@@ -96,16 +96,17 @@ class WebGLVectorLayerRenderer extends WebGLLayerRenderer {
|
|||||||
*/
|
*/
|
||||||
this.currentTransform_ = projectionMatrixTransform;
|
this.currentTransform_ = projectionMatrixTransform;
|
||||||
|
|
||||||
const polygonAttributesWithDefault = {
|
const fillAttributes = {
|
||||||
[DefaultAttributes.COLOR]: function () {
|
[DefaultAttributes.COLOR]: function () {
|
||||||
return packColor('#ddd');
|
return packColor('#ddd');
|
||||||
},
|
},
|
||||||
[DefaultAttributes.OPACITY]: function () {
|
[DefaultAttributes.OPACITY]: function () {
|
||||||
return 1;
|
return 1;
|
||||||
},
|
},
|
||||||
...(options.polygonShader && options.polygonShader.attributes),
|
...(options.fill && options.fill.attributes),
|
||||||
};
|
};
|
||||||
const lineAttributesWithDefault = {
|
|
||||||
|
const strokeAttributes = {
|
||||||
[DefaultAttributes.COLOR]: function () {
|
[DefaultAttributes.COLOR]: function () {
|
||||||
return packColor('#eee');
|
return packColor('#eee');
|
||||||
},
|
},
|
||||||
@@ -115,44 +116,41 @@ class WebGLVectorLayerRenderer extends WebGLLayerRenderer {
|
|||||||
[DefaultAttributes.WIDTH]: function () {
|
[DefaultAttributes.WIDTH]: function () {
|
||||||
return 1.5;
|
return 1.5;
|
||||||
},
|
},
|
||||||
...(options.lineStringShader && options.lineStringShader.attributes),
|
...(options.stroke && options.stroke.attributes),
|
||||||
};
|
};
|
||||||
const pointAttributesWithDefault = {
|
|
||||||
|
const pointAttributes = {
|
||||||
[DefaultAttributes.COLOR]: function () {
|
[DefaultAttributes.COLOR]: function () {
|
||||||
return packColor('#eee');
|
return packColor('#eee');
|
||||||
},
|
},
|
||||||
[DefaultAttributes.OPACITY]: function () {
|
[DefaultAttributes.OPACITY]: function () {
|
||||||
return 1;
|
return 1;
|
||||||
},
|
},
|
||||||
...(options.pointShader && options.pointShader.attributes),
|
...(options.point && options.point.attributes),
|
||||||
};
|
};
|
||||||
|
|
||||||
function toAttributesArray(obj) {
|
function toAttributesArray(obj) {
|
||||||
return Object.keys(obj).map((key) => ({name: key, callback: obj[key]}));
|
return Object.keys(obj).map((key) => ({name: key, callback: obj[key]}));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.polygonVertexShader_ =
|
this.fillVertexShader_ =
|
||||||
(options.polygonShader && options.polygonShader.vertexShader) ||
|
(options.fill && options.fill.vertexShader) || FILL_VERTEX_SHADER;
|
||||||
DEFAULT_POLYGON_VERTEX;
|
this.fillFragmentShader_ =
|
||||||
this.polygonFragmentShader_ =
|
(options.fill && options.fill.fragmentShader) || FILL_FRAGMENT_SHADER;
|
||||||
(options.polygonShader && options.polygonShader.fragmentShader) ||
|
this.fillAttributes_ = toAttributesArray(fillAttributes);
|
||||||
DEFAULT_POLYGON_FRAGMENT;
|
|
||||||
this.polygonAttributes_ = toAttributesArray(polygonAttributesWithDefault);
|
|
||||||
|
|
||||||
this.lineStringVertexShader_ =
|
this.strokeVertexShader_ =
|
||||||
(options.lineStringShader && options.lineStringShader.vertexShader) ||
|
(options.stroke && options.stroke.vertexShader) || STROKE_VERTEX_SHADER;
|
||||||
DEFAULT_LINESTRING_VERTEX;
|
this.strokeFragmentShader_ =
|
||||||
this.lineStringFragmentShader_ =
|
(options.stroke && options.stroke.fragmentShader) ||
|
||||||
(options.lineStringShader && options.lineStringShader.fragmentShader) ||
|
STROKE_FRAGMENT_SHADER;
|
||||||
DEFAULT_LINESTRING_FRAGMENT;
|
this.strokeAttributes_ = toAttributesArray(strokeAttributes);
|
||||||
this.lineStringAttributes_ = toAttributesArray(lineAttributesWithDefault);
|
|
||||||
|
|
||||||
this.pointVertexShader_ =
|
this.pointVertexShader_ =
|
||||||
(options.pointShader && options.pointShader.vertexShader) ||
|
(options.point && options.point.vertexShader) || POINT_VERTEX_SHADER;
|
||||||
DEFAULT_POINT_VERTEX;
|
|
||||||
this.pointFragmentShader_ =
|
this.pointFragmentShader_ =
|
||||||
(options.pointShader && options.pointShader.fragmentShader) ||
|
(options.point && options.point.fragmentShader) || POINT_FRAGMENT_SHADER;
|
||||||
DEFAULT_POINT_FRAGMENT;
|
this.pointAttributes_ = toAttributesArray(pointAttributes);
|
||||||
this.pointAttributes_ = toAttributesArray(pointAttributesWithDefault);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -198,9 +196,9 @@ class WebGLVectorLayerRenderer extends WebGLLayerRenderer {
|
|||||||
this.polygonRenderer_ = new PolygonBatchRenderer(
|
this.polygonRenderer_ = new PolygonBatchRenderer(
|
||||||
this.helper,
|
this.helper,
|
||||||
this.worker_,
|
this.worker_,
|
||||||
this.polygonVertexShader_,
|
this.fillVertexShader_,
|
||||||
this.polygonFragmentShader_,
|
this.fillFragmentShader_,
|
||||||
this.polygonAttributes_
|
this.fillAttributes_
|
||||||
);
|
);
|
||||||
this.pointRenderer_ = new PointBatchRenderer(
|
this.pointRenderer_ = new PointBatchRenderer(
|
||||||
this.helper,
|
this.helper,
|
||||||
@@ -212,9 +210,9 @@ class WebGLVectorLayerRenderer extends WebGLLayerRenderer {
|
|||||||
this.lineStringRenderer_ = new LineStringBatchRenderer(
|
this.lineStringRenderer_ = new LineStringBatchRenderer(
|
||||||
this.helper,
|
this.helper,
|
||||||
this.worker_,
|
this.worker_,
|
||||||
this.lineStringVertexShader_,
|
this.strokeVertexShader_,
|
||||||
this.lineStringFragmentShader_,
|
this.strokeFragmentShader_,
|
||||||
this.lineStringAttributes_
|
this.strokeAttributes_
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ const DECODE_COLOR_EXPRESSION = `vec3(
|
|||||||
* Relies on DefaultAttributes.COLOR and DefaultAttributes.OPACITY.
|
* Relies on DefaultAttributes.COLOR and DefaultAttributes.OPACITY.
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
export const DEFAULT_POLYGON_VERTEX = `
|
export const FILL_VERTEX_SHADER = `
|
||||||
precision mediump float;
|
precision mediump float;
|
||||||
uniform mat4 u_projectionMatrix;
|
uniform mat4 u_projectionMatrix;
|
||||||
attribute vec2 a_position;
|
attribute vec2 a_position;
|
||||||
@@ -57,7 +57,7 @@ export const DEFAULT_POLYGON_VERTEX = `
|
|||||||
* Default polygon fragment shader.
|
* Default polygon fragment shader.
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
export const DEFAULT_POLYGON_FRAGMENT = `
|
export const FILL_FRAGMENT_SHADER = `
|
||||||
precision mediump float;
|
precision mediump float;
|
||||||
varying vec3 v_color;
|
varying vec3 v_color;
|
||||||
varying float v_opacity;
|
varying float v_opacity;
|
||||||
@@ -71,7 +71,7 @@ export const DEFAULT_POLYGON_FRAGMENT = `
|
|||||||
* Relies on DefaultAttributes.COLOR, DefaultAttributes.OPACITY and DefaultAttributes.WIDTH.
|
* Relies on DefaultAttributes.COLOR, DefaultAttributes.OPACITY and DefaultAttributes.WIDTH.
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
export const DEFAULT_LINESTRING_VERTEX = `
|
export const STROKE_VERTEX_SHADER = `
|
||||||
precision mediump float;
|
precision mediump float;
|
||||||
uniform mat4 u_projectionMatrix;
|
uniform mat4 u_projectionMatrix;
|
||||||
uniform vec2 u_sizePx;
|
uniform vec2 u_sizePx;
|
||||||
@@ -136,7 +136,7 @@ export const DEFAULT_LINESTRING_VERTEX = `
|
|||||||
* Default linestring fragment shader.
|
* Default linestring fragment shader.
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
export const DEFAULT_LINESTRING_FRAGMENT = `
|
export const STROKE_FRAGMENT_SHADER = `
|
||||||
precision mediump float;
|
precision mediump float;
|
||||||
uniform float u_pixelRatio;
|
uniform float u_pixelRatio;
|
||||||
varying vec2 v_segmentStart;
|
varying vec2 v_segmentStart;
|
||||||
@@ -166,7 +166,7 @@ export const DEFAULT_LINESTRING_FRAGMENT = `
|
|||||||
* Relies on DefaultAttributes.COLOR and DefaultAttributes.OPACITY.
|
* Relies on DefaultAttributes.COLOR and DefaultAttributes.OPACITY.
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
export const DEFAULT_POINT_VERTEX = `
|
export const POINT_VERTEX_SHADER = `
|
||||||
precision mediump float;
|
precision mediump float;
|
||||||
uniform mat4 u_projectionMatrix;
|
uniform mat4 u_projectionMatrix;
|
||||||
uniform mat4 u_offsetScaleMatrix;
|
uniform mat4 u_offsetScaleMatrix;
|
||||||
@@ -196,7 +196,7 @@ export const DEFAULT_POINT_VERTEX = `
|
|||||||
* Default point fragment shader.
|
* Default point fragment shader.
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
export const DEFAULT_POINT_FRAGMENT = `
|
export const POINT_FRAGMENT_SHADER = `
|
||||||
precision mediump float;
|
precision mediump float;
|
||||||
varying vec3 v_color;
|
varying vec3 v_color;
|
||||||
varying float v_opacity;
|
varying float v_opacity;
|
||||||
|
|||||||
Reference in New Issue
Block a user