0

I have a WMS layer which have a different axis-orientation to the one that OpenLayers sends out in the BBOX-request.

Openlayers uses the BBOX (minx,miny,maxx,maxy): BBOX=1438239.124213878%2C7895639.273745567%2C1448023.0638343806%2C7905423.213366069

But to get my map-tiles I have to swap the axis-order to this (miny,minx,maxy,maxy):

BBOX=7895639.273745567%2C1438239.124213878%2C7905423.213366069%2C1448023.0638343806

The x and y should change order in the request. Is there any simple solution to this?

I´ve tried to read other questions, but most requests is to change the coordinate system, which I´m not interested in.

Also, the same question I have is posted here: How change axis/coordinates/xy order for a particular layer in a Map?

But that is referring to OpenLayers 2.

  • 2
    Which coordinate system you are using, and have you defined WMS to use version 1.1 or 1.3? – user30184 Dec 19 '18 at 11:49
  • The WMS can be dinfined in a lot of different CRS, but to make it easy the coordinatesystem is currently 3857. And yes, the version is defined: source: new ol.source.TileWMS({ url: 'Myurl', params: { 'VERSION': '1.3.0', 'LAYERS': 'wmslayer', 'TILED': true, 'STYLES': '', 'FORMAT': 'image/png' } }) – Eetmyhouse Dec 19 '18 at 12:06
  • Is your place of interest in the Southern Sweden or close to the Western coast of India? – user30184 Dec 19 '18 at 12:53
  • Sweden is correct – Eetmyhouse Dec 19 '18 at 12:58
  • In that case the BBOX that is created by OpenLayers is correct and you shoud fix the non-standard WMS service instead epsg.io/… – user30184 Dec 19 '18 at 13:09
0

Openlayers uses the BBOX (minx,miny,maxx,maxy)

So does WMS version 1.3.0:

7.2.4.6.8 BoundingBox

WMS service metadata shall declare one or more bounding boxes (as defined in 6.7.4) for each Layer. A Bounding Box metadata element may either be stated explicitly or may be inherited from a parent Layer. In XML, the metadata element includes the following attributes:

⎯ CRS indicates the Layer CRS that applies to this bounding box.

⎯ minx, miny, maxx, maxy indicate the limits of the bounding box using the axis units and order of the specified CRS.

⎯ resx and resy (optional) indicate the spatial resolution of the data comprising the layer in those same units.

And indeed WMS 1.1.1:

7.2.3.6 BBOX

The required BBOX parameter allows a Client to request a particular Bounding Box. Bounding Boxes are defined in the Basic Service Elements section. The value of the BBOX parameter in a GetMap request is a list of comma-separated numbers of the form "minx,miny,maxx,maxy".

The difference between the two standards is not the order of the x,y in the request, it's the potential difference between the definition of which axis (Easting/Northing, Latitude/Longitude, ...) constitutes x or y.

In WMS 1.1.1 the axis order is set as X=longitude (easting) and Y=latitude (northing), even if the actual axis order specified in the coordinate reference system is the other way around... In WMS 1.3.0 the axis order is specified according to the coordinate reference system definition.

So...

urn:ogc:def:crs:EPSG::3857 defines its axes as first axis "easting (X)" and second axis "northing (Y)"

Assuming you are using EPSG::3857, there should be no difference to your application if you use a WMS 1.1.1 or WMS 1.3.0.

Assuming OpenLayers is expecting x=Longitude/Easting, and you are using EPSG::3857, then if your data is displaying in the wrong location, the issue is with the WMS.

  • Yes, not all WMS comply with standards, and if it's not your own service and you need to use it that's a problem. As mentioned in the question OpenLayers 2 had a one line solution which is not available in OL3+. – Mike Dec 24 '18 at 14:51
0

If you don't have access to the server to fix the non-standard WMS you can use a custom tile url function to swap the bbox coordinates. This should work for a standard tile grid with square tiles and centered at [0,0].

var defaultUrlFunction = source.getTileUrlFunction().bind(source);
source.setTileUrlFunction( function(tileCoord, pixelRatio, projection) {
    var coord = ol.extent.getCenter(this.getTileGrid().getTileCoordExtent(tileCoord)).reverse();
    var newTileCoord = this.getTileGrid().getTileCoordForCoordAndZ(coord, tileCoord[0]);
    return defaultUrlFunction(newTileCoord, pixelRatio, projection);
});

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.