Still implementing mouse handlers.

This commit is contained in:
Eric van der Vlist 2022-09-06 23:46:08 +02:00
parent ec48c63667
commit 2b1066fd5b
1 changed files with 18 additions and 0 deletions

View File

@ -27,6 +27,15 @@ const lat2tile = (lat: number, zoom: number) => {
return [floor, real - floor]; return [floor, real - floor];
}; };
function tile2long(x: number, z: number) {
return (x / Math.pow(2, z)) * 360 - 180;
}
function tile2lat(y: number, z: number) {
var n = Math.PI - (2 * Math.PI * y) / Math.pow(2, z);
return (180 / Math.PI) * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
}
const Map: react.FC = () => { const Map: react.FC = () => {
console.log('Log - Rendering <Map />'); console.log('Log - Rendering <Map />');
@ -93,6 +102,15 @@ const Map: react.FC = () => {
const mouseUpHandler = (event: any) => { const mouseUpHandler = (event: any) => {
event.preventDefault(); event.preventDefault();
console.log('Log - Up, now do something ! '); console.log('Log - Up, now do something ! ');
const newCenterY =
tileCenterY +
reminderY +
(deltaX + mouseState.current.starting.x - event.pageX);
const newCenterX =
tileCenterX +
reminderX +
(deltaY + mouseState.current.starting.y - event.pageY);
setCenter([tile2lat(newCenterY, zoom), tile2long(newCenterX, zoom)]);
mouseState.current = initialMouseState; mouseState.current = initialMouseState;
genericHandler(event); genericHandler(event);
}; };