Get pixel data
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user