ol 7.1.1-dev.1663240093930 → 7.1.1-dev.1663334047420
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/dist/ol.js +2 -2
- package/dist/ol.js.map +1 -1
- package/package.json +1 -1
- package/proj/proj4.d.ts +42 -2
- package/proj/proj4.d.ts.map +1 -1
- package/proj/proj4.js +92 -2
- package/util.js +1 -1
package/package.json
CHANGED
package/proj/proj4.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @return {boolean} Proj4 has been registered.
|
|
3
|
+
*/
|
|
4
|
+
export function isRegistered(): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Unsets the shared proj4 previsouly set with register.
|
|
7
|
+
*/
|
|
8
|
+
export function unregister(): void;
|
|
1
9
|
/**
|
|
2
10
|
* Make projections defined in proj4 (with `proj4.defs()`) available in
|
|
3
11
|
* OpenLayers. Requires proj4 >= 2.8.0.
|
|
@@ -6,8 +14,40 @@
|
|
|
6
14
|
* registry, e.g. after calling `proj4.defs()`. Existing transforms will not be
|
|
7
15
|
* modified by this function.
|
|
8
16
|
*
|
|
9
|
-
* @param {
|
|
17
|
+
* @param {import("proj4")} proj4 Proj4.
|
|
18
|
+
* @api
|
|
19
|
+
*/
|
|
20
|
+
export function register(proj4: typeof import("proj4")): void;
|
|
21
|
+
/**
|
|
22
|
+
* Set the lookup function for getting proj4 definitions given an EPSG code.
|
|
23
|
+
* By default, the {@link module:ol/proj/proj4.fromEPSGCode} function uses the
|
|
24
|
+
* epsg.io website for proj4 definitions. This can be changed by providing a
|
|
25
|
+
* different lookup function.
|
|
26
|
+
*
|
|
27
|
+
* @param {function(number):Promise<string>} func The lookup function.
|
|
28
|
+
* @api
|
|
29
|
+
*/
|
|
30
|
+
export function setEPSGLookup(func: (arg0: number) => Promise<string>): void;
|
|
31
|
+
/**
|
|
32
|
+
* Get the current EPSG lookup function.
|
|
33
|
+
*
|
|
34
|
+
* @return {function(number):Promise<string>} The EPSG lookup function.
|
|
35
|
+
*/
|
|
36
|
+
export function getEPSGLookup(): (arg0: number) => Promise<string>;
|
|
37
|
+
/**
|
|
38
|
+
* Get a projection from an EPSG code. This function fetches the projection
|
|
39
|
+
* definition from the epsg.io website, registers this definition for use with
|
|
40
|
+
* proj4, and returns a configured projection. You must call import proj4 and
|
|
41
|
+
* call {@link module:ol/proj/proj4.register} before using this function.
|
|
42
|
+
*
|
|
43
|
+
* If the projection definition is already registered with proj4, it will not
|
|
44
|
+
* be fetched again (so it is ok to call this function multiple times with the
|
|
45
|
+
* same code).
|
|
46
|
+
*
|
|
47
|
+
* @param {number|string} code The EPSG code (e.g. 4326 or 'EPSG:4326').
|
|
48
|
+
* @return {Promise<Projection>} The projection.
|
|
10
49
|
* @api
|
|
11
50
|
*/
|
|
12
|
-
export function
|
|
51
|
+
export function fromEPSGCode(code: number | string): Promise<Projection>;
|
|
52
|
+
import Projection from "./Projection.js";
|
|
13
53
|
//# sourceMappingURL=proj4.d.ts.map
|
package/proj/proj4.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proj4.d.ts","sourceRoot":"","sources":["proj4.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"proj4.d.ts","sourceRoot":"","sources":["proj4.js"],"names":[],"mappings":"AAkBA;;GAEG;AACH,gCAFY,OAAO,CAIlB;AAED;;GAEG;AACH,mCAEC;AAED;;;;;;;;;;GAUG;AACH,8DA6CC;AAcD;;;;;;;;GAQG;AACH,2CAHoB,MAAM,KAAE,QAAQ,MAAM,CAAC,QAK1C;AAED;;;;GAIG;AACH,wCAFqB,MAAM,KAAE,QAAQ,MAAM,CAAC,CAI3C;AAED;;;;;;;;;;;;;GAaG;AACH,mCAJW,MAAM,GAAC,MAAM,GACZ,QAAQ,UAAU,CAAC,CAsB9B"}
|
package/proj/proj4.js
CHANGED
|
@@ -11,6 +11,25 @@ import {
|
|
|
11
11
|
} from '../proj.js';
|
|
12
12
|
import {get as getTransform} from './transforms.js';
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* @type {import("proj4")|null}
|
|
16
|
+
*/
|
|
17
|
+
let registered = null;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @return {boolean} Proj4 has been registered.
|
|
21
|
+
*/
|
|
22
|
+
export function isRegistered() {
|
|
23
|
+
return !!registered;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Unsets the shared proj4 previsouly set with register.
|
|
28
|
+
*/
|
|
29
|
+
export function unregister() {
|
|
30
|
+
registered = null;
|
|
31
|
+
}
|
|
32
|
+
|
|
14
33
|
/**
|
|
15
34
|
* Make projections defined in proj4 (with `proj4.defs()`) available in
|
|
16
35
|
* OpenLayers. Requires proj4 >= 2.8.0.
|
|
@@ -19,10 +38,12 @@ import {get as getTransform} from './transforms.js';
|
|
|
19
38
|
* registry, e.g. after calling `proj4.defs()`. Existing transforms will not be
|
|
20
39
|
* modified by this function.
|
|
21
40
|
*
|
|
22
|
-
* @param {
|
|
41
|
+
* @param {import("proj4")} proj4 Proj4.
|
|
23
42
|
* @api
|
|
24
43
|
*/
|
|
25
44
|
export function register(proj4) {
|
|
45
|
+
registered = proj4;
|
|
46
|
+
|
|
26
47
|
const projCodes = Object.keys(proj4.defs);
|
|
27
48
|
const len = projCodes.length;
|
|
28
49
|
let i, j;
|
|
@@ -30,7 +51,7 @@ export function register(proj4) {
|
|
|
30
51
|
const code = projCodes[i];
|
|
31
52
|
if (!get(code)) {
|
|
32
53
|
const def = proj4.defs(code);
|
|
33
|
-
let units = def.units;
|
|
54
|
+
let units = /** @type {import("./Units.js").Units} */ (def.units);
|
|
34
55
|
if (!units && def.projName === 'longlat') {
|
|
35
56
|
units = 'degrees';
|
|
36
57
|
}
|
|
@@ -66,3 +87,72 @@ export function register(proj4) {
|
|
|
66
87
|
}
|
|
67
88
|
}
|
|
68
89
|
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @param {number} code The EPSG code.
|
|
93
|
+
* @return {Promise<string>} The proj4 definition.
|
|
94
|
+
*/
|
|
95
|
+
let epsgLookup = async function (code) {
|
|
96
|
+
const response = await fetch(`https://epsg.io/${code}.proj4`);
|
|
97
|
+
if (!response.ok) {
|
|
98
|
+
throw new Error(`Unexpected response from epsg.io: ${response.status}`);
|
|
99
|
+
}
|
|
100
|
+
return response.text();
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Set the lookup function for getting proj4 definitions given an EPSG code.
|
|
105
|
+
* By default, the {@link module:ol/proj/proj4.fromEPSGCode} function uses the
|
|
106
|
+
* epsg.io website for proj4 definitions. This can be changed by providing a
|
|
107
|
+
* different lookup function.
|
|
108
|
+
*
|
|
109
|
+
* @param {function(number):Promise<string>} func The lookup function.
|
|
110
|
+
* @api
|
|
111
|
+
*/
|
|
112
|
+
export function setEPSGLookup(func) {
|
|
113
|
+
epsgLookup = func;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Get the current EPSG lookup function.
|
|
118
|
+
*
|
|
119
|
+
* @return {function(number):Promise<string>} The EPSG lookup function.
|
|
120
|
+
*/
|
|
121
|
+
export function getEPSGLookup() {
|
|
122
|
+
return epsgLookup;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Get a projection from an EPSG code. This function fetches the projection
|
|
127
|
+
* definition from the epsg.io website, registers this definition for use with
|
|
128
|
+
* proj4, and returns a configured projection. You must call import proj4 and
|
|
129
|
+
* call {@link module:ol/proj/proj4.register} before using this function.
|
|
130
|
+
*
|
|
131
|
+
* If the projection definition is already registered with proj4, it will not
|
|
132
|
+
* be fetched again (so it is ok to call this function multiple times with the
|
|
133
|
+
* same code).
|
|
134
|
+
*
|
|
135
|
+
* @param {number|string} code The EPSG code (e.g. 4326 or 'EPSG:4326').
|
|
136
|
+
* @return {Promise<Projection>} The projection.
|
|
137
|
+
* @api
|
|
138
|
+
*/
|
|
139
|
+
export async function fromEPSGCode(code) {
|
|
140
|
+
if (typeof code === 'string') {
|
|
141
|
+
code = parseInt(code.split(':').pop(), 10);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const proj4 = registered;
|
|
145
|
+
if (!proj4) {
|
|
146
|
+
throw new Error('Proj4 must be registered first with register(proj4)');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const epsgCode = 'EPSG:' + code;
|
|
150
|
+
if (proj4.defs(epsgCode)) {
|
|
151
|
+
return get(epsgCode);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
proj4.defs(epsgCode, await epsgLookup(code));
|
|
155
|
+
register(proj4);
|
|
156
|
+
|
|
157
|
+
return get(epsgCode);
|
|
158
|
+
}
|
package/util.js
CHANGED