Webgl / return 0 if doing renderTarget.read outside of data width/height

This would happen when WebGLPointsLayerRenderer.forEachFeatureAtCoordinate
is called on "warped" worlds at -360/+360 degrees, and may produce false
positives.
This commit is contained in:
Olivier Guyot
2019-10-31 13:27:57 +01:00
parent f7b0f6750b
commit 43010c8934
2 changed files with 26 additions and 0 deletions

View File

@@ -115,12 +115,18 @@ class WebGLRenderTarget {
/**
* Reads one pixel of the frame buffer as an array of r, g, b, a components
* in the 0-255 range (unsigned byte).
* If x and/or y are outside of existing data, an array filled with 0 is returned.
* @param {number} x Pixel coordinate
* @param {number} y Pixel coordinate
* @returns {Uint8Array} Integer array with one color value (4 components)
* @api
*/
readPixel(x, y) {
if (x < 0 || y < 0 || x > this.size_[0] || y >= this.size_[1]) {
tmpArray4[0] = tmpArray4[1] = tmpArray4[2] = tmpArray4[3] = 0;
return tmpArray4;
}
this.readAll();
const index = Math.floor(x) + (this.size_[1] - Math.floor(y) - 1) * this.size_[0];
tmpArray4[0] = this.data_[index * 4];