I have a WMS that renders a logo into a corner of all requested images. I want the logo to be visible in the corner of the OpenLayers map. I am upgrading from Openlayes 2.13 to Openlayers 4.6.4

In Openlayers 2 it worked by setting ratio:1, singleTile: true

  var layer = new OpenLayers.Layer.WMS(..., 
    singleTile: true,
    ratio: 1,

In Openlayers 4 I don't get the "ratio:1" option to work.

How can I setup Openlayers 4 to request WMS-images with the exact same size of the map-view?

UPDATE: The current Single Image WMS example in OpenLayers 4 documentation shows a ratio: 1, but it doesn't seem to work for me.

  • 1
    Did you look openlayers.org/en/latest/examples/wms-image.html? There is a reference to ratio 1 in the sample. It could be what you are seeking?! – ThomasG77 Jan 31 '18 at 23:07
  • Thanks, yes, I had seen that, but I tested it thoroughly, and it has no effect. Seems to be a copy&paste bug in the OL 4 example. – alfonx Jan 31 '18 at 23:24
  • The ratio option works as expected for me, i.e. the image from the WMS is requested with the exact same size as the map. Can you show an example where it does not? – ahocevar Feb 10 '18 at 10:17

I finally figured it out by debugging the Single Image WMS example

new ol.layer.Image({
      extent: [-13884991, 2870341, -7455066, 6338219],
      source: new ol.source.ImageWMS({
        url: 'https://ahocevar.com/geoserver/wms',
        params: {'LAYERS': 'topp:states'},
        ratio: 1,
        serverType: 'blabla'

The ratio option only works together with serverType. Even if you don't have a WMS Geoserver. It also works with serverType: 'myserver'. It doesn't work when serverType is undefined.

  • I opened a ticket: github.com/openlayers/openlayers/issues/7755 – alfonx Jan 31 '18 at 23:58
  • Your snippet above does not work at all. However, it works when you remove the invalid serverType. I am unable to verify your observation that the ratio option only works together with serverType. – ahocevar Feb 10 '18 at 10:19
  • Thanks for your reply. I did double check my post when I posted it, but I will double check it again.... next week ... – alfonx Feb 13 '18 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.