Make proj4 transforms behave like built-in transforms

This commit is contained in:
Andreas Hocevar
2020-06-26 00:16:52 +02:00
parent 4758b533d0
commit bef4d8a494
4 changed files with 100 additions and 15 deletions
+16 -11
View File
@@ -410,17 +410,22 @@ export function toStringXY(coordinate, opt_fractionDigits) {
* @return {Coordinate} The coordinate within the real world extent.
*/
export function wrapX(coordinate, projection) {
const projectionExtent = projection.getExtent();
if (
projection.canWrapX() &&
(coordinate[0] < projectionExtent[0] ||
coordinate[0] >= projectionExtent[2])
) {
const worldWidth = getWidth(projectionExtent);
const worldsAway = Math.floor(
(coordinate[0] - projectionExtent[0]) / worldWidth
);
coordinate[0] -= worldsAway * worldWidth;
const worldsAway = getWorldsAway(coordinate, projection);
if (worldsAway) {
coordinate[0] -= worldsAway * getWidth(projection.getExtent());
}
return coordinate;
}
export function getWorldsAway(coordinate, projection) {
const projectionExtent = projection.getExtent();
let worldsAway = 0;
if (
projection.canWrapX() &&
(coordinate[0] < projectionExtent[0] || coordinate[0] > projectionExtent[2])
) {
const worldWidth = getWidth(projectionExtent);
worldsAway = Math.floor((coordinate[0] - projectionExtent[0]) / worldWidth);
}
return worldsAway;
}