itowns 2.44.3-next.25 → 2.44.3-next.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,12 @@
1
1
  import proj4 from 'proj4';
2
2
  proj4.defs('EPSG:4978', '+proj=geocent +datum=WGS84 +units=m +no_defs');
3
3
 
4
+ // Redefining proj4 global projections to match epsg.org database axis order.
5
+ // See https://github.com/iTowns/itowns/pull/2465#issuecomment-2517024859
6
+ proj4.defs('EPSG:4326').axis = 'neu';
7
+ proj4.defs('EPSG:4269').axis = 'neu';
8
+ proj4.defs('WGS84').axis = 'neu';
9
+
4
10
  /**
5
11
  * A projection as a CRS identifier string. This identifier references a
6
12
  * projection definition previously defined with
@@ -133,6 +139,19 @@ export function reasonableEpsilon(crs) {
133
139
  }
134
140
  }
135
141
 
142
+ /**
143
+ * Returns the axis parameter defined in proj4 for the provided crs.
144
+ * Might be undefined depending on crs definition.
145
+ *
146
+ * @param crs - The CRS to get axis from.
147
+ * @returns the matching proj4 axis string, 'enu' for instance (east, north, up)
148
+ */
149
+ export function axisOrder(crs) {
150
+ mustBeString(crs);
151
+ const projection = proj4.defs(crs);
152
+ return !projection ? undefined : projection.axis;
153
+ }
154
+
136
155
  /**
137
156
  * Defines a proj4 projection as a named alias.
138
157
  * This function is a specialized wrapper over the
@@ -1,8 +1,37 @@
1
1
  import Source from "./Source.js";
2
2
  import URLBuilder from "../Provider/URLBuilder.js";
3
3
  import Extent from "../Core/Geographic/Extent.js";
4
+ import * as CRS from "../Core/Geographic/Crs.js";
4
5
  const _extent = new Extent('EPSG:4326', [0, 0, 0, 0]);
5
6
 
7
+ /**
8
+ * Proj provides an optional param to define axis order and orientation for a
9
+ * given projection. 'enu' for instance stands for east, north, up.
10
+ * Elevation is not needed here. The two first characters are sufficient to map
11
+ * proj axis to iTowns bbox order formalism.
12
+ * 'enu' corresponds to 'wsen' because bbox starts by lower value coordinates
13
+ * and preserves axis ordering, here long/lat.
14
+ */
15
+ const projAxisToBboxMappings = {
16
+ en: 'wsen',
17
+ es: 'wnes',
18
+ wn: 'eswn',
19
+ ws: 'enws',
20
+ ne: 'swne',
21
+ se: 'nwse',
22
+ nw: 'senw',
23
+ sw: 'nesw'
24
+ };
25
+
26
+ /**
27
+ * Provides the bbox axis order matching provided proj4 axis
28
+ * @param {string} projAxis the CRS axis order as defined in proj4
29
+ * @returns {string} the corresponding bbox axis order to use for WMS 1.3.0
30
+ */
31
+ function projAxisToWmsBbox(projAxis) {
32
+ return projAxis && projAxisToBboxMappings[projAxis.slice(0, 2)] || 'wsen';
33
+ }
34
+
6
35
  /**
7
36
  * An object defining the source of images to get from a
8
37
  * [WMS](http://www.opengeospatial.org/standards/wms) server. It inherits
@@ -97,16 +126,15 @@ class WMSSource extends Source {
97
126
  this.version = source.version || '1.3.0';
98
127
  this.transparent = source.transparent || false;
99
128
  this.bboxDigits = source.bboxDigits;
100
- if (!source.axisOrder) {
101
- // 4326 (lat/long) axis order depends on the WMS version used
102
- if (this.crs == 'EPSG:4326') {
103
- // EPSG 4326 x = lat, long = y
104
- // version 1.X.X long/lat while version 1.3.0 mandates xy (so lat,long)
105
- this.axisOrder = this.version === '1.3.0' ? 'swne' : 'wsen';
106
- } else {
107
- // xy,xy order
108
- this.axisOrder = 'wsen';
109
- }
129
+ if (source.axisOrder) {
130
+ this.axisOrder = source.axisOrder;
131
+ } else if (this.version === '1.3.0') {
132
+ // If not set, axis order depends on WMS version
133
+ // Version 1.3.0 depends on CRS axis order as defined in epsg.org database
134
+ this.axisOrder = projAxisToWmsBbox(CRS.axisOrder(this.crs));
135
+ } else {
136
+ // Versions 1.X.X mandate long/lat order, east-north orientation
137
+ this.axisOrder = 'wsen';
110
138
  }
111
139
  const crsPropName = this.version === '1.3.0' ? 'CRS' : 'SRS';
112
140
  const urlObj = new URL(this.url);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "itowns",
3
- "version": "2.44.3-next.25",
3
+ "version": "2.44.3-next.26",
4
4
  "description": "A JS/WebGL framework for 3D geospatial data visualization",
5
5
  "type": "module",
6
6
  "main": "lib/Main.js",