0

I am trying to understand the setting of ratio in ol.source.ImageWMS but I am not succeeding. I already understand the ratio: 1, as there is not much to understand there. ratio: 1 = browser viewbox. I also understand the principle of ratio: 2.

Ratio. 1 means image requests are the size of the map viewport, 2 means twice the width and height of the map viewport, and so on. Must be 1 or higher.

The Data of a BBOX is sent in the URL-querystring at the server request. But it seems that these are not the coordinates of the BBOX from the ratio. Or is it? If no, then I ask how the data of the ratio BBOX can be calculated?

What I need is the data for cropping. So far I had no success to calculate them.

This calculation does not provide the correct data for cropping:

var ImageWMS_ratio = 2; // range 1 - 2

var mapsize_width = map.getSize()[0];
var mapsize_height = map.getSize()[1];

var mapsize_width_ratio = (mapsize_width * (ImageWMS_ratio - 1));
var mapsize_height_ratio = (mapsize_height * (ImageWMS_ratio - 1));

/*
// In this example without if() rules.
// The if() rules are calculated with the BBOX data from the URL-Querystring and map.getPixelFromCoordinate([]);
// If a Image edge outside the BBOX, then cropping, otherwise = 0.
*/
var left_crop = (mapsize_width_ratio * -1);
var bottom_crop = (mapsize_height + mapsize_height_ratio);
var right_crop = (mapsize_width + mapsize_width_ratio);
var top_crop = (mapsize_height_ratio * -1);

Note: For all those who think that the WMS calculates this: No WMS is used. The cropping data is needed.

Here are three graphics that clarify the whole thing. I visualized it with a ratio greater than 1 and in 3 zoom levels.
Picture 1: The image is inside the browser viewbox.
Picture 2: The image is outside the browser viewbox and inside the ratio BBOX (i think).
Picture 3: The image is outside the browser viewbox and outside the ratio BBOX (i think). Cropping is necessary.

enter image description here

enter image description here

enter image description here

7
  • Can you further clarify what you want to achieve, looking at your third example, is it that you've made a GetMap request, it has returned an image (that fits the green box) and then in OpenLayers you want to remove part of that image (the red bit)?
    – nmtoken
    Commented May 23, 2022 at 13:39
  • @nmtoken, the first, i will understand it. I have a PHP script that delivers a scaled and/or croped image. It works fine with ratio:1, but had problems with ratio greater 1, also already without cropping. I don't understand the logic of ratio greater 1. First also i will understand it for coding a calculation. Last, i need the data, to scale and crop the images correctly. I don't use a WMS. The BBOX data for the images and there names are in a array in the Javascript code. In the ol.source.ImageWMS i can use the imageLoadFunction for calculation the data and send it to the server.
    – Suka
    Commented May 25, 2022 at 15:08
  • I'm confused by the statement No WMS is used. Does your PHP script provide an OGC Web Map Service (WMS) interface or not?
    – nmtoken
    Commented May 25, 2022 at 17:36
  • My PHP script does'nt OGC or similar. It is very simple. Look here: github.com/openlayers/openlayers/issues/13675 . I send the required data with the imageLoadFunction and use the existing URL-query keys:values.
    – Suka
    Commented May 26, 2022 at 12:37
  • I removed the tag wms, which is specific to the OGC WMS specification. I guess you're in uncharted territory now, OpenLayers ImageWMS is expecting an OGC WMS but you're not using one
    – nmtoken
    Commented May 26, 2022 at 15:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.