Skip to content

Commit

Permalink
refactor: rely on affine transformations in the legacy CRS
Browse files Browse the repository at this point in the history
Issue: #237
Issue: #300
  • Loading branch information
alex4401 committed Jul 21, 2024
1 parent aff371c commit 56351d0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 76 deletions.
15 changes: 3 additions & 12 deletions modules/core/CoordinateSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ module.exports = class CoordinateSystem {
*/
fromPoint( point ) {
const
y = (
this.origin === CRSOrigin.TopLeft ? ( this.bottomRight[ 0 ] - point[ 0 ] ) : point[ 0 ]
) * this.scaleY,
y = point[ 0 ] * this.scaleY,
x = point[ 1 ] * this.scaleX;
return [ x * this.rSin + y * this.rCos, x * this.rCos - y * this.rSin ];
}
Expand All @@ -49,13 +47,9 @@ module.exports = class CoordinateSystem {
*/
fromBox( box ) {
const
sY = (
this.origin === CRSOrigin.TopLeft ? ( this.bottomRight[ 0 ] - box[ 0 ][ 0 ] ) : box[ 0 ][ 0 ]
) * this.scaleY,
sY = box[ 0 ][ 0 ] * this.scaleY,
sX = box[ 0 ][ 1 ] * this.scaleX,
eY = (
this.origin === CRSOrigin.TopLeft ? ( this.bottomRight[ 0 ] - box[ 1 ][ 0 ] ) : box[ 1 ][ 0 ]
) * this.scaleY,
eY = box[ 1 ][ 0 ] * this.scaleY,
eX = box[ 1 ][ 1 ] * this.scaleX;
return [
[ sY, sX ],
Expand All @@ -72,9 +66,6 @@ module.exports = class CoordinateSystem {
fromLeaflet( latlng, round ) {
let lat = latlng.lat / this.scaleY,
lon = latlng.lng / this.scaleX;
if ( this.origin === CRSOrigin.TopLeft ) {
lat = this.bottomRight[ 0 ] - lat;
}

if ( this.rotation ) {
[ lat, lon ] = [
Expand Down
64 changes: 0 additions & 64 deletions modules/core/CoordinateSystemNew.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,68 +11,4 @@ module.exports = class CoordinateSystemNew extends CoordinateSystem {
this.scaleX = 0.01;
this.scaleY = 0.01;
}


/**
* Maps a point from map's coordinate reference system specified by the server, to the universal space [ 0 0 100 100 ].
* This respects CRS rotation.
*
* This is non-destructive, and clones the input.
*
* @param {DataMaps.PointTupleRepr} point Array with two number elements: X and Y coordinates.
* @return {LeafletModule.PointTuple} New point in the universal space.
*/
fromPoint( point ) {
const
y = point[ 0 ] * this.scaleY,
x = point[ 1 ] * this.scaleX;
return [ x * this.rSin + y * this.rCos, x * this.rCos - y * this.rSin ];
}


/**
* Maps a box from map's coordinate reference system specified by the server, to the universal space [ 0 0 100 100 ].
* This does not respect CRS rotation. Consumers must handle it on their own.
*
* This is non-destructive, and clones the input.
*
* @param {LeafletModule.LatLngBoundsTuple} box
* @return {LeafletModule.LatLngBoundsTuple} New box in the universal space.
*/
fromBox( box ) {
const
sY = box[ 0 ][ 0 ] * this.scaleY,
sX = box[ 0 ][ 1 ] * this.scaleX,
eY = box[ 1 ][ 0 ] * this.scaleY,
eX = box[ 1 ][ 1 ] * this.scaleX;
return [
[ sY, sX ],
[ eY, eX ]
];
}


/**
* @param {LeafletModule.LatLng} latlng
* @param {boolean} [round=false]
* @return {DataMaps.PointTupleRepr}
*/
fromLeaflet( latlng, round ) {
let lat = latlng.lat / this.scaleY,
lon = latlng.lng / this.scaleX;

if ( this.rotation ) {
[ lat, lon ] = [
lon * this.rSinInv + lat * this.rCosInv,
lon * this.rCosInv - lat * this.rSinInv
];
}

if ( round ) {
lat = Math.round( lat * 10e3 ) / 10e3;
lon = Math.round( lon * 10e3 ) / 10e3;
}

return [ lat, lon ];
}
};

0 comments on commit 56351d0

Please sign in to comment.