I am trying to use the DrawExtent interaction in OpenLayers5 to define the BBOX parameter of a WMS/WCS request to Geoserver. Using this technique I am able to retrieve the image subset I need with a custom WMS url, but when I set the BBOX in the params property of ImageWMS, the response defaults to the entire image.
I have tried using a "custom" url:
'http://localhost:8080/geoserver/wms'+
'?request=GetMap'+
'&service=WMS'+
'&version=1.3.0'+
'&layers='+name+
'&styles=""'+
'&crs=EPSG:3857'+
->'&bbox='+bounds+
'&width=665'+
'&height=551'+
'&format=image/geotiff';
to request the same subset which does work, but I cannot seem to get OpenLayers to recognize the GeoTIFF response as a layer (using ol.source.Image() and ol.layer.Image()). Thus I default back to ol.source.ImageWMS() which provides a param property that I can set BBOX to a string of coordinates. The issue is that these are overwritten(?) and the request is sent with BBOX defined as the image extent.
DRAW BOX EXTENT INTERACTION
var extent = new ol.interaction.Extent({
condition: ol.events.conditions
});
map.addInteraction(extent);
extent.setActive(false);
window.addEventListener('keydown', function(event) {
if (event.keyCode == 16) {
extent.setActive(true);
}
});
window.addEventListener('keyup', function(event) {
if (event.keyCode == 16) {
extent.setActive(false);
var bbox = extent.getExtent();
bbox[0]=Math.round(bbox[0]);
bbox[1]=Math.round(bbox[1]);
bbox[2]=Math.round(bbox[2]);
bbox[3]=Math.round(bbox[3]);
var bboxString = bbox.toString();
getWMS('nurc:Img_Sample',bboxString);
};
});
WMS GET MAP
function getWMS(name,bounds) {
var wmsSource = new ol.source.ImageWMS({
url: 'http://localhost:8080/geoserver/wms',
params: {LAYERS:name, BBOX:bounds, CRS:'EPSG:3857'},
serverType: 'geoserver'
crossOrigin: 'anonymous'
});
var wmsLayer = new ol.layer.Image({
source: wmsSource
});
map.addLayer(wmsLayer);
};
The WMS request should have the BBOX property set to the bounds passed by the extent interaction, but the actual url is overwritten with the bounds of nurc:img_Sample