map-2d-base 1.0.0
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/README.md +3 -0
- package/dist/assets/map-2d-base.css +1 -0
- package/dist/chunks/asserts-B5CSgOpZ.js +713 -0
- package/dist/chunks/index-CwJi8_r0.js +828 -0
- package/dist/chunks/index-qMK-h7Yi.js +3260 -0
- package/dist/chunks/index-snoDp5kN.js +1216 -0
- package/dist/chunks/math-CtjJ8U9C.js +105 -0
- package/dist/geom.esm.js +4 -0
- package/dist/index.esm.js +22796 -0
- package/dist/style.esm.js +9 -0
- package/dist/utils.esm.js +5 -0
- package/package.json +80 -0
|
@@ -0,0 +1,1216 @@
|
|
|
1
|
+
var __pow = Math.pow;
|
|
2
|
+
import { t as toRadians, w as wrap, g as toDegrees, m as modulo } from "./math-CtjJ8U9C.js";
|
|
3
|
+
const Relationship = {
|
|
4
|
+
UNKNOWN: 0,
|
|
5
|
+
INTERSECTING: 1,
|
|
6
|
+
ABOVE: 2,
|
|
7
|
+
RIGHT: 4,
|
|
8
|
+
BELOW: 8,
|
|
9
|
+
LEFT: 16
|
|
10
|
+
};
|
|
11
|
+
function boundingExtent(coordinates) {
|
|
12
|
+
const extent = createEmpty();
|
|
13
|
+
for (let i = 0, ii = coordinates.length; i < ii; ++i) {
|
|
14
|
+
extendCoordinate(extent, coordinates[i]);
|
|
15
|
+
}
|
|
16
|
+
return extent;
|
|
17
|
+
}
|
|
18
|
+
function buffer(extent, value, dest) {
|
|
19
|
+
if (dest) {
|
|
20
|
+
dest[0] = extent[0] - value;
|
|
21
|
+
dest[1] = extent[1] - value;
|
|
22
|
+
dest[2] = extent[2] + value;
|
|
23
|
+
dest[3] = extent[3] + value;
|
|
24
|
+
return dest;
|
|
25
|
+
}
|
|
26
|
+
return [
|
|
27
|
+
extent[0] - value,
|
|
28
|
+
extent[1] - value,
|
|
29
|
+
extent[2] + value,
|
|
30
|
+
extent[3] + value
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
function clone(extent, dest) {
|
|
34
|
+
if (dest) {
|
|
35
|
+
dest[0] = extent[0];
|
|
36
|
+
dest[1] = extent[1];
|
|
37
|
+
dest[2] = extent[2];
|
|
38
|
+
dest[3] = extent[3];
|
|
39
|
+
return dest;
|
|
40
|
+
}
|
|
41
|
+
return extent.slice();
|
|
42
|
+
}
|
|
43
|
+
function closestSquaredDistanceXY(extent, x, y) {
|
|
44
|
+
let dx, dy;
|
|
45
|
+
if (x < extent[0]) {
|
|
46
|
+
dx = extent[0] - x;
|
|
47
|
+
} else if (extent[2] < x) {
|
|
48
|
+
dx = x - extent[2];
|
|
49
|
+
} else {
|
|
50
|
+
dx = 0;
|
|
51
|
+
}
|
|
52
|
+
if (y < extent[1]) {
|
|
53
|
+
dy = extent[1] - y;
|
|
54
|
+
} else if (extent[3] < y) {
|
|
55
|
+
dy = y - extent[3];
|
|
56
|
+
} else {
|
|
57
|
+
dy = 0;
|
|
58
|
+
}
|
|
59
|
+
return dx * dx + dy * dy;
|
|
60
|
+
}
|
|
61
|
+
function containsCoordinate(extent, coordinate) {
|
|
62
|
+
return containsXY(extent, coordinate[0], coordinate[1]);
|
|
63
|
+
}
|
|
64
|
+
function containsExtent(extent1, extent2) {
|
|
65
|
+
return extent1[0] <= extent2[0] && extent2[2] <= extent1[2] && extent1[1] <= extent2[1] && extent2[3] <= extent1[3];
|
|
66
|
+
}
|
|
67
|
+
function containsXY(extent, x, y) {
|
|
68
|
+
return extent[0] <= x && x <= extent[2] && extent[1] <= y && y <= extent[3];
|
|
69
|
+
}
|
|
70
|
+
function coordinateRelationship(extent, coordinate) {
|
|
71
|
+
const minX = extent[0];
|
|
72
|
+
const minY = extent[1];
|
|
73
|
+
const maxX = extent[2];
|
|
74
|
+
const maxY = extent[3];
|
|
75
|
+
const x = coordinate[0];
|
|
76
|
+
const y = coordinate[1];
|
|
77
|
+
let relationship = Relationship.UNKNOWN;
|
|
78
|
+
if (x < minX) {
|
|
79
|
+
relationship = relationship | Relationship.LEFT;
|
|
80
|
+
} else if (x > maxX) {
|
|
81
|
+
relationship = relationship | Relationship.RIGHT;
|
|
82
|
+
}
|
|
83
|
+
if (y < minY) {
|
|
84
|
+
relationship = relationship | Relationship.BELOW;
|
|
85
|
+
} else if (y > maxY) {
|
|
86
|
+
relationship = relationship | Relationship.ABOVE;
|
|
87
|
+
}
|
|
88
|
+
if (relationship === Relationship.UNKNOWN) {
|
|
89
|
+
relationship = Relationship.INTERSECTING;
|
|
90
|
+
}
|
|
91
|
+
return relationship;
|
|
92
|
+
}
|
|
93
|
+
function createEmpty() {
|
|
94
|
+
return [Infinity, Infinity, -Infinity, -Infinity];
|
|
95
|
+
}
|
|
96
|
+
function createOrUpdate(minX, minY, maxX, maxY, dest) {
|
|
97
|
+
if (dest) {
|
|
98
|
+
dest[0] = minX;
|
|
99
|
+
dest[1] = minY;
|
|
100
|
+
dest[2] = maxX;
|
|
101
|
+
dest[3] = maxY;
|
|
102
|
+
return dest;
|
|
103
|
+
}
|
|
104
|
+
return [minX, minY, maxX, maxY];
|
|
105
|
+
}
|
|
106
|
+
function createOrUpdateEmpty(dest) {
|
|
107
|
+
return createOrUpdate(Infinity, Infinity, -Infinity, -Infinity, dest);
|
|
108
|
+
}
|
|
109
|
+
function createOrUpdateFromCoordinate(coordinate, dest) {
|
|
110
|
+
const x = coordinate[0];
|
|
111
|
+
const y = coordinate[1];
|
|
112
|
+
return createOrUpdate(x, y, x, y, dest);
|
|
113
|
+
}
|
|
114
|
+
function createOrUpdateFromFlatCoordinates(flatCoordinates, offset, end, stride, dest) {
|
|
115
|
+
const extent = createOrUpdateEmpty(dest);
|
|
116
|
+
return extendFlatCoordinates(extent, flatCoordinates, offset, end, stride);
|
|
117
|
+
}
|
|
118
|
+
function equals$1(extent1, extent2) {
|
|
119
|
+
return extent1[0] == extent2[0] && extent1[2] == extent2[2] && extent1[1] == extent2[1] && extent1[3] == extent2[3];
|
|
120
|
+
}
|
|
121
|
+
function extend(extent1, extent2) {
|
|
122
|
+
if (extent2[0] < extent1[0]) {
|
|
123
|
+
extent1[0] = extent2[0];
|
|
124
|
+
}
|
|
125
|
+
if (extent2[2] > extent1[2]) {
|
|
126
|
+
extent1[2] = extent2[2];
|
|
127
|
+
}
|
|
128
|
+
if (extent2[1] < extent1[1]) {
|
|
129
|
+
extent1[1] = extent2[1];
|
|
130
|
+
}
|
|
131
|
+
if (extent2[3] > extent1[3]) {
|
|
132
|
+
extent1[3] = extent2[3];
|
|
133
|
+
}
|
|
134
|
+
return extent1;
|
|
135
|
+
}
|
|
136
|
+
function extendCoordinate(extent, coordinate) {
|
|
137
|
+
if (coordinate[0] < extent[0]) {
|
|
138
|
+
extent[0] = coordinate[0];
|
|
139
|
+
}
|
|
140
|
+
if (coordinate[0] > extent[2]) {
|
|
141
|
+
extent[2] = coordinate[0];
|
|
142
|
+
}
|
|
143
|
+
if (coordinate[1] < extent[1]) {
|
|
144
|
+
extent[1] = coordinate[1];
|
|
145
|
+
}
|
|
146
|
+
if (coordinate[1] > extent[3]) {
|
|
147
|
+
extent[3] = coordinate[1];
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function extendFlatCoordinates(extent, flatCoordinates, offset, end, stride) {
|
|
151
|
+
for (; offset < end; offset += stride) {
|
|
152
|
+
extendXY(extent, flatCoordinates[offset], flatCoordinates[offset + 1]);
|
|
153
|
+
}
|
|
154
|
+
return extent;
|
|
155
|
+
}
|
|
156
|
+
function extendXY(extent, x, y) {
|
|
157
|
+
extent[0] = Math.min(extent[0], x);
|
|
158
|
+
extent[1] = Math.min(extent[1], y);
|
|
159
|
+
extent[2] = Math.max(extent[2], x);
|
|
160
|
+
extent[3] = Math.max(extent[3], y);
|
|
161
|
+
}
|
|
162
|
+
function forEachCorner(extent, callback) {
|
|
163
|
+
let val;
|
|
164
|
+
val = callback(getBottomLeft(extent));
|
|
165
|
+
if (val) {
|
|
166
|
+
return val;
|
|
167
|
+
}
|
|
168
|
+
val = callback(getBottomRight(extent));
|
|
169
|
+
if (val) {
|
|
170
|
+
return val;
|
|
171
|
+
}
|
|
172
|
+
val = callback(getTopRight(extent));
|
|
173
|
+
if (val) {
|
|
174
|
+
return val;
|
|
175
|
+
}
|
|
176
|
+
val = callback(getTopLeft(extent));
|
|
177
|
+
if (val) {
|
|
178
|
+
return val;
|
|
179
|
+
}
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
function getArea(extent) {
|
|
183
|
+
let area = 0;
|
|
184
|
+
if (!isEmpty(extent)) {
|
|
185
|
+
area = getWidth(extent) * getHeight(extent);
|
|
186
|
+
}
|
|
187
|
+
return area;
|
|
188
|
+
}
|
|
189
|
+
function getBottomLeft(extent) {
|
|
190
|
+
return [extent[0], extent[1]];
|
|
191
|
+
}
|
|
192
|
+
function getBottomRight(extent) {
|
|
193
|
+
return [extent[2], extent[1]];
|
|
194
|
+
}
|
|
195
|
+
function getCenter(extent) {
|
|
196
|
+
return [(extent[0] + extent[2]) / 2, (extent[1] + extent[3]) / 2];
|
|
197
|
+
}
|
|
198
|
+
function getCorner(extent, corner) {
|
|
199
|
+
let coordinate;
|
|
200
|
+
if (corner === "bottom-left") {
|
|
201
|
+
coordinate = getBottomLeft(extent);
|
|
202
|
+
} else if (corner === "bottom-right") {
|
|
203
|
+
coordinate = getBottomRight(extent);
|
|
204
|
+
} else if (corner === "top-left") {
|
|
205
|
+
coordinate = getTopLeft(extent);
|
|
206
|
+
} else if (corner === "top-right") {
|
|
207
|
+
coordinate = getTopRight(extent);
|
|
208
|
+
} else {
|
|
209
|
+
throw new Error("Invalid corner");
|
|
210
|
+
}
|
|
211
|
+
return coordinate;
|
|
212
|
+
}
|
|
213
|
+
function getForViewAndSize(center, resolution, rotation, size, dest) {
|
|
214
|
+
const [x0, y0, x1, y1, x2, y2, x3, y3] = getRotatedViewport(
|
|
215
|
+
center,
|
|
216
|
+
resolution,
|
|
217
|
+
rotation,
|
|
218
|
+
size
|
|
219
|
+
);
|
|
220
|
+
return createOrUpdate(
|
|
221
|
+
Math.min(x0, x1, x2, x3),
|
|
222
|
+
Math.min(y0, y1, y2, y3),
|
|
223
|
+
Math.max(x0, x1, x2, x3),
|
|
224
|
+
Math.max(y0, y1, y2, y3),
|
|
225
|
+
dest
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
function getRotatedViewport(center, resolution, rotation, size) {
|
|
229
|
+
const dx = resolution * size[0] / 2;
|
|
230
|
+
const dy = resolution * size[1] / 2;
|
|
231
|
+
const cosRotation = Math.cos(rotation);
|
|
232
|
+
const sinRotation = Math.sin(rotation);
|
|
233
|
+
const xCos = dx * cosRotation;
|
|
234
|
+
const xSin = dx * sinRotation;
|
|
235
|
+
const yCos = dy * cosRotation;
|
|
236
|
+
const ySin = dy * sinRotation;
|
|
237
|
+
const x = center[0];
|
|
238
|
+
const y = center[1];
|
|
239
|
+
return [
|
|
240
|
+
x - xCos + ySin,
|
|
241
|
+
y - xSin - yCos,
|
|
242
|
+
x - xCos - ySin,
|
|
243
|
+
y - xSin + yCos,
|
|
244
|
+
x + xCos - ySin,
|
|
245
|
+
y + xSin + yCos,
|
|
246
|
+
x + xCos + ySin,
|
|
247
|
+
y + xSin - yCos,
|
|
248
|
+
x - xCos + ySin,
|
|
249
|
+
y - xSin - yCos
|
|
250
|
+
];
|
|
251
|
+
}
|
|
252
|
+
function getHeight(extent) {
|
|
253
|
+
return extent[3] - extent[1];
|
|
254
|
+
}
|
|
255
|
+
function getIntersection(extent1, extent2, dest) {
|
|
256
|
+
const intersection = dest ? dest : createEmpty();
|
|
257
|
+
if (intersects(extent1, extent2)) {
|
|
258
|
+
if (extent1[0] > extent2[0]) {
|
|
259
|
+
intersection[0] = extent1[0];
|
|
260
|
+
} else {
|
|
261
|
+
intersection[0] = extent2[0];
|
|
262
|
+
}
|
|
263
|
+
if (extent1[1] > extent2[1]) {
|
|
264
|
+
intersection[1] = extent1[1];
|
|
265
|
+
} else {
|
|
266
|
+
intersection[1] = extent2[1];
|
|
267
|
+
}
|
|
268
|
+
if (extent1[2] < extent2[2]) {
|
|
269
|
+
intersection[2] = extent1[2];
|
|
270
|
+
} else {
|
|
271
|
+
intersection[2] = extent2[2];
|
|
272
|
+
}
|
|
273
|
+
if (extent1[3] < extent2[3]) {
|
|
274
|
+
intersection[3] = extent1[3];
|
|
275
|
+
} else {
|
|
276
|
+
intersection[3] = extent2[3];
|
|
277
|
+
}
|
|
278
|
+
} else {
|
|
279
|
+
createOrUpdateEmpty(intersection);
|
|
280
|
+
}
|
|
281
|
+
return intersection;
|
|
282
|
+
}
|
|
283
|
+
function getTopLeft(extent) {
|
|
284
|
+
return [extent[0], extent[3]];
|
|
285
|
+
}
|
|
286
|
+
function getTopRight(extent) {
|
|
287
|
+
return [extent[2], extent[3]];
|
|
288
|
+
}
|
|
289
|
+
function getWidth(extent) {
|
|
290
|
+
return extent[2] - extent[0];
|
|
291
|
+
}
|
|
292
|
+
function intersects(extent1, extent2) {
|
|
293
|
+
return extent1[0] <= extent2[2] && extent1[2] >= extent2[0] && extent1[1] <= extent2[3] && extent1[3] >= extent2[1];
|
|
294
|
+
}
|
|
295
|
+
function isEmpty(extent) {
|
|
296
|
+
return extent[2] < extent[0] || extent[3] < extent[1];
|
|
297
|
+
}
|
|
298
|
+
function returnOrUpdate(extent, dest) {
|
|
299
|
+
if (dest) {
|
|
300
|
+
dest[0] = extent[0];
|
|
301
|
+
dest[1] = extent[1];
|
|
302
|
+
dest[2] = extent[2];
|
|
303
|
+
dest[3] = extent[3];
|
|
304
|
+
return dest;
|
|
305
|
+
}
|
|
306
|
+
return extent;
|
|
307
|
+
}
|
|
308
|
+
function intersectsSegment(extent, start, end) {
|
|
309
|
+
let intersects2 = false;
|
|
310
|
+
const startRel = coordinateRelationship(extent, start);
|
|
311
|
+
const endRel = coordinateRelationship(extent, end);
|
|
312
|
+
if (startRel === Relationship.INTERSECTING || endRel === Relationship.INTERSECTING) {
|
|
313
|
+
intersects2 = true;
|
|
314
|
+
} else {
|
|
315
|
+
const minX = extent[0];
|
|
316
|
+
const minY = extent[1];
|
|
317
|
+
const maxX = extent[2];
|
|
318
|
+
const maxY = extent[3];
|
|
319
|
+
const startX = start[0];
|
|
320
|
+
const startY = start[1];
|
|
321
|
+
const endX = end[0];
|
|
322
|
+
const endY = end[1];
|
|
323
|
+
const slope = (endY - startY) / (endX - startX);
|
|
324
|
+
let x, y;
|
|
325
|
+
if (!!(endRel & Relationship.ABOVE) && !(startRel & Relationship.ABOVE)) {
|
|
326
|
+
x = endX - (endY - maxY) / slope;
|
|
327
|
+
intersects2 = x >= minX && x <= maxX;
|
|
328
|
+
}
|
|
329
|
+
if (!intersects2 && !!(endRel & Relationship.RIGHT) && !(startRel & Relationship.RIGHT)) {
|
|
330
|
+
y = endY - (endX - maxX) * slope;
|
|
331
|
+
intersects2 = y >= minY && y <= maxY;
|
|
332
|
+
}
|
|
333
|
+
if (!intersects2 && !!(endRel & Relationship.BELOW) && !(startRel & Relationship.BELOW)) {
|
|
334
|
+
x = endX - (endY - minY) / slope;
|
|
335
|
+
intersects2 = x >= minX && x <= maxX;
|
|
336
|
+
}
|
|
337
|
+
if (!intersects2 && !!(endRel & Relationship.LEFT) && !(startRel & Relationship.LEFT)) {
|
|
338
|
+
y = endY - (endX - minX) * slope;
|
|
339
|
+
intersects2 = y >= minY && y <= maxY;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return intersects2;
|
|
343
|
+
}
|
|
344
|
+
function wrapX$1(extent, projection) {
|
|
345
|
+
const projectionExtent = projection.getExtent();
|
|
346
|
+
const center = getCenter(extent);
|
|
347
|
+
if (projection.canWrapX() && (center[0] < projectionExtent[0] || center[0] >= projectionExtent[2])) {
|
|
348
|
+
const worldWidth = getWidth(projectionExtent);
|
|
349
|
+
const worldsAway = Math.floor(
|
|
350
|
+
(center[0] - projectionExtent[0]) / worldWidth
|
|
351
|
+
);
|
|
352
|
+
const offset = worldsAway * worldWidth;
|
|
353
|
+
extent[0] -= offset;
|
|
354
|
+
extent[2] -= offset;
|
|
355
|
+
}
|
|
356
|
+
return extent;
|
|
357
|
+
}
|
|
358
|
+
function wrapAndSliceX(extent, projection, multiWorld) {
|
|
359
|
+
if (projection.canWrapX()) {
|
|
360
|
+
const projectionExtent = projection.getExtent();
|
|
361
|
+
if (!isFinite(extent[0]) || !isFinite(extent[2])) {
|
|
362
|
+
return [[projectionExtent[0], extent[1], projectionExtent[2], extent[3]]];
|
|
363
|
+
}
|
|
364
|
+
wrapX$1(extent, projection);
|
|
365
|
+
const worldWidth = getWidth(projectionExtent);
|
|
366
|
+
if (getWidth(extent) > worldWidth && !multiWorld) {
|
|
367
|
+
return [[projectionExtent[0], extent[1], projectionExtent[2], extent[3]]];
|
|
368
|
+
}
|
|
369
|
+
if (extent[0] < projectionExtent[0]) {
|
|
370
|
+
return [
|
|
371
|
+
[extent[0] + worldWidth, extent[1], projectionExtent[2], extent[3]],
|
|
372
|
+
[projectionExtent[0], extent[1], extent[2], extent[3]]
|
|
373
|
+
];
|
|
374
|
+
}
|
|
375
|
+
if (extent[2] > projectionExtent[2]) {
|
|
376
|
+
return [
|
|
377
|
+
[extent[0], extent[1], projectionExtent[2], extent[3]],
|
|
378
|
+
[projectionExtent[0], extent[1], extent[2] - worldWidth, extent[3]]
|
|
379
|
+
];
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return [extent];
|
|
383
|
+
}
|
|
384
|
+
function add$2(coordinate, delta) {
|
|
385
|
+
coordinate[0] += +delta[0];
|
|
386
|
+
coordinate[1] += +delta[1];
|
|
387
|
+
return coordinate;
|
|
388
|
+
}
|
|
389
|
+
function equals(coordinate1, coordinate2) {
|
|
390
|
+
let equals2 = true;
|
|
391
|
+
for (let i = coordinate1.length - 1; i >= 0; --i) {
|
|
392
|
+
if (coordinate1[i] != coordinate2[i]) {
|
|
393
|
+
equals2 = false;
|
|
394
|
+
break;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return equals2;
|
|
398
|
+
}
|
|
399
|
+
function rotate(coordinate, angle) {
|
|
400
|
+
const cosAngle = Math.cos(angle);
|
|
401
|
+
const sinAngle = Math.sin(angle);
|
|
402
|
+
const x = coordinate[0] * cosAngle - coordinate[1] * sinAngle;
|
|
403
|
+
const y = coordinate[1] * cosAngle + coordinate[0] * sinAngle;
|
|
404
|
+
coordinate[0] = x;
|
|
405
|
+
coordinate[1] = y;
|
|
406
|
+
return coordinate;
|
|
407
|
+
}
|
|
408
|
+
function scale(coordinate, scale2) {
|
|
409
|
+
coordinate[0] *= scale2;
|
|
410
|
+
coordinate[1] *= scale2;
|
|
411
|
+
return coordinate;
|
|
412
|
+
}
|
|
413
|
+
function wrapX(coordinate, projection) {
|
|
414
|
+
if (projection.canWrapX()) {
|
|
415
|
+
const worldWidth = getWidth(projection.getExtent());
|
|
416
|
+
const worldsAway = getWorldsAway(coordinate, projection, worldWidth);
|
|
417
|
+
if (worldsAway) {
|
|
418
|
+
coordinate[0] -= worldsAway * worldWidth;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
return coordinate;
|
|
422
|
+
}
|
|
423
|
+
function getWorldsAway(coordinate, projection, sourceExtentWidth) {
|
|
424
|
+
const projectionExtent = projection.getExtent();
|
|
425
|
+
let worldsAway = 0;
|
|
426
|
+
if (projection.canWrapX() && (coordinate[0] < projectionExtent[0] || coordinate[0] > projectionExtent[2])) {
|
|
427
|
+
sourceExtentWidth = sourceExtentWidth || getWidth(projectionExtent);
|
|
428
|
+
worldsAway = Math.floor(
|
|
429
|
+
(coordinate[0] - projectionExtent[0]) / sourceExtentWidth
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
return worldsAway;
|
|
433
|
+
}
|
|
434
|
+
const DEFAULT_RADIUS = 63710088e-1;
|
|
435
|
+
function getDistance(c1, c2, radius) {
|
|
436
|
+
radius = radius || DEFAULT_RADIUS;
|
|
437
|
+
const lat1 = toRadians(c1[1]);
|
|
438
|
+
const lat2 = toRadians(c2[1]);
|
|
439
|
+
const deltaLatBy2 = (lat2 - lat1) / 2;
|
|
440
|
+
const deltaLonBy2 = toRadians(c2[0] - c1[0]) / 2;
|
|
441
|
+
const a = Math.sin(deltaLatBy2) * Math.sin(deltaLatBy2) + Math.sin(deltaLonBy2) * Math.sin(deltaLonBy2) * Math.cos(lat1) * Math.cos(lat2);
|
|
442
|
+
return 2 * radius * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
443
|
+
}
|
|
444
|
+
function warn(...args) {
|
|
445
|
+
console.warn(...args);
|
|
446
|
+
}
|
|
447
|
+
const METERS_PER_UNIT$1 = {
|
|
448
|
+
// use the radius of the Normal sphere
|
|
449
|
+
"radians": 6370997 / (2 * Math.PI),
|
|
450
|
+
"degrees": 2 * Math.PI * 6370997 / 360,
|
|
451
|
+
"ft": 0.3048,
|
|
452
|
+
"m": 1,
|
|
453
|
+
"us-ft": 1200 / 3937
|
|
454
|
+
};
|
|
455
|
+
class Projection {
|
|
456
|
+
/**
|
|
457
|
+
* @param {Options} options Projection options.
|
|
458
|
+
*/
|
|
459
|
+
constructor(options) {
|
|
460
|
+
this.code_ = options.code;
|
|
461
|
+
this.units_ = /** @type {import("./Units.js").Units} */
|
|
462
|
+
options.units;
|
|
463
|
+
this.extent_ = options.extent !== void 0 ? options.extent : null;
|
|
464
|
+
this.worldExtent_ = options.worldExtent !== void 0 ? options.worldExtent : null;
|
|
465
|
+
this.axisOrientation_ = options.axisOrientation !== void 0 ? options.axisOrientation : "enu";
|
|
466
|
+
this.global_ = options.global !== void 0 ? options.global : false;
|
|
467
|
+
this.canWrapX_ = !!(this.global_ && this.extent_);
|
|
468
|
+
this.getPointResolutionFunc_ = options.getPointResolution;
|
|
469
|
+
this.defaultTileGrid_ = null;
|
|
470
|
+
this.metersPerUnit_ = options.metersPerUnit;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* @return {boolean} The projection is suitable for wrapping the x-axis
|
|
474
|
+
*/
|
|
475
|
+
canWrapX() {
|
|
476
|
+
return this.canWrapX_;
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Get the code for this projection, e.g. 'EPSG:4326'.
|
|
480
|
+
* @return {string} Code.
|
|
481
|
+
* @api
|
|
482
|
+
*/
|
|
483
|
+
getCode() {
|
|
484
|
+
return this.code_;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Get the validity extent for this projection.
|
|
488
|
+
* @return {import("../extent.js").Extent} Extent.
|
|
489
|
+
* @api
|
|
490
|
+
*/
|
|
491
|
+
getExtent() {
|
|
492
|
+
return this.extent_;
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Get the units of this projection.
|
|
496
|
+
* @return {import("./Units.js").Units} Units.
|
|
497
|
+
* @api
|
|
498
|
+
*/
|
|
499
|
+
getUnits() {
|
|
500
|
+
return this.units_;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Get the amount of meters per unit of this projection. If the projection is
|
|
504
|
+
* not configured with `metersPerUnit` or a units identifier, the return is
|
|
505
|
+
* `undefined`.
|
|
506
|
+
* @return {number|undefined} Meters.
|
|
507
|
+
* @api
|
|
508
|
+
*/
|
|
509
|
+
getMetersPerUnit() {
|
|
510
|
+
return this.metersPerUnit_ || METERS_PER_UNIT$1[this.units_];
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Get the world extent for this projection.
|
|
514
|
+
* @return {import("../extent.js").Extent} Extent.
|
|
515
|
+
* @api
|
|
516
|
+
*/
|
|
517
|
+
getWorldExtent() {
|
|
518
|
+
return this.worldExtent_;
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Get the axis orientation of this projection.
|
|
522
|
+
* Example values are:
|
|
523
|
+
* enu - the default easting, northing, elevation.
|
|
524
|
+
* neu - northing, easting, up - useful for "lat/long" geographic coordinates,
|
|
525
|
+
* or south orientated transverse mercator.
|
|
526
|
+
* wnu - westing, northing, up - some planetary coordinate systems have
|
|
527
|
+
* "west positive" coordinate systems
|
|
528
|
+
* @return {string} Axis orientation.
|
|
529
|
+
* @api
|
|
530
|
+
*/
|
|
531
|
+
getAxisOrientation() {
|
|
532
|
+
return this.axisOrientation_;
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Is this projection a global projection which spans the whole world?
|
|
536
|
+
* @return {boolean} Whether the projection is global.
|
|
537
|
+
* @api
|
|
538
|
+
*/
|
|
539
|
+
isGlobal() {
|
|
540
|
+
return this.global_;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Set if the projection is a global projection which spans the whole world
|
|
544
|
+
* @param {boolean} global Whether the projection is global.
|
|
545
|
+
* @api
|
|
546
|
+
*/
|
|
547
|
+
setGlobal(global) {
|
|
548
|
+
this.global_ = global;
|
|
549
|
+
this.canWrapX_ = !!(global && this.extent_);
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* @return {import("../tilegrid/TileGrid.js").default} The default tile grid.
|
|
553
|
+
*/
|
|
554
|
+
getDefaultTileGrid() {
|
|
555
|
+
return this.defaultTileGrid_;
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* @param {import("../tilegrid/TileGrid.js").default} tileGrid The default tile grid.
|
|
559
|
+
*/
|
|
560
|
+
setDefaultTileGrid(tileGrid) {
|
|
561
|
+
this.defaultTileGrid_ = tileGrid;
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Set the validity extent for this projection.
|
|
565
|
+
* @param {import("../extent.js").Extent} extent Extent.
|
|
566
|
+
* @api
|
|
567
|
+
*/
|
|
568
|
+
setExtent(extent) {
|
|
569
|
+
this.extent_ = extent;
|
|
570
|
+
this.canWrapX_ = !!(this.global_ && extent);
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* Set the world extent for this projection.
|
|
574
|
+
* @param {import("../extent.js").Extent} worldExtent World extent
|
|
575
|
+
* [minlon, minlat, maxlon, maxlat].
|
|
576
|
+
* @api
|
|
577
|
+
*/
|
|
578
|
+
setWorldExtent(worldExtent) {
|
|
579
|
+
this.worldExtent_ = worldExtent;
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Set the getPointResolution function (see {@link module:ol/proj.getPointResolution}
|
|
583
|
+
* for this projection.
|
|
584
|
+
* @param {function(number, import("../coordinate.js").Coordinate):number} func Function
|
|
585
|
+
* @api
|
|
586
|
+
*/
|
|
587
|
+
setGetPointResolution(func) {
|
|
588
|
+
this.getPointResolutionFunc_ = func;
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Get the custom point resolution function for this projection (if set).
|
|
592
|
+
* @return {GetPointResolution|undefined} The custom point
|
|
593
|
+
* resolution function (if set).
|
|
594
|
+
*/
|
|
595
|
+
getPointResolutionFunc() {
|
|
596
|
+
return this.getPointResolutionFunc_;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
const RADIUS$1 = 6378137;
|
|
600
|
+
const HALF_SIZE = Math.PI * RADIUS$1;
|
|
601
|
+
const EXTENT$1 = [-HALF_SIZE, -HALF_SIZE, HALF_SIZE, HALF_SIZE];
|
|
602
|
+
const WORLD_EXTENT = [-180, -85, 180, 85];
|
|
603
|
+
const MAX_SAFE_Y = RADIUS$1 * Math.log(Math.tan(Math.PI / 2));
|
|
604
|
+
class EPSG3857Projection extends Projection {
|
|
605
|
+
/**
|
|
606
|
+
* @param {string} code Code.
|
|
607
|
+
*/
|
|
608
|
+
constructor(code) {
|
|
609
|
+
super({
|
|
610
|
+
code,
|
|
611
|
+
units: "m",
|
|
612
|
+
extent: EXTENT$1,
|
|
613
|
+
global: true,
|
|
614
|
+
worldExtent: WORLD_EXTENT,
|
|
615
|
+
getPointResolution: function(resolution, point) {
|
|
616
|
+
return resolution / Math.cosh(point[1] / RADIUS$1);
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
const PROJECTIONS$1 = [
|
|
622
|
+
new EPSG3857Projection("EPSG:3857"),
|
|
623
|
+
new EPSG3857Projection("EPSG:102100"),
|
|
624
|
+
new EPSG3857Projection("EPSG:102113"),
|
|
625
|
+
new EPSG3857Projection("EPSG:900913"),
|
|
626
|
+
new EPSG3857Projection("http://www.opengis.net/def/crs/EPSG/0/3857"),
|
|
627
|
+
new EPSG3857Projection("http://www.opengis.net/gml/srs/epsg.xml#3857")
|
|
628
|
+
];
|
|
629
|
+
function fromEPSG4326(input, output, dimension, stride) {
|
|
630
|
+
const length = input.length;
|
|
631
|
+
dimension = dimension > 1 ? dimension : 2;
|
|
632
|
+
stride = stride != null ? stride : dimension;
|
|
633
|
+
if (output === void 0) {
|
|
634
|
+
if (dimension > 2) {
|
|
635
|
+
output = input.slice();
|
|
636
|
+
} else {
|
|
637
|
+
output = new Array(length);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
for (let i = 0; i < length; i += stride) {
|
|
641
|
+
output[i] = HALF_SIZE * input[i] / 180;
|
|
642
|
+
let y = RADIUS$1 * Math.log(Math.tan(Math.PI * (+input[i + 1] + 90) / 360));
|
|
643
|
+
if (y > MAX_SAFE_Y) {
|
|
644
|
+
y = MAX_SAFE_Y;
|
|
645
|
+
} else if (y < -MAX_SAFE_Y) {
|
|
646
|
+
y = -MAX_SAFE_Y;
|
|
647
|
+
}
|
|
648
|
+
output[i + 1] = y;
|
|
649
|
+
}
|
|
650
|
+
return output;
|
|
651
|
+
}
|
|
652
|
+
function toEPSG4326(input, output, dimension, stride) {
|
|
653
|
+
const length = input.length;
|
|
654
|
+
dimension = dimension > 1 ? dimension : 2;
|
|
655
|
+
stride = stride != null ? stride : dimension;
|
|
656
|
+
if (output === void 0) {
|
|
657
|
+
if (dimension > 2) {
|
|
658
|
+
output = input.slice();
|
|
659
|
+
} else {
|
|
660
|
+
output = new Array(length);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
for (let i = 0; i < length; i += stride) {
|
|
664
|
+
output[i] = 180 * input[i] / HALF_SIZE;
|
|
665
|
+
output[i + 1] = 360 * Math.atan(Math.exp(input[i + 1] / RADIUS$1)) / Math.PI - 90;
|
|
666
|
+
}
|
|
667
|
+
return output;
|
|
668
|
+
}
|
|
669
|
+
const RADIUS = 6378137;
|
|
670
|
+
const EXTENT = [-180, -90, 180, 90];
|
|
671
|
+
const METERS_PER_UNIT = Math.PI * RADIUS / 180;
|
|
672
|
+
class EPSG4326Projection extends Projection {
|
|
673
|
+
/**
|
|
674
|
+
* @param {string} code Code.
|
|
675
|
+
* @param {string} [axisOrientation] Axis orientation.
|
|
676
|
+
*/
|
|
677
|
+
constructor(code, axisOrientation) {
|
|
678
|
+
super({
|
|
679
|
+
code,
|
|
680
|
+
units: "degrees",
|
|
681
|
+
extent: EXTENT,
|
|
682
|
+
axisOrientation,
|
|
683
|
+
global: true,
|
|
684
|
+
metersPerUnit: METERS_PER_UNIT,
|
|
685
|
+
worldExtent: EXTENT
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
const PROJECTIONS = [
|
|
690
|
+
new EPSG4326Projection("CRS:84"),
|
|
691
|
+
new EPSG4326Projection("EPSG:4326", "neu"),
|
|
692
|
+
new EPSG4326Projection("urn:ogc:def:crs:OGC:1.3:CRS84"),
|
|
693
|
+
new EPSG4326Projection("urn:ogc:def:crs:OGC:2:84"),
|
|
694
|
+
new EPSG4326Projection("http://www.opengis.net/def/crs/OGC/1.3/CRS84"),
|
|
695
|
+
new EPSG4326Projection("http://www.opengis.net/gml/srs/epsg.xml#4326", "neu"),
|
|
696
|
+
new EPSG4326Projection("http://www.opengis.net/def/crs/EPSG/0/4326", "neu")
|
|
697
|
+
];
|
|
698
|
+
let cache = {};
|
|
699
|
+
function get$2(code) {
|
|
700
|
+
return cache[code] || cache[code.replace(/urn:(x-)?ogc:def:crs:EPSG:(.*:)?(\w+)$/, "EPSG:$3")] || null;
|
|
701
|
+
}
|
|
702
|
+
function add$1(code, projection) {
|
|
703
|
+
cache[code] = projection;
|
|
704
|
+
}
|
|
705
|
+
let transforms = {};
|
|
706
|
+
function add(source, destination, transformFn) {
|
|
707
|
+
const sourceCode = source.getCode();
|
|
708
|
+
const destinationCode = destination.getCode();
|
|
709
|
+
if (!(sourceCode in transforms)) {
|
|
710
|
+
transforms[sourceCode] = {};
|
|
711
|
+
}
|
|
712
|
+
transforms[sourceCode][destinationCode] = transformFn;
|
|
713
|
+
}
|
|
714
|
+
function get$1(sourceCode, destinationCode) {
|
|
715
|
+
if (sourceCode in transforms && destinationCode in transforms[sourceCode]) {
|
|
716
|
+
return transforms[sourceCode][destinationCode];
|
|
717
|
+
}
|
|
718
|
+
return null;
|
|
719
|
+
}
|
|
720
|
+
const K0 = 0.9996;
|
|
721
|
+
const E = 669438e-8;
|
|
722
|
+
const E2 = E * E;
|
|
723
|
+
const E3 = E2 * E;
|
|
724
|
+
const E_P2 = E / (1 - E);
|
|
725
|
+
const SQRT_E = Math.sqrt(1 - E);
|
|
726
|
+
const _E = (1 - SQRT_E) / (1 + SQRT_E);
|
|
727
|
+
const _E2 = _E * _E;
|
|
728
|
+
const _E3 = _E2 * _E;
|
|
729
|
+
const _E4 = _E3 * _E;
|
|
730
|
+
const _E5 = _E4 * _E;
|
|
731
|
+
const M1 = 1 - E / 4 - 3 * E2 / 64 - 5 * E3 / 256;
|
|
732
|
+
const M2 = 3 * E / 8 + 3 * E2 / 32 + 45 * E3 / 1024;
|
|
733
|
+
const M3 = 15 * E2 / 256 + 45 * E3 / 1024;
|
|
734
|
+
const M4 = 35 * E3 / 3072;
|
|
735
|
+
const P2 = 3 / 2 * _E - 27 / 32 * _E3 + 269 / 512 * _E5;
|
|
736
|
+
const P3 = 21 / 16 * _E2 - 55 / 32 * _E4;
|
|
737
|
+
const P4 = 151 / 96 * _E3 - 417 / 128 * _E5;
|
|
738
|
+
const P5 = 1097 / 512 * _E4;
|
|
739
|
+
const R = 6378137;
|
|
740
|
+
function toLonLat$1(easting, northing, zone) {
|
|
741
|
+
const x = easting - 5e5;
|
|
742
|
+
const y = zone.north ? northing : northing - 1e7;
|
|
743
|
+
const m = y / K0;
|
|
744
|
+
const mu = m / (R * M1);
|
|
745
|
+
const pRad = mu + P2 * Math.sin(2 * mu) + P3 * Math.sin(4 * mu) + P4 * Math.sin(6 * mu) + P5 * Math.sin(8 * mu);
|
|
746
|
+
const pSin = Math.sin(pRad);
|
|
747
|
+
const pSin2 = pSin * pSin;
|
|
748
|
+
const pCos = Math.cos(pRad);
|
|
749
|
+
const pTan = pSin / pCos;
|
|
750
|
+
const pTan2 = pTan * pTan;
|
|
751
|
+
const pTan4 = pTan2 * pTan2;
|
|
752
|
+
const epSin = 1 - E * pSin2;
|
|
753
|
+
const epSinSqrt = Math.sqrt(1 - E * pSin2);
|
|
754
|
+
const n = R / epSinSqrt;
|
|
755
|
+
const r = (1 - E) / epSin;
|
|
756
|
+
const c = E_P2 * __pow(pCos, 2);
|
|
757
|
+
const c2 = c * c;
|
|
758
|
+
const d = x / (n * K0);
|
|
759
|
+
const d2 = d * d;
|
|
760
|
+
const d3 = d2 * d;
|
|
761
|
+
const d4 = d3 * d;
|
|
762
|
+
const d5 = d4 * d;
|
|
763
|
+
const d6 = d5 * d;
|
|
764
|
+
const latitude = pRad - pTan / r * (d2 / 2 - d4 / 24 * (5 + 3 * pTan2 + 10 * c - 4 * c2 - 9 * E_P2)) + d6 / 720 * (61 + 90 * pTan2 + 298 * c + 45 * pTan4 - 252 * E_P2 - 3 * c2);
|
|
765
|
+
let longitude = (d - d3 / 6 * (1 + 2 * pTan2 + c) + d5 / 120 * (5 - 2 * c + 28 * pTan2 - 3 * c2 + 8 * E_P2 + 24 * pTan4)) / pCos;
|
|
766
|
+
longitude = wrap(
|
|
767
|
+
longitude + toRadians(zoneToCentralLongitude(zone.number)),
|
|
768
|
+
-Math.PI,
|
|
769
|
+
Math.PI
|
|
770
|
+
);
|
|
771
|
+
return [toDegrees(longitude), toDegrees(latitude)];
|
|
772
|
+
}
|
|
773
|
+
const MIN_LATITUDE = -80;
|
|
774
|
+
const MAX_LATITUDE = 84;
|
|
775
|
+
const MIN_LONGITUDE = -180;
|
|
776
|
+
const MAX_LONGITUDE = 180;
|
|
777
|
+
function fromLonLat$1(longitude, latitude, zone) {
|
|
778
|
+
longitude = wrap(longitude, MIN_LONGITUDE, MAX_LONGITUDE);
|
|
779
|
+
if (latitude < MIN_LATITUDE) {
|
|
780
|
+
latitude = MIN_LATITUDE;
|
|
781
|
+
} else if (latitude > MAX_LATITUDE) {
|
|
782
|
+
latitude = MAX_LATITUDE;
|
|
783
|
+
}
|
|
784
|
+
const latRad = toRadians(latitude);
|
|
785
|
+
const latSin = Math.sin(latRad);
|
|
786
|
+
const latCos = Math.cos(latRad);
|
|
787
|
+
const latTan = latSin / latCos;
|
|
788
|
+
const latTan2 = latTan * latTan;
|
|
789
|
+
const latTan4 = latTan2 * latTan2;
|
|
790
|
+
const lonRad = toRadians(longitude);
|
|
791
|
+
const centralLon = zoneToCentralLongitude(zone.number);
|
|
792
|
+
const centralLonRad = toRadians(centralLon);
|
|
793
|
+
const n = R / Math.sqrt(1 - E * __pow(latSin, 2));
|
|
794
|
+
const c = E_P2 * __pow(latCos, 2);
|
|
795
|
+
const a = latCos * wrap(lonRad - centralLonRad, -Math.PI, Math.PI);
|
|
796
|
+
const a2 = a * a;
|
|
797
|
+
const a3 = a2 * a;
|
|
798
|
+
const a4 = a3 * a;
|
|
799
|
+
const a5 = a4 * a;
|
|
800
|
+
const a6 = a5 * a;
|
|
801
|
+
const m = R * (M1 * latRad - M2 * Math.sin(2 * latRad) + M3 * Math.sin(4 * latRad) - M4 * Math.sin(6 * latRad));
|
|
802
|
+
const easting = K0 * n * (a + a3 / 6 * (1 - latTan2 + c) + a5 / 120 * (5 - 18 * latTan2 + latTan4 + 72 * c - 58 * E_P2)) + 5e5;
|
|
803
|
+
let northing = K0 * (m + n * latTan * (a2 / 2 + a4 / 24 * (5 - latTan2 + 9 * c + 4 * __pow(c, 2)) + a6 / 720 * (61 - 58 * latTan2 + latTan4 + 600 * c - 330 * E_P2)));
|
|
804
|
+
if (!zone.north) {
|
|
805
|
+
northing += 1e7;
|
|
806
|
+
}
|
|
807
|
+
return [easting, northing];
|
|
808
|
+
}
|
|
809
|
+
function zoneToCentralLongitude(zone) {
|
|
810
|
+
return (zone - 1) * 6 - 180 + 3;
|
|
811
|
+
}
|
|
812
|
+
const epsgRegExes = [
|
|
813
|
+
/^EPSG:(\d+)$/,
|
|
814
|
+
/^urn:ogc:def:crs:EPSG::(\d+)$/,
|
|
815
|
+
/^http:\/\/www\.opengis\.net\/def\/crs\/EPSG\/0\/(\d+)$/
|
|
816
|
+
];
|
|
817
|
+
function zoneFromCode(code) {
|
|
818
|
+
let epsgId = 0;
|
|
819
|
+
for (const re of epsgRegExes) {
|
|
820
|
+
const match = code.match(re);
|
|
821
|
+
if (match) {
|
|
822
|
+
epsgId = parseInt(match[1]);
|
|
823
|
+
break;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
if (!epsgId) {
|
|
827
|
+
return null;
|
|
828
|
+
}
|
|
829
|
+
let number = 0;
|
|
830
|
+
let north = false;
|
|
831
|
+
if (epsgId > 32700 && epsgId < 32761) {
|
|
832
|
+
number = epsgId - 32700;
|
|
833
|
+
} else if (epsgId > 32600 && epsgId < 32661) {
|
|
834
|
+
north = true;
|
|
835
|
+
number = epsgId - 32600;
|
|
836
|
+
}
|
|
837
|
+
if (!number) {
|
|
838
|
+
return null;
|
|
839
|
+
}
|
|
840
|
+
return { number, north };
|
|
841
|
+
}
|
|
842
|
+
function makeTransformFunction(transformer, zone) {
|
|
843
|
+
return function(input, output, dimension, stride) {
|
|
844
|
+
const length = input.length;
|
|
845
|
+
dimension = dimension > 1 ? dimension : 2;
|
|
846
|
+
stride = stride != null ? stride : dimension;
|
|
847
|
+
if (!output) {
|
|
848
|
+
if (dimension > 2) {
|
|
849
|
+
output = input.slice();
|
|
850
|
+
} else {
|
|
851
|
+
output = new Array(length);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
for (let i = 0; i < length; i += stride) {
|
|
855
|
+
const x = input[i];
|
|
856
|
+
const y = input[i + 1];
|
|
857
|
+
const coord = transformer(x, y, zone);
|
|
858
|
+
output[i] = coord[0];
|
|
859
|
+
output[i + 1] = coord[1];
|
|
860
|
+
}
|
|
861
|
+
return output;
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
function makeProjection(code) {
|
|
865
|
+
const zone = zoneFromCode(code);
|
|
866
|
+
if (!zone) {
|
|
867
|
+
return null;
|
|
868
|
+
}
|
|
869
|
+
return new Projection({ code, units: "m" });
|
|
870
|
+
}
|
|
871
|
+
function makeTransforms(projection) {
|
|
872
|
+
const zone = zoneFromCode(projection.getCode());
|
|
873
|
+
if (!zone) {
|
|
874
|
+
return null;
|
|
875
|
+
}
|
|
876
|
+
return {
|
|
877
|
+
forward: makeTransformFunction(fromLonLat$1, zone),
|
|
878
|
+
inverse: makeTransformFunction(toLonLat$1, zone)
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
const transformFactories = [makeTransforms];
|
|
882
|
+
const projectionFactories = [makeProjection];
|
|
883
|
+
let showCoordinateWarning = true;
|
|
884
|
+
function disableCoordinateWarning(disable) {
|
|
885
|
+
showCoordinateWarning = false;
|
|
886
|
+
}
|
|
887
|
+
function cloneTransform(input, output) {
|
|
888
|
+
if (output !== void 0) {
|
|
889
|
+
for (let i = 0, ii = input.length; i < ii; ++i) {
|
|
890
|
+
output[i] = input[i];
|
|
891
|
+
}
|
|
892
|
+
output = output;
|
|
893
|
+
} else {
|
|
894
|
+
output = input.slice();
|
|
895
|
+
}
|
|
896
|
+
return output;
|
|
897
|
+
}
|
|
898
|
+
function addProjection(projection) {
|
|
899
|
+
add$1(projection.getCode(), projection);
|
|
900
|
+
add(projection, projection, cloneTransform);
|
|
901
|
+
}
|
|
902
|
+
function addProjections(projections) {
|
|
903
|
+
projections.forEach(addProjection);
|
|
904
|
+
}
|
|
905
|
+
function get(projectionLike) {
|
|
906
|
+
if (!(typeof projectionLike === "string")) {
|
|
907
|
+
return projectionLike;
|
|
908
|
+
}
|
|
909
|
+
const projection = get$2(projectionLike);
|
|
910
|
+
if (projection) {
|
|
911
|
+
return projection;
|
|
912
|
+
}
|
|
913
|
+
for (const makeProjection2 of projectionFactories) {
|
|
914
|
+
const projection2 = makeProjection2(projectionLike);
|
|
915
|
+
if (projection2) {
|
|
916
|
+
return projection2;
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
return null;
|
|
920
|
+
}
|
|
921
|
+
function getPointResolution(projection, resolution, point, units) {
|
|
922
|
+
projection = get(projection);
|
|
923
|
+
let pointResolution;
|
|
924
|
+
const getter = projection.getPointResolutionFunc();
|
|
925
|
+
if (getter) {
|
|
926
|
+
pointResolution = getter(resolution, point);
|
|
927
|
+
} else {
|
|
928
|
+
const projUnits = projection.getUnits();
|
|
929
|
+
if (projUnits == "degrees" && !units || units == "degrees") {
|
|
930
|
+
pointResolution = resolution;
|
|
931
|
+
} else {
|
|
932
|
+
const toEPSG43262 = getTransformFromProjections(
|
|
933
|
+
projection,
|
|
934
|
+
get("EPSG:4326")
|
|
935
|
+
);
|
|
936
|
+
if (!toEPSG43262 && projUnits !== "degrees") {
|
|
937
|
+
pointResolution = resolution * projection.getMetersPerUnit();
|
|
938
|
+
} else {
|
|
939
|
+
let vertices = [
|
|
940
|
+
point[0] - resolution / 2,
|
|
941
|
+
point[1],
|
|
942
|
+
point[0] + resolution / 2,
|
|
943
|
+
point[1],
|
|
944
|
+
point[0],
|
|
945
|
+
point[1] - resolution / 2,
|
|
946
|
+
point[0],
|
|
947
|
+
point[1] + resolution / 2
|
|
948
|
+
];
|
|
949
|
+
vertices = toEPSG43262(vertices, vertices, 2);
|
|
950
|
+
const width = getDistance(vertices.slice(0, 2), vertices.slice(2, 4));
|
|
951
|
+
const height = getDistance(vertices.slice(4, 6), vertices.slice(6, 8));
|
|
952
|
+
pointResolution = (width + height) / 2;
|
|
953
|
+
}
|
|
954
|
+
const metersPerUnit = projection.getMetersPerUnit();
|
|
955
|
+
if (metersPerUnit !== void 0) {
|
|
956
|
+
pointResolution /= metersPerUnit;
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
return pointResolution;
|
|
961
|
+
}
|
|
962
|
+
function addEquivalentProjections(projections) {
|
|
963
|
+
addProjections(projections);
|
|
964
|
+
projections.forEach(function(source) {
|
|
965
|
+
projections.forEach(function(destination) {
|
|
966
|
+
if (source !== destination) {
|
|
967
|
+
add(source, destination, cloneTransform);
|
|
968
|
+
}
|
|
969
|
+
});
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
function addEquivalentTransforms(projections1, projections2, forwardTransform, inverseTransform) {
|
|
973
|
+
projections1.forEach(function(projection1) {
|
|
974
|
+
projections2.forEach(function(projection2) {
|
|
975
|
+
add(projection1, projection2, forwardTransform);
|
|
976
|
+
add(projection2, projection1, inverseTransform);
|
|
977
|
+
});
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
function createProjection(projection, defaultCode) {
|
|
981
|
+
if (!projection) {
|
|
982
|
+
return get(defaultCode);
|
|
983
|
+
}
|
|
984
|
+
if (typeof projection === "string") {
|
|
985
|
+
return get(projection);
|
|
986
|
+
}
|
|
987
|
+
return (
|
|
988
|
+
/** @type {Projection} */
|
|
989
|
+
projection
|
|
990
|
+
);
|
|
991
|
+
}
|
|
992
|
+
function createTransformFromCoordinateTransform(coordTransform) {
|
|
993
|
+
return (
|
|
994
|
+
/**
|
|
995
|
+
* @param {Array<number>} input Input.
|
|
996
|
+
* @param {Array<number>} [output] Output.
|
|
997
|
+
* @param {number} [dimension] Dimensions that should be transformed.
|
|
998
|
+
* @param {number} [stride] Stride.
|
|
999
|
+
* @return {Array<number>} Output.
|
|
1000
|
+
*/
|
|
1001
|
+
(function(input, output, dimension, stride) {
|
|
1002
|
+
const length = input.length;
|
|
1003
|
+
dimension = dimension !== void 0 ? dimension : 2;
|
|
1004
|
+
stride = stride != null ? stride : dimension;
|
|
1005
|
+
output = output !== void 0 ? output : new Array(length);
|
|
1006
|
+
for (let i = 0; i < length; i += stride) {
|
|
1007
|
+
const point = coordTransform(input.slice(i, i + dimension));
|
|
1008
|
+
const pointLength = point.length;
|
|
1009
|
+
for (let j = 0, jj = stride; j < jj; ++j) {
|
|
1010
|
+
output[i + j] = j >= pointLength ? input[i + j] : point[j];
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
return output;
|
|
1014
|
+
})
|
|
1015
|
+
);
|
|
1016
|
+
}
|
|
1017
|
+
function fromLonLat(coordinate, projection) {
|
|
1018
|
+
disableCoordinateWarning();
|
|
1019
|
+
return transform(
|
|
1020
|
+
coordinate,
|
|
1021
|
+
"EPSG:4326",
|
|
1022
|
+
projection !== void 0 ? projection : "EPSG:3857"
|
|
1023
|
+
);
|
|
1024
|
+
}
|
|
1025
|
+
function toLonLat(coordinate, projection) {
|
|
1026
|
+
const lonLat = transform(
|
|
1027
|
+
coordinate,
|
|
1028
|
+
projection !== void 0 ? projection : "EPSG:3857",
|
|
1029
|
+
"EPSG:4326"
|
|
1030
|
+
);
|
|
1031
|
+
const lon = lonLat[0];
|
|
1032
|
+
if (lon < -180 || lon > 180) {
|
|
1033
|
+
lonLat[0] = modulo(lon + 180, 360) - 180;
|
|
1034
|
+
}
|
|
1035
|
+
return lonLat;
|
|
1036
|
+
}
|
|
1037
|
+
function equivalent(projection1, projection2) {
|
|
1038
|
+
if (projection1 === projection2) {
|
|
1039
|
+
return true;
|
|
1040
|
+
}
|
|
1041
|
+
const equalUnits = projection1.getUnits() === projection2.getUnits();
|
|
1042
|
+
if (projection1.getCode() === projection2.getCode()) {
|
|
1043
|
+
return equalUnits;
|
|
1044
|
+
}
|
|
1045
|
+
const transformFunc = getTransformFromProjections(projection1, projection2);
|
|
1046
|
+
return transformFunc === cloneTransform && equalUnits;
|
|
1047
|
+
}
|
|
1048
|
+
function getTransformFromProjections(source, destination) {
|
|
1049
|
+
const sourceCode = source.getCode();
|
|
1050
|
+
const destinationCode = destination.getCode();
|
|
1051
|
+
let transformFunc = get$1(sourceCode, destinationCode);
|
|
1052
|
+
if (transformFunc) {
|
|
1053
|
+
return transformFunc;
|
|
1054
|
+
}
|
|
1055
|
+
let sourceTransforms = null;
|
|
1056
|
+
let destinationTransforms = null;
|
|
1057
|
+
for (const makeTransforms2 of transformFactories) {
|
|
1058
|
+
if (!sourceTransforms) {
|
|
1059
|
+
sourceTransforms = makeTransforms2(source);
|
|
1060
|
+
}
|
|
1061
|
+
if (!destinationTransforms) {
|
|
1062
|
+
destinationTransforms = makeTransforms2(destination);
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
if (!sourceTransforms && !destinationTransforms) {
|
|
1066
|
+
return null;
|
|
1067
|
+
}
|
|
1068
|
+
const intermediateCode = "EPSG:4326";
|
|
1069
|
+
if (!destinationTransforms) {
|
|
1070
|
+
const toDestination = get$1(intermediateCode, destinationCode);
|
|
1071
|
+
if (toDestination) {
|
|
1072
|
+
transformFunc = composeTransformFuncs(
|
|
1073
|
+
sourceTransforms.inverse,
|
|
1074
|
+
toDestination
|
|
1075
|
+
);
|
|
1076
|
+
}
|
|
1077
|
+
} else if (!sourceTransforms) {
|
|
1078
|
+
const fromSource = get$1(sourceCode, intermediateCode);
|
|
1079
|
+
if (fromSource) {
|
|
1080
|
+
transformFunc = composeTransformFuncs(
|
|
1081
|
+
fromSource,
|
|
1082
|
+
destinationTransforms.forward
|
|
1083
|
+
);
|
|
1084
|
+
}
|
|
1085
|
+
} else {
|
|
1086
|
+
transformFunc = composeTransformFuncs(
|
|
1087
|
+
sourceTransforms.inverse,
|
|
1088
|
+
destinationTransforms.forward
|
|
1089
|
+
);
|
|
1090
|
+
}
|
|
1091
|
+
if (transformFunc) {
|
|
1092
|
+
addProjection(source);
|
|
1093
|
+
addProjection(destination);
|
|
1094
|
+
add(source, destination, transformFunc);
|
|
1095
|
+
}
|
|
1096
|
+
return transformFunc;
|
|
1097
|
+
}
|
|
1098
|
+
function composeTransformFuncs(t1, t2) {
|
|
1099
|
+
return function(input, output, dimensions, stride) {
|
|
1100
|
+
output = t1(input, output, dimensions, stride);
|
|
1101
|
+
return t2(output, output, dimensions, stride);
|
|
1102
|
+
};
|
|
1103
|
+
}
|
|
1104
|
+
function getTransform(source, destination) {
|
|
1105
|
+
const sourceProjection = get(source);
|
|
1106
|
+
const destinationProjection = get(destination);
|
|
1107
|
+
return getTransformFromProjections(sourceProjection, destinationProjection);
|
|
1108
|
+
}
|
|
1109
|
+
function transform(coordinate, source, destination) {
|
|
1110
|
+
const transformFunc = getTransform(source, destination);
|
|
1111
|
+
if (!transformFunc) {
|
|
1112
|
+
const sourceCode = get(source).getCode();
|
|
1113
|
+
const destinationCode = get(destination).getCode();
|
|
1114
|
+
throw new Error(
|
|
1115
|
+
`No transform available between ${sourceCode} and ${destinationCode}`
|
|
1116
|
+
);
|
|
1117
|
+
}
|
|
1118
|
+
return transformFunc(coordinate, void 0, coordinate.length);
|
|
1119
|
+
}
|
|
1120
|
+
function toUserCoordinate(coordinate, sourceProjection) {
|
|
1121
|
+
{
|
|
1122
|
+
return coordinate;
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
function fromUserCoordinate(coordinate, destProjection) {
|
|
1126
|
+
{
|
|
1127
|
+
if (showCoordinateWarning && !equals(coordinate, [0, 0]) && coordinate[0] >= -180 && coordinate[0] <= 180 && coordinate[1] >= -90 && coordinate[1] <= 90) {
|
|
1128
|
+
showCoordinateWarning = false;
|
|
1129
|
+
warn(
|
|
1130
|
+
"Call useGeographic() from ol/proj once to work with [longitude, latitude] coordinates."
|
|
1131
|
+
);
|
|
1132
|
+
}
|
|
1133
|
+
return coordinate;
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
function toUserExtent(extent, sourceProjection) {
|
|
1137
|
+
{
|
|
1138
|
+
return extent;
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
function fromUserExtent(extent, destProjection) {
|
|
1142
|
+
{
|
|
1143
|
+
return extent;
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
function addCommon() {
|
|
1147
|
+
addEquivalentProjections(PROJECTIONS$1);
|
|
1148
|
+
addEquivalentProjections(PROJECTIONS);
|
|
1149
|
+
addEquivalentTransforms(
|
|
1150
|
+
PROJECTIONS,
|
|
1151
|
+
PROJECTIONS$1,
|
|
1152
|
+
fromEPSG4326,
|
|
1153
|
+
toEPSG4326
|
|
1154
|
+
);
|
|
1155
|
+
}
|
|
1156
|
+
addCommon();
|
|
1157
|
+
export {
|
|
1158
|
+
getCorner as $,
|
|
1159
|
+
warn as A,
|
|
1160
|
+
containsCoordinate as B,
|
|
1161
|
+
coordinateRelationship as C,
|
|
1162
|
+
buffer as D,
|
|
1163
|
+
createOrUpdate as E,
|
|
1164
|
+
extendCoordinate as F,
|
|
1165
|
+
getTopLeft as G,
|
|
1166
|
+
getTopRight as H,
|
|
1167
|
+
getBottomRight as I,
|
|
1168
|
+
getBottomLeft as J,
|
|
1169
|
+
containsExtent as K,
|
|
1170
|
+
wrapX$1 as L,
|
|
1171
|
+
METERS_PER_UNIT$1 as M,
|
|
1172
|
+
extend as N,
|
|
1173
|
+
transform as O,
|
|
1174
|
+
getPointResolution as P,
|
|
1175
|
+
createTransformFromCoordinateTransform as Q,
|
|
1176
|
+
Relationship as R,
|
|
1177
|
+
getTransform as S,
|
|
1178
|
+
getArea as T,
|
|
1179
|
+
boundingExtent as U,
|
|
1180
|
+
wrapAndSliceX as V,
|
|
1181
|
+
equivalent as W,
|
|
1182
|
+
getRotatedViewport as X,
|
|
1183
|
+
createOrUpdateFromFlatCoordinates as Y,
|
|
1184
|
+
createOrUpdateFromCoordinate as Z,
|
|
1185
|
+
get as _,
|
|
1186
|
+
createEmpty as a,
|
|
1187
|
+
returnOrUpdate as a0,
|
|
1188
|
+
containsXY as a1,
|
|
1189
|
+
fromLonLat as a2,
|
|
1190
|
+
toLonLat as a3,
|
|
1191
|
+
intersectsSegment as b,
|
|
1192
|
+
closestSquaredDistanceXY as c,
|
|
1193
|
+
isEmpty as d,
|
|
1194
|
+
extendFlatCoordinates as e,
|
|
1195
|
+
forEachCorner as f,
|
|
1196
|
+
getCenter as g,
|
|
1197
|
+
getWidth as h,
|
|
1198
|
+
intersects as i,
|
|
1199
|
+
getHeight as j,
|
|
1200
|
+
createProjection as k,
|
|
1201
|
+
fromUserCoordinate as l,
|
|
1202
|
+
fromUserExtent as m,
|
|
1203
|
+
add$2 as n,
|
|
1204
|
+
toUserExtent as o,
|
|
1205
|
+
getForViewAndSize as p,
|
|
1206
|
+
equals as q,
|
|
1207
|
+
rotate as r,
|
|
1208
|
+
disableCoordinateWarning as s,
|
|
1209
|
+
toUserCoordinate as t,
|
|
1210
|
+
scale as u,
|
|
1211
|
+
getIntersection as v,
|
|
1212
|
+
wrapX as w,
|
|
1213
|
+
equals$1 as x,
|
|
1214
|
+
createOrUpdateEmpty as y,
|
|
1215
|
+
clone as z
|
|
1216
|
+
};
|