[GIS] openlayers 4.2 400 Error Code (Bad request)

openlayerswms

I'm trying to load a WMS in my application, but I get the following error:

400 (Bad Request)

Confusingly enough I still get an empty image.

The corresponding request is:

http://sg.geodatenzentrum.de/wms_dop40?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&FORMAT=image/png&TRANSPARENT=true&LAYERS=rgb&WIDTH=256&HEIGHT=256&SRS=EPSG:4326&STYLES=&BBOX=112.5,33.75,123.75,45

I've tried setting layer projection parameters to 3857, 4326, 900913 and 25832 but none worked. QGIS also doesn't seem to like the WMS either.
So I tried simple getMap requests in my browser and the following worked:

http://sg.geodatenzentrum.de/wms_dop40?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&FORMAT=image/png&TRANSPARENT=true&LAYERS=rgb&WIDTH=256&HEIGHT=256&SRS=EPSG:4326&STYLES=&BBOX=5.625,50.625,11.25,56.25

The only difference I could find was a different BBOX parameter.

Does Openlayers create a wrong BBOX parameter or what do I have to change in my code?

var view = new ol.View({
    center: ol.proj.fromLonLat([10, 51]),
    zoom: 6,
    maxZoom: 11,
    projection: 'EPSG:3857'
});

var luftbilder = new ol.layer.Tile({
    source: new ol.source.TileWMS({
        url: 'http://sg.geodatenzentrum.de/wms_dop40?',
        params: {'LAYERS': 'rgb',
                'VERSION': '1.1.1',
                },
        projection: 'EPSG:4326'

    })  
});

var map = new ol.Map({
    target: 'map',
    view: view,
    layers: [luftbilder]
});

weird, fiddle works fine fiddle (in Chrome)

Best Answer

If you are seeing a 400 error from the server then you can't also get an image (blank or otherwise). I see some sort of access control error when I try your links.

BUT

If you check the capabilities document for the WMS you will see the supported bounding box is

<LatLonBoundingBox minx="5.42587260523" miny="46.9672880527" maxx="15.7908768234" maxy="55.1764096793" />

So it seems that your bounding box (BBOX=112.5,33.75,123.75,45) does not intersect the available map data, so you get a blank image.

In any case this will all fail to display (correctly) as you are requesting the map in degrees (epsg:4326) but your map is in meters (epsg:3857). Try removing the projection line in your layer and let the WMS server send the map in the map projection.

Related Question