-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: refactor resizable to behaviour closer to common drawing tool UX patterns * fix: completely refactor resizable flag for select mode
- Loading branch information
1 parent
0a88c2b
commit 9573164
Showing
10 changed files
with
527 additions
and
358 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { lngLatToWebMercatorXY, webMercatorXYToLngLat } from "./web-mercator"; | ||
|
||
describe("web mercator", () => { | ||
describe("lngLatToWebMercatorXY", () => { | ||
it("returns x,y of 0,0 web mercator coordinates from lng,lat of 0,0", () => { | ||
const result = lngLatToWebMercatorXY(0, 0); | ||
expect(result).toStrictEqual({ x: 0, y: 0 }); | ||
}); | ||
|
||
it("returns correct x,y web mercator coordinates for lng, lat", () => { | ||
const result = lngLatToWebMercatorXY(179, 89); | ||
expect(result).toStrictEqual({ | ||
x: 19926188.85199597, | ||
y: 30240971.958386205, | ||
}); | ||
}); | ||
|
||
it("returns correct x,y web mercator coordinates for lng, lat", () => { | ||
const result = lngLatToWebMercatorXY(-179, -89); | ||
expect(result).toStrictEqual({ | ||
x: -19926188.85199597, | ||
y: -30240971.95838617, | ||
}); | ||
}); | ||
}); | ||
|
||
describe("webMercatorXYToLngLat", () => { | ||
it("returns x,y of 0,0 web mercator coordinates from lng,lat of 0,0", () => { | ||
const result = webMercatorXYToLngLat(0, 0); | ||
expect(result).toStrictEqual({ lng: 0, lat: 0 }); | ||
}); | ||
|
||
it("returns correct x,y web mercator coordinates for lng, lat", () => { | ||
const result = webMercatorXYToLngLat( | ||
19926188.85199597, | ||
30240971.958386205, | ||
); | ||
expect(result).toStrictEqual({ lng: 179, lat: 89.00000000000001 }); // TODO: should we limit precision? | ||
}); | ||
|
||
it("returns correct x,y web mercator coordinates for lng, lat", () => { | ||
const result = webMercatorXYToLngLat( | ||
-19926188.85199597, | ||
-30240971.95838617, | ||
); | ||
expect(result).toStrictEqual({ lng: -179, lat: -89 }); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const RADIANS_TO_DEGREES = 57.29577951308232 as const; // 180 / Math.PI | ||
const DEGREES_TO_RADIANS = 0.017453292519943295 as const; // Math.PI / 180 | ||
const R = 6378137 as const; | ||
|
||
/** | ||
* Convert longitude and latitude to web mercator x and y | ||
* @param lng | ||
* @param lat | ||
* @returns - web mercator x and y | ||
*/ | ||
export const lngLatToWebMercatorXY = ( | ||
lng: number, | ||
lat: number, | ||
): { x: number; y: number } => ({ | ||
x: lng === 0 ? 0 : lng * DEGREES_TO_RADIANS * R, | ||
y: | ||
lat === 0 | ||
? 0 | ||
: Math.log(Math.tan(Math.PI / 4 + (lat * DEGREES_TO_RADIANS) / 2)) * R, | ||
}); | ||
|
||
/** | ||
* Convert web mercator x and y to longitude and latitude | ||
* @param x - web mercator x | ||
* @param y - web mercator y | ||
* @returns - longitude and latitude | ||
*/ | ||
export const webMercatorXYToLngLat = ( | ||
x: number, | ||
y: number, | ||
): { lng: number; lat: number } => ({ | ||
lng: x === 0 ? 0 : RADIANS_TO_DEGREES * (x / R), | ||
lat: | ||
y === 0 | ||
? 0 | ||
: (2 * Math.atan(Math.exp(y / R)) - Math.PI / 2) * RADIANS_TO_DEGREES, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.