ol 10.2.2-dev.1730915520848 → 10.2.2-dev.1730934210683

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.
package/geom/Geometry.js CHANGED
@@ -330,11 +330,11 @@ class Geometry extends BaseObject {
330
330
  tmpTransform,
331
331
  outCoordinates,
332
332
  );
333
- return getTransform(sourceProj, destination)(
334
- transformed,
335
- transformed,
336
- stride,
337
- );
333
+ const projTransform = getTransform(sourceProj, destination);
334
+ if (projTransform) {
335
+ return projTransform(transformed, transformed, stride);
336
+ }
337
+ return transformed;
338
338
  }
339
339
  : getTransform(sourceProj, destination);
340
340
  this.applyTransform(transformFn);
package/math.d.ts CHANGED
@@ -101,4 +101,12 @@ export function floor(n: number, decimals: number): number;
101
101
  * @return {number} The next bigger integer.
102
102
  */
103
103
  export function ceil(n: number, decimals: number): number;
104
+ /**
105
+ * Wraps a number between some minimum and maximum values.
106
+ * @param {number} n The number to wrap.
107
+ * @param {number} min The minimum of the range (inclusive).
108
+ * @param {number} max The maximum of the range (exclusive).
109
+ * @return {number} The wrapped number.
110
+ */
111
+ export function wrap(n: number, min: number, max: number): number;
104
112
  //# sourceMappingURL=math.d.ts.map
package/math.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"math.d.ts","sourceRoot":"","sources":["math.js"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;GAOG;AACH,6BANW,MAAM,OACN,MAAM,OACN,MAAM,GACL,MAAM,CAKjB;AAED;;;;;;;;;;GAUG;AACH,0CARW,MAAM,KACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACL,MAAM,CAgBjB;AAED;;;;;;;GAOG;AACH,oCANW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACL,MAAM,CAMjB;AAED;;;;;;GAMG;AACH,uCAJW,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAEnB,KAAK,CAAC,MAAM,CAAC,GAAC,IAAI,CAgD7B;AAED;;;;;GAKG;AACH,0CAHW,MAAM,GACL,MAAM,CAIjB;AAED;;;;;GAKG;AACH,0CAHW,MAAM,GACL,MAAM,CAIjB;AAED;;;;;;GAMG;AACH,0BAJW,MAAM,KACN,MAAM,GACL,MAAM,CAKjB;AAED;;;;;;;GAOG;AACH,wBALW,MAAM,KACN,MAAM,KACN,MAAM,GACL,MAAM,CAIjB;AAED;;;;;GAKG;AACH,2BAJW,MAAM,YACN,MAAM,GACL,MAAM,CAKjB;AAED;;;;;;GAMG;AACH,yBAJW,MAAM,YACN,MAAM,GACL,MAAM,CAIjB;AAED;;;;;;GAMG;AACH,yBAJW,MAAM,YACN,MAAM,GACL,MAAM,CAIjB;AAED;;;;;;GAMG;AACH,wBAJW,MAAM,YACN,MAAM,GACL,MAAM,CAIjB"}
1
+ {"version":3,"file":"math.d.ts","sourceRoot":"","sources":["math.js"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;GAOG;AACH,6BANW,MAAM,OACN,MAAM,OACN,MAAM,GACL,MAAM,CAKjB;AAED;;;;;;;;;;GAUG;AACH,0CARW,MAAM,KACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACL,MAAM,CAgBjB;AAED;;;;;;;GAOG;AACH,oCANW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,GACL,MAAM,CAMjB;AAED;;;;;;GAMG;AACH,uCAJW,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAEnB,KAAK,CAAC,MAAM,CAAC,GAAC,IAAI,CAgD7B;AAED;;;;;GAKG;AACH,0CAHW,MAAM,GACL,MAAM,CAIjB;AAED;;;;;GAKG;AACH,0CAHW,MAAM,GACL,MAAM,CAIjB;AAED;;;;;;GAMG;AACH,0BAJW,MAAM,KACN,MAAM,GACL,MAAM,CAKjB;AAED;;;;;;;GAOG;AACH,wBALW,MAAM,KACN,MAAM,KACN,MAAM,GACL,MAAM,CAIjB;AAED;;;;;GAKG;AACH,2BAJW,MAAM,YACN,MAAM,GACL,MAAM,CAKjB;AAED;;;;;;GAMG;AACH,yBAJW,MAAM,YACN,MAAM,GACL,MAAM,CAIjB;AAED;;;;;;GAMG;AACH,yBAJW,MAAM,YACN,MAAM,GACL,MAAM,CAIjB;AAED;;;;;;GAMG;AACH,wBAJW,MAAM,YACN,MAAM,GACL,MAAM,CAIjB;AAED;;;;;;GAMG;AACH,wBALW,MAAM,OACN,MAAM,OACN,MAAM,GACL,MAAM,CAQjB"}
package/math.js CHANGED
@@ -197,3 +197,18 @@ export function floor(n, decimals) {
197
197
  export function ceil(n, decimals) {
198
198
  return Math.ceil(toFixed(n, decimals));
199
199
  }
200
+
201
+ /**
202
+ * Wraps a number between some minimum and maximum values.
203
+ * @param {number} n The number to wrap.
204
+ * @param {number} min The minimum of the range (inclusive).
205
+ * @param {number} max The maximum of the range (exclusive).
206
+ * @return {number} The wrapped number.
207
+ */
208
+ export function wrap(n, min, max) {
209
+ if (n >= min && n < max) {
210
+ return n;
211
+ }
212
+ const range = max - min;
213
+ return ((((n - min) % range) + range) % range) + min;
214
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ol",
3
- "version": "10.2.2-dev.1730915520848",
3
+ "version": "10.2.2-dev.1730934210683",
4
4
  "description": "OpenLayers mapping library",
5
5
  "keywords": [
6
6
  "map",
@@ -58,28 +58,30 @@ export type Options = {
58
58
  */
59
59
  /**
60
60
  * @classdesc
61
- * Projection definition class. One of these is created for each projection
62
- * supported in the application and stored in the {@link module:ol/proj} namespace.
63
- * You can use these in applications, but this is not required, as API params
64
- * and options use {@link module:ol/proj~ProjectionLike} which means the simple string
65
- * code will suffice.
61
+ * In most cases, you should not need to create instances of this class.
62
+ * Instead, where projection information is required, you can use a string
63
+ * projection code or identifier (e.g. `EPSG:4326`) instead of a projection
64
+ * instance.
66
65
  *
67
- * You can use {@link module:ol/proj.get} to retrieve the object for a particular
68
- * projection.
66
+ * The library includes support for transforming coordinates between the following
67
+ * projections:
69
68
  *
70
- * The library includes definitions for `EPSG:4326` and `EPSG:3857`, together
71
- * with the following aliases:
72
- * * `EPSG:4326`: CRS:84, urn:ogc:def:crs:EPSG:6.6:4326,
73
- * urn:ogc:def:crs:OGC:1.3:CRS84, urn:ogc:def:crs:OGC:2:84,
74
- * http://www.opengis.net/gml/srs/epsg.xml#4326,
75
- * urn:x-ogc:def:crs:EPSG:4326
76
- * * `EPSG:3857`: EPSG:102100, EPSG:102113, EPSG:900913,
77
- * urn:ogc:def:crs:EPSG:6.18:3:3857,
78
- * http://www.opengis.net/gml/srs/epsg.xml#3857
69
+ * * WGS 84 / Geographic - Using codes `EPSG:4326`, `CRS:84`, `urn:ogc:def:crs:EPSG:6.6:4326`,
70
+ * `urn:ogc:def:crs:OGC:1.3:CRS84`, `urn:ogc:def:crs:OGC:2:84`, `http://www.opengis.net/gml/srs/epsg.xml#4326`,
71
+ * or `urn:x-ogc:def:crs:EPSG:4326`
72
+ * * WGS 84 / Spherical Mercator - Using codes `EPSG:3857`, `EPSG:102100`, `EPSG:102113`, `EPSG:900913`,
73
+ * `urn:ogc:def:crs:EPSG:6.18:3:3857`, or `http://www.opengis.net/gml/srs/epsg.xml#3857`
74
+ * * WGS 84 / UTM zones - Using codes `EPSG:32601` through `EPSG:32660` for northern zones
75
+ * and `EPSG:32701` through `EPSG:32760` for southern zones. Note that the built-in UTM transforms
76
+ * are lower accuracy (with errors on the order of 0.1 m) than those that you might get in a
77
+ * library like [proj4js](https://github.com/proj4js/proj4js).
79
78
  *
80
- * If you use [proj4js](https://github.com/proj4js/proj4js), aliases can
81
- * be added using `proj4.defs()`. After all required projection definitions are
82
- * added, call the {@link module:ol/proj/proj4.register} function.
79
+ * For additional projection support, or to use higher accuracy transforms than the built-in ones, you can use
80
+ * the [proj4js](https://github.com/proj4js/proj4js) library. With `proj4js`, after adding any new projection
81
+ * definitions, call the {@link module:ol/proj/proj4.register} function.
82
+ *
83
+ * You can use the {@link module:ol/proj.get} function to retrieve a projection instance
84
+ * for one of the registered projections.
83
85
  *
84
86
  * @api
85
87
  */
@@ -1 +1 @@
1
- {"version":3,"file":"Projection.d.ts","sourceRoot":"","sources":["Projection.js"],"names":[],"mappings":";;;;;UAOc,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAUG,MAAM,QAAE,OAAO,kBAAkB,EAAE,UAAU,KAAE,MAAM;;AAZ5E;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH;IACE;;OAEG;IACH,qBAFW,OAAO,EAyEjB;IAtEC;;;OAGG;IACH,cAAyB;IAEzB;;;;;;OAMG;IACH,eAAuE;IAEvE;;;;;;OAMG;IACH,gBAAmE;IAEnE;;;;;;OAMG;IACH,qBACgE;IAEhE;;;OAGG;IACH,yBACyE;IAEzE;;;OAGG;IACH,gBAAoE;IAEpE;;;OAGG;IACH,kBAAiD;IAEjD;;;OAGG;IACH,gCAAyD;IAEzD;;;OAGG;IACH,yBAA4B;IAE5B;;;OAGG;IACH,uBAA2C;IAG7C;;OAEG;IACH,YAFY,OAAO,CAIlB;IAED;;;;OAIG;IACH,WAHY,MAAM,CAKjB;IAED;;;;OAIG;IACH,aAHY,OAAO,cAAc,EAAE,MAAM,CAKxC;IAED;;;;OAIG;IACH,YAHY,OAAO,YAAY,EAAE,KAAK,CAKrC;IAED;;;;;;OAMG;IACH,oBAHY,MAAM,GAAC,SAAS,CAK3B;IAED;;;;OAIG;IACH,kBAHY,OAAO,cAAc,EAAE,MAAM,CAKxC;IAED;;;;;;;;;;OAUG;IACH,sBAHY,MAAM,CAKjB;IAED;;;;OAIG;IACH,YAHY,OAAO,CAKlB;IAED;;;;OAIG;IACH,kBAHW,OAAO,QAMjB;IAED;;OAEG;IACH,sBAFY,OAAO,yBAAyB,EAAE,OAAO,CAIpD;IAED;;OAEG;IACH,6BAFW,OAAO,yBAAyB,EAAE,OAAO,QAInD;IAED;;;;OAIG;IACH,kBAHW,OAAO,cAAc,EAAE,MAAM,QAMvC;IAED;;;;;OAKG;IACH,4BAJW,OAAO,cAAc,EAAE,MAAM,QAMvC;IAED;;;;;OAKG;IACH,4BAHW,CAAS,IAAM,EAAN,MAAM,EAAE,IAAqC,EAArC,OAAO,kBAAkB,EAAE,UAAU,KAAE,MAAM,QAKxE;IAED;;;;OAIG;IACH,0BAHY,CAAS,IAAM,EAAN,MAAM,EAAE,IAAqC,EAArC,OAAO,kBAAkB,EAAE,UAAU,KAAE,MAAM,GAAC,SAAS,CAKnF;CACF"}
1
+ {"version":3,"file":"Projection.d.ts","sourceRoot":"","sources":["Projection.js"],"names":[],"mappings":";;;;;UAOc,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iCAUG,MAAM,QAAE,OAAO,kBAAkB,EAAE,UAAU,KAAE,MAAM;;AAZ5E;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH;IACE;;OAEG;IACH,qBAFW,OAAO,EAyEjB;IAtEC;;;OAGG;IACH,cAAyB;IAEzB;;;;;;OAMG;IACH,eAAuE;IAEvE;;;;;;OAMG;IACH,gBAAmE;IAEnE;;;;;;OAMG;IACH,qBACgE;IAEhE;;;OAGG;IACH,yBACyE;IAEzE;;;OAGG;IACH,gBAAoE;IAEpE;;;OAGG;IACH,kBAAiD;IAEjD;;;OAGG;IACH,gCAAyD;IAEzD;;;OAGG;IACH,yBAA4B;IAE5B;;;OAGG;IACH,uBAA2C;IAG7C;;OAEG;IACH,YAFY,OAAO,CAIlB;IAED;;;;OAIG;IACH,WAHY,MAAM,CAKjB;IAED;;;;OAIG;IACH,aAHY,OAAO,cAAc,EAAE,MAAM,CAKxC;IAED;;;;OAIG;IACH,YAHY,OAAO,YAAY,EAAE,KAAK,CAKrC;IAED;;;;;;OAMG;IACH,oBAHY,MAAM,GAAC,SAAS,CAK3B;IAED;;;;OAIG;IACH,kBAHY,OAAO,cAAc,EAAE,MAAM,CAKxC;IAED;;;;;;;;;;OAUG;IACH,sBAHY,MAAM,CAKjB;IAED;;;;OAIG;IACH,YAHY,OAAO,CAKlB;IAED;;;;OAIG;IACH,kBAHW,OAAO,QAMjB;IAED;;OAEG;IACH,sBAFY,OAAO,yBAAyB,EAAE,OAAO,CAIpD;IAED;;OAEG;IACH,6BAFW,OAAO,yBAAyB,EAAE,OAAO,QAInD;IAED;;;;OAIG;IACH,kBAHW,OAAO,cAAc,EAAE,MAAM,QAMvC;IAED;;;;;OAKG;IACH,4BAJW,OAAO,cAAc,EAAE,MAAM,QAMvC;IAED;;;;;OAKG;IACH,4BAHW,CAAS,IAAM,EAAN,MAAM,EAAE,IAAqC,EAArC,OAAO,kBAAkB,EAAE,UAAU,KAAE,MAAM,QAKxE;IAED;;;;OAIG;IACH,0BAHY,CAAS,IAAM,EAAN,MAAM,EAAE,IAAqC,EAArC,OAAO,kBAAkB,EAAE,UAAU,KAAE,MAAM,GAAC,SAAS,CAKnF;CACF"}
@@ -24,28 +24,30 @@ import {METERS_PER_UNIT} from './Units.js';
24
24
 
25
25
  /**
26
26
  * @classdesc
27
- * Projection definition class. One of these is created for each projection
28
- * supported in the application and stored in the {@link module:ol/proj} namespace.
29
- * You can use these in applications, but this is not required, as API params
30
- * and options use {@link module:ol/proj~ProjectionLike} which means the simple string
31
- * code will suffice.
27
+ * In most cases, you should not need to create instances of this class.
28
+ * Instead, where projection information is required, you can use a string
29
+ * projection code or identifier (e.g. `EPSG:4326`) instead of a projection
30
+ * instance.
32
31
  *
33
- * You can use {@link module:ol/proj.get} to retrieve the object for a particular
34
- * projection.
32
+ * The library includes support for transforming coordinates between the following
33
+ * projections:
35
34
  *
36
- * The library includes definitions for `EPSG:4326` and `EPSG:3857`, together
37
- * with the following aliases:
38
- * * `EPSG:4326`: CRS:84, urn:ogc:def:crs:EPSG:6.6:4326,
39
- * urn:ogc:def:crs:OGC:1.3:CRS84, urn:ogc:def:crs:OGC:2:84,
40
- * http://www.opengis.net/gml/srs/epsg.xml#4326,
41
- * urn:x-ogc:def:crs:EPSG:4326
42
- * * `EPSG:3857`: EPSG:102100, EPSG:102113, EPSG:900913,
43
- * urn:ogc:def:crs:EPSG:6.18:3:3857,
44
- * http://www.opengis.net/gml/srs/epsg.xml#3857
35
+ * * WGS 84 / Geographic - Using codes `EPSG:4326`, `CRS:84`, `urn:ogc:def:crs:EPSG:6.6:4326`,
36
+ * `urn:ogc:def:crs:OGC:1.3:CRS84`, `urn:ogc:def:crs:OGC:2:84`, `http://www.opengis.net/gml/srs/epsg.xml#4326`,
37
+ * or `urn:x-ogc:def:crs:EPSG:4326`
38
+ * * WGS 84 / Spherical Mercator - Using codes `EPSG:3857`, `EPSG:102100`, `EPSG:102113`, `EPSG:900913`,
39
+ * `urn:ogc:def:crs:EPSG:6.18:3:3857`, or `http://www.opengis.net/gml/srs/epsg.xml#3857`
40
+ * * WGS 84 / UTM zones - Using codes `EPSG:32601` through `EPSG:32660` for northern zones
41
+ * and `EPSG:32701` through `EPSG:32760` for southern zones. Note that the built-in UTM transforms
42
+ * are lower accuracy (with errors on the order of 0.1 m) than those that you might get in a
43
+ * library like [proj4js](https://github.com/proj4js/proj4js).
45
44
  *
46
- * If you use [proj4js](https://github.com/proj4js/proj4js), aliases can
47
- * be added using `proj4.defs()`. After all required projection definitions are
48
- * added, call the {@link module:ol/proj/proj4.register} function.
45
+ * For additional projection support, or to use higher accuracy transforms than the built-in ones, you can use
46
+ * the [proj4js](https://github.com/proj4js/proj4js) library. With `proj4js`, after adding any new projection
47
+ * definitions, call the {@link module:ol/proj/proj4.register} function.
48
+ *
49
+ * You can use the {@link module:ol/proj.get} function to retrieve a projection instance
50
+ * for one of the registered projections.
49
51
  *
50
52
  * @api
51
53
  */
package/proj/proj4.js CHANGED
@@ -7,8 +7,8 @@ import {
7
7
  addEquivalentProjections,
8
8
  addProjection,
9
9
  createSafeCoordinateTransform,
10
- get,
11
10
  } from '../proj.js';
11
+ import {get as getCachedProjection} from './projections.js';
12
12
  import {get as getTransform} from './transforms.js';
13
13
 
14
14
  /**
@@ -49,7 +49,7 @@ export function register(proj4) {
49
49
  let i, j;
50
50
  for (i = 0; i < len; ++i) {
51
51
  const code = projCodes[i];
52
- if (!get(code)) {
52
+ if (!getCachedProjection(code)) {
53
53
  const def = proj4.defs(code);
54
54
  let units = /** @type {import("./Units.js").Units} */ (def.units);
55
55
  if (!units && def.projName === 'longlat') {
@@ -67,10 +67,10 @@ export function register(proj4) {
67
67
  }
68
68
  for (i = 0; i < len; ++i) {
69
69
  const code1 = projCodes[i];
70
- const proj1 = get(code1);
70
+ const proj1 = getCachedProjection(code1);
71
71
  for (j = 0; j < len; ++j) {
72
72
  const code2 = projCodes[j];
73
- const proj2 = get(code2);
73
+ const proj2 = getCachedProjection(code2);
74
74
  if (!getTransform(code1, code2)) {
75
75
  if (proj4.defs[code1] === proj4.defs[code2]) {
76
76
  addEquivalentProjections([proj1, proj2]);
@@ -148,13 +148,13 @@ export async function fromEPSGCode(code) {
148
148
 
149
149
  const epsgCode = 'EPSG:' + code;
150
150
  if (proj4.defs(epsgCode)) {
151
- return get(epsgCode);
151
+ return getCachedProjection(epsgCode);
152
152
  }
153
153
 
154
154
  proj4.defs(epsgCode, await epsgLookup(code));
155
155
  register(proj4);
156
156
 
157
- return get(epsgCode);
157
+ return getCachedProjection(epsgCode);
158
158
  }
159
159
 
160
160
  /**
@@ -5,9 +5,9 @@ export function clear(): void;
5
5
  /**
6
6
  * Get a cached projection by code.
7
7
  * @param {string} code The code for the projection.
8
- * @return {import("./Projection.js").default} The projection (if cached).
8
+ * @return {import("./Projection.js").default|null} The projection (if cached).
9
9
  */
10
- export function get(code: string): import("./Projection.js").default;
10
+ export function get(code: string): import("./Projection.js").default | null;
11
11
  /**
12
12
  * Add a projection to the cache.
13
13
  * @param {string} code The projection code.
@@ -1 +1 @@
1
- {"version":3,"file":"projections.d.ts","sourceRoot":"","sources":["projections.js"],"names":[],"mappings":"AASA;;GAEG;AACH,8BAEC;AAED;;;;GAIG;AACH,0BAHW,MAAM,GACL,OAAO,iBAAiB,EAAE,OAAO,CAQ5C;AAED;;;;GAIG;AACH,0BAHW,MAAM,cACN,OAAO,iBAAiB,EAAE,OAAO,QAI3C"}
1
+ {"version":3,"file":"projections.d.ts","sourceRoot":"","sources":["projections.js"],"names":[],"mappings":"AASA;;GAEG;AACH,8BAEC;AAED;;;;GAIG;AACH,0BAHW,MAAM,GACL,OAAO,iBAAiB,EAAE,OAAO,GAAC,IAAI,CAQjD;AAED;;;;GAIG;AACH,0BAHW,MAAM,cACN,OAAO,iBAAiB,EAAE,OAAO,QAI3C"}
@@ -17,7 +17,7 @@ export function clear() {
17
17
  /**
18
18
  * Get a cached projection by code.
19
19
  * @param {string} code The code for the projection.
20
- * @return {import("./Projection.js").default} The projection (if cached).
20
+ * @return {import("./Projection.js").default|null} The projection (if cached).
21
21
  */
22
22
  export function get(code) {
23
23
  return (
@@ -25,7 +25,7 @@ export function remove(source: import("./Projection.js").default, destination: i
25
25
  * Get a transform given a source code and a destination code.
26
26
  * @param {string} sourceCode The code for the source projection.
27
27
  * @param {string} destinationCode The code for the destination projection.
28
- * @return {import("../proj.js").TransformFunction|undefined} The transform function (if found).
28
+ * @return {import("../proj.js").TransformFunction|null} The transform function (if found).
29
29
  */
30
- export function get(sourceCode: string, destinationCode: string): import("../proj.js").TransformFunction | undefined;
30
+ export function get(sourceCode: string, destinationCode: string): import("../proj.js").TransformFunction | null;
31
31
  //# sourceMappingURL=transforms.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transforms.d.ts","sourceRoot":"","sources":["transforms.js"],"names":[],"mappings":"AAWA;;GAEG;AACH,8BAEC;AAED;;;;;;;GAOG;AACH,4BAJW,OAAO,iBAAiB,EAAE,OAAO,eACjC,OAAO,iBAAiB,EAAE,OAAO,eACjC,OAAO,YAAY,EAAE,iBAAiB,QAShD;AAED;;;;;;;;GAQG;AACH,+BAJW,OAAO,iBAAiB,EAAE,OAAO,eACjC,OAAO,iBAAiB,EAAE,OAAO,GAChC,OAAO,YAAY,EAAE,iBAAiB,CAWjD;AAED;;;;;GAKG;AACH,gCAJW,MAAM,mBACN,MAAM,GACL,OAAO,YAAY,EAAE,iBAAiB,GAAC,SAAS,CAQ3D"}
1
+ {"version":3,"file":"transforms.d.ts","sourceRoot":"","sources":["transforms.js"],"names":[],"mappings":"AAWA;;GAEG;AACH,8BAEC;AAED;;;;;;;GAOG;AACH,4BAJW,OAAO,iBAAiB,EAAE,OAAO,eACjC,OAAO,iBAAiB,EAAE,OAAO,eACjC,OAAO,YAAY,EAAE,iBAAiB,QAShD;AAED;;;;;;;;GAQG;AACH,+BAJW,OAAO,iBAAiB,EAAE,OAAO,eACjC,OAAO,iBAAiB,EAAE,OAAO,GAChC,OAAO,YAAY,EAAE,iBAAiB,CAWjD;AAED;;;;;GAKG;AACH,gCAJW,MAAM,mBACN,MAAM,GACL,OAAO,YAAY,EAAE,iBAAiB,GAAC,IAAI,CAOtD"}
@@ -57,12 +57,11 @@ export function remove(source, destination) {
57
57
  * Get a transform given a source code and a destination code.
58
58
  * @param {string} sourceCode The code for the source projection.
59
59
  * @param {string} destinationCode The code for the destination projection.
60
- * @return {import("../proj.js").TransformFunction|undefined} The transform function (if found).
60
+ * @return {import("../proj.js").TransformFunction|null} The transform function (if found).
61
61
  */
62
62
  export function get(sourceCode, destinationCode) {
63
- let transform;
64
63
  if (sourceCode in transforms && destinationCode in transforms[sourceCode]) {
65
- transform = transforms[sourceCode][destinationCode];
64
+ return transforms[sourceCode][destinationCode];
66
65
  }
67
- return transform;
66
+ return null;
68
67
  }
package/proj/utm.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @param {string} code The projection code.
3
+ * @return {UTMZone|null} The UTM zone info (or null if not UTM).
4
+ */
5
+ export function zoneFromCode(code: string): UTMZone | null;
6
+ /**
7
+ * @param {string} code The projection code.
8
+ * @return {import('./Projection.js').default|null} A projection or null if unable to create one.
9
+ */
10
+ export function makeProjection(code: string): import("./Projection.js").default | null;
11
+ /**
12
+ * @param {import('./Projection.js').default} projection The projection.
13
+ * @return {import('../proj.js').Transforms|null} The transforms lookup or null if unable to handle projection.
14
+ */
15
+ export function makeTransforms(projection: import("./Projection.js").default): import("../proj.js").Transforms | null;
16
+ export type UTMZone = {
17
+ /**
18
+ * The zone number (1 - 60).
19
+ */
20
+ number: number;
21
+ /**
22
+ * The northern hemisphere.
23
+ */
24
+ north: boolean;
25
+ };
26
+ //# sourceMappingURL=utm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utm.d.ts","sourceRoot":"","sources":["utm.js"],"names":[],"mappings":"AA6MA;;;GAGG;AACH,mCAHW,MAAM,GACL,OAAO,GAAC,IAAI,CA4BvB;AA8BD;;;GAGG;AACH,qCAHW,MAAM,GACL,OAAO,iBAAiB,EAAE,OAAO,GAAC,IAAI,CAQjD;AAED;;;GAGG;AACH,2CAHW,OAAO,iBAAiB,EAAE,OAAO,GAChC,OAAO,YAAY,EAAE,UAAU,GAAC,IAAI,CAY/C;;;;;YAhRa,MAAM;;;;WACN,OAAO"}
package/proj/utm.js ADDED
@@ -0,0 +1,292 @@
1
+ /**
2
+ * @module ol/proj/utm
3
+ */
4
+
5
+ /**
6
+ * Adapted from https://github.com/Turbo87/utm
7
+ * Copyright (c) 2012-2017 Tobias Bieniek
8
+ *
9
+ * The functions here provide approximate transforms to and from UTM.
10
+ * They are not appropriate for use beyond the validity extend of a UTM
11
+ * zone, and the accuracy of the transform decreases toward the zone
12
+ * edges.
13
+ */
14
+
15
+ import Projection from './Projection.js';
16
+ import {toDegrees, toRadians, wrap} from '../math.js';
17
+
18
+ /**
19
+ * @typedef {Object} UTMZone
20
+ * @property {number} number The zone number (1 - 60).
21
+ * @property {boolean} north The northern hemisphere.
22
+ */
23
+
24
+ const K0 = 0.9996;
25
+
26
+ const E = 0.00669438;
27
+ const E2 = E * E;
28
+ const E3 = E2 * E;
29
+ const E_P2 = E / (1 - E);
30
+
31
+ const SQRT_E = Math.sqrt(1 - E);
32
+ const _E = (1 - SQRT_E) / (1 + SQRT_E);
33
+ const _E2 = _E * _E;
34
+ const _E3 = _E2 * _E;
35
+ const _E4 = _E3 * _E;
36
+ const _E5 = _E4 * _E;
37
+
38
+ const M1 = 1 - E / 4 - (3 * E2) / 64 - (5 * E3) / 256;
39
+ const M2 = (3 * E) / 8 + (3 * E2) / 32 + (45 * E3) / 1024;
40
+ const M3 = (15 * E2) / 256 + (45 * E3) / 1024;
41
+ const M4 = (35 * E3) / 3072;
42
+
43
+ const P2 = (3 / 2) * _E - (27 / 32) * _E3 + (269 / 512) * _E5;
44
+ const P3 = (21 / 16) * _E2 - (55 / 32) * _E4;
45
+ const P4 = (151 / 96) * _E3 - (417 / 128) * _E5;
46
+ const P5 = (1097 / 512) * _E4;
47
+
48
+ const R = 6378137;
49
+
50
+ /**
51
+ * @param {number} easting Easting value of coordinate.
52
+ * @param {number} northing Northing value of coordinate.
53
+ * @param {UTMZone} zone The UTM zone.
54
+ * @return {import("../coordinate.js").Coordinate} The transformed coordinate.
55
+ */
56
+ function toLonLat(easting, northing, zone) {
57
+ const x = easting - 500000;
58
+ const y = zone.north ? northing : northing - 10000000;
59
+
60
+ const m = y / K0;
61
+ const mu = m / (R * M1);
62
+
63
+ const pRad =
64
+ mu +
65
+ P2 * Math.sin(2 * mu) +
66
+ P3 * Math.sin(4 * mu) +
67
+ P4 * Math.sin(6 * mu) +
68
+ P5 * Math.sin(8 * mu);
69
+
70
+ const pSin = Math.sin(pRad);
71
+ const pSin2 = pSin * pSin;
72
+
73
+ const pCos = Math.cos(pRad);
74
+
75
+ const pTan = pSin / pCos;
76
+ const pTan2 = pTan * pTan;
77
+ const pTan4 = pTan2 * pTan2;
78
+
79
+ const epSin = 1 - E * pSin2;
80
+ const epSinSqrt = Math.sqrt(1 - E * pSin2);
81
+
82
+ const n = R / epSinSqrt;
83
+ const r = (1 - E) / epSin;
84
+
85
+ const c = E_P2 * pCos ** 2;
86
+ const c2 = c * c;
87
+
88
+ const d = x / (n * K0);
89
+ const d2 = d * d;
90
+ const d3 = d2 * d;
91
+ const d4 = d3 * d;
92
+ const d5 = d4 * d;
93
+ const d6 = d5 * d;
94
+
95
+ const latitude =
96
+ pRad -
97
+ (pTan / r) *
98
+ (d2 / 2 - (d4 / 24) * (5 + 3 * pTan2 + 10 * c - 4 * c2 - 9 * E_P2)) +
99
+ (d6 / 720) * (61 + 90 * pTan2 + 298 * c + 45 * pTan4 - 252 * E_P2 - 3 * c2);
100
+
101
+ let longitude =
102
+ (d -
103
+ (d3 / 6) * (1 + 2 * pTan2 + c) +
104
+ (d5 / 120) * (5 - 2 * c + 28 * pTan2 - 3 * c2 + 8 * E_P2 + 24 * pTan4)) /
105
+ pCos;
106
+
107
+ longitude = wrap(
108
+ longitude + toRadians(zoneToCentralLongitude(zone.number)),
109
+ -Math.PI,
110
+ Math.PI,
111
+ );
112
+
113
+ return [toDegrees(longitude), toDegrees(latitude)];
114
+ }
115
+
116
+ const MIN_LATITUDE = -80;
117
+ const MAX_LATITUDE = 84;
118
+ const MIN_LONGITUDE = -180;
119
+ const MAX_LONGITUDE = 180;
120
+
121
+ /**
122
+ * @param {number} longitude The longitude.
123
+ * @param {number} latitude The latitude.
124
+ * @param {UTMZone} zone The UTM zone.
125
+ * @return {import('../coordinate.js').Coordinate} The UTM coordinate.
126
+ */
127
+ function fromLonLat(longitude, latitude, zone) {
128
+ longitude = wrap(longitude, MIN_LONGITUDE, MAX_LONGITUDE);
129
+
130
+ if (latitude < MIN_LATITUDE) {
131
+ latitude = MIN_LATITUDE;
132
+ } else if (latitude > MAX_LATITUDE) {
133
+ latitude = MAX_LATITUDE;
134
+ }
135
+
136
+ const latRad = toRadians(latitude);
137
+ const latSin = Math.sin(latRad);
138
+ const latCos = Math.cos(latRad);
139
+
140
+ const latTan = latSin / latCos;
141
+ const latTan2 = latTan * latTan;
142
+ const latTan4 = latTan2 * latTan2;
143
+
144
+ const lonRad = toRadians(longitude);
145
+ const centralLon = zoneToCentralLongitude(zone.number);
146
+ const centralLonRad = toRadians(centralLon);
147
+
148
+ const n = R / Math.sqrt(1 - E * latSin ** 2);
149
+ const c = E_P2 * latCos ** 2;
150
+
151
+ const a = latCos * wrap(lonRad - centralLonRad, -Math.PI, Math.PI);
152
+ const a2 = a * a;
153
+ const a3 = a2 * a;
154
+ const a4 = a3 * a;
155
+ const a5 = a4 * a;
156
+ const a6 = a5 * a;
157
+
158
+ const m =
159
+ R *
160
+ (M1 * latRad -
161
+ M2 * Math.sin(2 * latRad) +
162
+ M3 * Math.sin(4 * latRad) -
163
+ M4 * Math.sin(6 * latRad));
164
+
165
+ const easting =
166
+ K0 *
167
+ n *
168
+ (a +
169
+ (a3 / 6) * (1 - latTan2 + c) +
170
+ (a5 / 120) * (5 - 18 * latTan2 + latTan4 + 72 * c - 58 * E_P2)) +
171
+ 500000;
172
+
173
+ let northing =
174
+ K0 *
175
+ (m +
176
+ n *
177
+ latTan *
178
+ (a2 / 2 +
179
+ (a4 / 24) * (5 - latTan2 + 9 * c + 4 * c ** 2) +
180
+ (a6 / 720) * (61 - 58 * latTan2 + latTan4 + 600 * c - 330 * E_P2)));
181
+
182
+ if (!zone.north) {
183
+ northing += 10000000;
184
+ }
185
+
186
+ return [easting, northing];
187
+ }
188
+
189
+ /**
190
+ * @param {number} zone The zone number.
191
+ * @return {number} The central longitude in degrees.
192
+ */
193
+ function zoneToCentralLongitude(zone) {
194
+ return (zone - 1) * 6 - 180 + 3;
195
+ }
196
+
197
+ /**
198
+ * @type {Array<RegExp>}
199
+ */
200
+ const epsgRegExes = [
201
+ /^EPSG:(\d+)$/,
202
+ /^urn:ogc:def:crs:EPSG::(\d+)$/,
203
+ /^http:\/\/www\.opengis\.net\/def\/crs\/EPSG\/0\/(\d+)$/,
204
+ ];
205
+
206
+ /**
207
+ * @param {string} code The projection code.
208
+ * @return {UTMZone|null} The UTM zone info (or null if not UTM).
209
+ */
210
+ export function zoneFromCode(code) {
211
+ let epsgId = 0;
212
+ for (const re of epsgRegExes) {
213
+ const match = code.match(re);
214
+ if (match) {
215
+ epsgId = parseInt(match[1]);
216
+ break;
217
+ }
218
+ }
219
+ if (!epsgId) {
220
+ return null;
221
+ }
222
+
223
+ let number = 0;
224
+ let north = false;
225
+ if (epsgId > 32700 && epsgId < 32761) {
226
+ number = epsgId - 32700;
227
+ } else if (epsgId > 32600 && epsgId < 32661) {
228
+ north = true;
229
+ number = epsgId - 32600;
230
+ }
231
+ if (!number) {
232
+ return null;
233
+ }
234
+
235
+ return {number, north};
236
+ }
237
+
238
+ /**
239
+ * @param {function(number, number, UTMZone): import('../coordinate.js').Coordinate} transformer The transformer.
240
+ * @param {UTMZone} zone The UTM zone.
241
+ * @return {import('../proj.js').TransformFunction} The transform function.
242
+ */
243
+ function makeTransformFunction(transformer, zone) {
244
+ return function (input, output, dimension, stride) {
245
+ const length = input.length;
246
+ dimension = dimension > 1 ? dimension : 2;
247
+ stride = stride ?? dimension;
248
+ if (!output) {
249
+ if (dimension > 2) {
250
+ output = input.slice();
251
+ } else {
252
+ output = new Array(length);
253
+ }
254
+ }
255
+ for (let i = 0; i < length; i += stride) {
256
+ const x = input[i];
257
+ const y = input[i + 1];
258
+ const coord = transformer(x, y, zone);
259
+ output[i] = coord[0];
260
+ output[i + 1] = coord[1];
261
+ }
262
+ return output;
263
+ };
264
+ }
265
+
266
+ /**
267
+ * @param {string} code The projection code.
268
+ * @return {import('./Projection.js').default|null} A projection or null if unable to create one.
269
+ */
270
+ export function makeProjection(code) {
271
+ const zone = zoneFromCode(code);
272
+ if (!zone) {
273
+ return null;
274
+ }
275
+ return new Projection({code, units: 'm'});
276
+ }
277
+
278
+ /**
279
+ * @param {import('./Projection.js').default} projection The projection.
280
+ * @return {import('../proj.js').Transforms|null} The transforms lookup or null if unable to handle projection.
281
+ */
282
+ export function makeTransforms(projection) {
283
+ const zone = zoneFromCode(projection.getCode());
284
+ if (!zone) {
285
+ return null;
286
+ }
287
+
288
+ return {
289
+ forward: makeTransformFunction(fromLonLat, zone),
290
+ inverse: makeTransformFunction(toLonLat, zone),
291
+ };
292
+ }
package/proj.d.ts CHANGED
@@ -156,12 +156,12 @@ export function equivalent(projection1: Projection, projection2: Projection): bo
156
156
  * Searches in the list of transform functions for the function for converting
157
157
  * coordinates from the source projection to the destination projection.
158
158
  *
159
- * @param {Projection} sourceProjection Source Projection object.
160
- * @param {Projection} destinationProjection Destination Projection
159
+ * @param {Projection} source Source Projection object.
160
+ * @param {Projection} destination Destination Projection
161
161
  * object.
162
- * @return {TransformFunction} Transform function.
162
+ * @return {TransformFunction|null} Transform function.
163
163
  */
164
- export function getTransformFromProjections(sourceProjection: Projection, destinationProjection: Projection): TransformFunction;
164
+ export function getTransformFromProjections(source: Projection, destination: Projection): TransformFunction | null;
165
165
  /**
166
166
  * Given the projection-like objects, searches for a transformation
167
167
  * function to convert a coordinates array from the source projection to the
@@ -175,7 +175,9 @@ export function getTransformFromProjections(sourceProjection: Projection, destin
175
175
  export function getTransform(source: ProjectionLike, destination: ProjectionLike): TransformFunction;
176
176
  /**
177
177
  * Transforms a coordinate from source projection to destination projection.
178
- * This returns a new coordinate (and does not modify the original).
178
+ * This returns a new coordinate (and does not modify the original). If there
179
+ * is no available transform between the two projection, the function will throw
180
+ * an error.
179
181
  *
180
182
  * See {@link module:ol/proj.transformExtent} for extent transformation.
181
183
  * See the transform method of {@link module:ol/geom/Geometry~Geometry} and its
@@ -308,6 +310,16 @@ export function addCommon(): void;
308
310
  * string or undefined.
309
311
  */
310
312
  export type ProjectionLike = Projection | string | undefined;
313
+ export type Transforms = {
314
+ /**
315
+ * The forward transform (from geographic).
316
+ */
317
+ forward: TransformFunction;
318
+ /**
319
+ * The inverse transform (to geographic).
320
+ */
321
+ inverse: TransformFunction;
322
+ };
311
323
  /**
312
324
  * A transform function accepts an array of input coordinate values, an optional
313
325
  * output array, and an optional dimension (default should be 2). The function