|
1 | 1 | import Source from 'Source/Source'; |
2 | 2 | import URLBuilder from 'Provider/URLBuilder'; |
3 | 3 | import Extent from 'Core/Geographic/Extent'; |
| 4 | +import * as CRS from 'Core/Geographic/Crs'; |
4 | 5 |
|
5 | 6 | const _extent = new Extent('EPSG:4326', [0, 0, 0, 0]); |
6 | 7 |
|
| 8 | +/** |
| 9 | + * Proj provides an optional param to define axis order and orientation for a |
| 10 | + * given projection. 'enu' for instance stands for east, north, up. |
| 11 | + * Elevation is not needed here. The two first characters are sufficient to map |
| 12 | + * proj axis to iTowns bbox order formalism. |
| 13 | + * 'enu' corresponds to 'wsen' because bbox starts by lower value coordinates |
| 14 | + * and preserves axis ordering, here long/lat. |
| 15 | + */ |
| 16 | +const projAxisToBboxMappings = { |
| 17 | + en: 'wsen', |
| 18 | + es: 'wnes', |
| 19 | + wn: 'eswn', |
| 20 | + ws: 'enws', |
| 21 | + ne: 'swne', |
| 22 | + se: 'nwse', |
| 23 | + nw: 'senw', |
| 24 | + sw: 'nesw', |
| 25 | +}; |
| 26 | + |
| 27 | +/** |
| 28 | + * Provides the bbox axis order matching provided proj4 axis |
| 29 | + * @param {string} projAxis the CRS axis order as defined in proj4 |
| 30 | + * @returns {string} the corresponding bbox axis order to use for WMS 1.3.0 |
| 31 | + */ |
| 32 | +function projAxisToWmsBbox(projAxis) { |
| 33 | + return projAxis && projAxisToBboxMappings[projAxis.slice(0, 2)] || 'wsen'; |
| 34 | +} |
| 35 | + |
7 | 36 | /** |
8 | 37 | * An object defining the source of images to get from a |
9 | 38 | * [WMS](http://www.opengeospatial.org/standards/wms) server. It inherits |
@@ -104,13 +133,11 @@ class WMSSource extends Source { |
104 | 133 |
|
105 | 134 | if (source.axisOrder) { |
106 | 135 | this.axisOrder = source.axisOrder; |
107 | | - } else if (this.crs == 'EPSG:4326') { |
108 | | - // 4326 (lat/long) axis order depends on the WMS version used |
109 | | - // EPSG 4326 x = lat, long = y |
110 | | - // version 1.X.X long/lat while version 1.3.0 mandates xy (so lat,long) |
111 | | - this.axisOrder = this.version === '1.3.0' ? 'swne' : 'wsen'; |
| 136 | + } else if (this.version === '1.3.0') { // If not set, axis order depends on WMS version |
| 137 | + // Version 1.3.0 depends on CRS axis order as defined in epsg.org database |
| 138 | + this.axisOrder = projAxisToWmsBbox(CRS.axisOrder(this.crs)); |
112 | 139 | } else { |
113 | | - // xy,xy order |
| 140 | + // Versions 1.X.X mandate long/lat order, east-north orientation |
114 | 141 | this.axisOrder = 'wsen'; |
115 | 142 | } |
116 | 143 |
|
|
0 commit comments