Merge pull request #11545 from fredj/webgl_className

Use the className param in ol.layer.Heatmap
This commit is contained in:
Frédéric Junod
2020-09-11 10:00:30 +02:00
committed by GitHub
5 changed files with 24 additions and 0 deletions

View File

@@ -182,6 +182,7 @@ class Heatmap extends VectorLayer {
*/
createRenderer() {
return new WebGLPointsLayerRenderer(this, {
className: this.getClassName(),
attributes: [
{
name: 'weight',

View File

@@ -96,6 +96,7 @@ class WebGLPointsLayer extends Layer {
*/
createRenderer() {
return new WebGLPointsLayerRenderer(this, {
className: this.getClassName(),
vertexShader: this.parseResult_.builder.getSymbolVertexShader(),
fragmentShader: this.parseResult_.builder.getSymbolFragmentShader(),
hitVertexShader:

View File

@@ -37,6 +37,7 @@ export const WebGLWorkerMessageType = {
/**
* @typedef {Object} Options
* @property {string} [className='ol-layer'] A CSS class name to set to the canvas element.
* @property {Object.<string,import("../../webgl/Helper").UniformValue>} [uniforms] Uniform definitions for the post process steps
* @property {Array<PostProcessesOptions>} [postProcesses] Post-processes definitions
*/
@@ -65,6 +66,10 @@ class WebGLLayerRenderer extends LayerRenderer {
postProcesses: options.postProcesses,
uniforms: options.uniforms,
});
if (options.className !== undefined) {
this.helper.getCanvas().className = options.className;
}
}
/**

View File

@@ -44,6 +44,7 @@ import {listen, unlistenByKey} from '../../events.js';
/**
* @typedef {Object} Options
* @property {string} [className='ol-layer'] A CSS class name to set to the canvas element.
* @property {Array<CustomAttribute>} [attributes] These attributes will be read from the features in the source and then
* passed to the GPU. The `name` property of each attribute will serve as its identifier:
* * In the vertex shader as an `attribute` by prefixing it with `a_`
@@ -131,6 +132,7 @@ class WebGLPointsLayerRenderer extends WebGLLayerRenderer {
uniforms[DefaultUniform.PROJECTION_MATRIX] = projectionMatrixTransform;
super(layer, {
className: options.className,
uniforms: uniforms,
postProcesses: options.postProcesses,
});

View File

@@ -11,6 +11,21 @@ describe('ol.layer.Heatmap', function () {
const instance = new HeatmapLayer();
expect(instance).to.be.an(HeatmapLayer);
});
it('has a default className', function () {
const layer = new HeatmapLayer({
source: new VectorSource(),
});
const canvas = layer.getRenderer().helper.getCanvas();
expect(canvas.className).to.eql('ol-layer');
});
it('accepts a custom className', function () {
const layer = new HeatmapLayer({
source: new VectorSource(),
className: 'a-class-name',
});
const canvas = layer.getRenderer().helper.getCanvas();
expect(canvas.className).to.eql('a-class-name');
});
});
describe('hit detection', function () {