Get pixel data

This commit is contained in:
Tim Schaub
2022-02-06 16:46:01 -07:00
parent cd45663996
commit eb4d5e0784
23 changed files with 721 additions and 101 deletions
+20
View File
@@ -136,6 +136,26 @@ class BaseTileLayer extends Layer {
setUseInterimTilesOnError(useInterimTilesOnError) {
this.set(TileProperty.USE_INTERIM_TILES_ON_ERROR, useInterimTilesOnError);
}
/**
* Get data for a pixel location. The return type depends on the source data. For image tiles,
* a four element RGBA array will be returned. For data tiles, the array length will match the
* number of bands in the dataset. For requests outside the layer extent, `null` will be returned.
* Data for a image tiles can only be retrieved if the source's `crossOrigin` property is set.
*
* ```js
* // display layer data on every pointer move
* map.on('pointermove', (event) => {
* console.log(layer.getData(event.pixel));
* });
* ```
* @param {import("../pixel").Pixel} pixel Pixel.
* @return {Uint8ClampedArray|Uint8Array|Float32Array|DataView|null} Pixel data.
* @api
*/
getData(pixel) {
return super.getData(pixel);
}
}
export default BaseTileLayer;
+19
View File
@@ -27,6 +27,25 @@ class ImageLayer extends BaseImageLayer {
createRenderer() {
return new CanvasImageLayerRenderer(this);
}
/**
* Get data for a pixel location. A four element RGBA array will be returned. For requests outside the
* layer extent, `null` will be returned. Data for an image can only be retrieved if the
* source's `crossOrigin` property is set.
*
* ```js
* // display layer data on every pointer move
* map.on('pointermove', (event) => {
* console.log(layer.getData(event.pixel));
* });
* ```
* @param {import("../pixel").Pixel} pixel Pixel.
* @return {Uint8ClampedArray|Uint8Array|Float32Array|DataView|null} Pixel data.
* @api
*/
getData(pixel) {
return super.getData(pixel);
}
}
export default ImageLayer;
+11
View File
@@ -250,6 +250,17 @@ class Layer extends BaseLayer {
return this.renderer_.getFeatures(pixel);
}
/**
* @param {import("../pixel").Pixel} pixel Pixel.
* @return {Uint8ClampedArray|Uint8Array|Float32Array|DataView|null} Pixel data.
*/
getData(pixel) {
if (!this.renderer_) {
return null;
}
return this.renderer_.getData(pixel);
}
/**
* In charge to manage the rendering of the layer. One layer type is
* bounded with one layer renderer.