Webgl points layer / allow disabling hit detection
Having hit detection enabled has an overhead as it means continously generating additional render instructions and rendering to an offscreen canvas
This commit is contained in:
@@ -122,7 +122,8 @@ const map = new Map({
|
||||
}),
|
||||
new WebGLPointsLayer({
|
||||
style: style,
|
||||
source: vectorSource
|
||||
source: vectorSource,
|
||||
disableHitDetection: true
|
||||
})
|
||||
],
|
||||
target: document.getElementById('map'),
|
||||
|
||||
@@ -117,7 +117,8 @@ function refreshLayer(newStyle) {
|
||||
const previousLayer = pointsLayer;
|
||||
pointsLayer = new WebGLPointsLayer({
|
||||
source: vectorSource,
|
||||
style: newStyle
|
||||
style: newStyle,
|
||||
disableHitDetection: true
|
||||
});
|
||||
map.addLayer(pointsLayer);
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ import Layer from './Layer.js';
|
||||
* @property {number} [maxResolution] The maximum resolution (exclusive) below which this layer will
|
||||
* be visible.
|
||||
* @property {import("../source/Vector.js").default} [source] Source.
|
||||
* @property {boolean} [disableHitDetection] Setting this to true will provide a slight performance boost, but will
|
||||
* prevent all hit detection on the layer.
|
||||
*/
|
||||
|
||||
|
||||
@@ -75,6 +77,12 @@ class WebGLPointsLayer extends Layer {
|
||||
* @type {import('../webgl/ShaderBuilder.js').StyleParseResult}
|
||||
*/
|
||||
this.parseResult_ = parseLiteralStyle(options.style);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.hitDetectionDisabled_ = !!options.disableHitDetection;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,8 +92,10 @@ class WebGLPointsLayer extends Layer {
|
||||
return new WebGLPointsLayerRenderer(this, {
|
||||
vertexShader: this.parseResult_.builder.getSymbolVertexShader(),
|
||||
fragmentShader: this.parseResult_.builder.getSymbolFragmentShader(),
|
||||
hitVertexShader: this.parseResult_.builder.getSymbolVertexShader(true),
|
||||
hitFragmentShader: this.parseResult_.builder.getSymbolFragmentShader(true),
|
||||
hitVertexShader: !this.hitDetectionDisabled_ &&
|
||||
this.parseResult_.builder.getSymbolVertexShader(true),
|
||||
hitFragmentShader: !this.hitDetectionDisabled_ &&
|
||||
this.parseResult_.builder.getSymbolFragmentShader(true),
|
||||
uniforms: this.parseResult_.uniforms,
|
||||
attributes: this.parseResult_.attributes
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user