I have layer (ImageWMS that has GeoTIFF format) and also OSM or another for my baselayer. According to https://openlayers.org/en/latest/examples/disable-image-smoothing.html I should get pixel[0] and pixel[1] and pixel[2] to calculate height . But I have an image layer and when clicked on image layer I received pixel values of base layer not image layer. So I added filter to my codes for showing just image layer's pixel value but console show me (NON). How can I find the pixel value of image layer or better way for calculate height from image layer (raster layer .tiff)?
Here is my code :
const UnTiled = new ol.layer.Image({
opacity:0.9,
title:'UnTiled',
source: new ol.source.ImageWMS({
ratio: 1,
url: 'http://localhost:8080/geoserver/world/wms',
params: {
'VERSION': '1.1.1',
"STYLES": '',
"LAYERS": 'world:world',
"exceptions": 'application/vnd.ogc.se_inimage',
}
})
});map.addLayer(UnTiled);
map.on('singleclick', function(evt) {
map.forEachLayerAtPixel(
evt.pixel,
function (layer, pixel) {
var height =
-10000 + (pixel[0] * 256 * 256 + pixel[1] * 256 + pixel[2]) * 0.1;
console.log(height)
},
{
layerFilter: function (layer) {
return layer === UnTiled;
},
}
);
})
className
in the overlay layer options to ensure it is rendered on separate canvas. You are need theimageSmoothing: false
option otherwise the browser will smooth the output and the pixel values will be meaningless. PNG is correct to display the WMS as most browsers cannot display TIFF.