diff --git a/src/components/map/Handler.css b/src/components/map/Handler.css new file mode 100644 index 0000000..f72bca6 --- /dev/null +++ b/src/components/map/Handler.css @@ -0,0 +1,5 @@ +.handler { + position: fixed; + height: 100%; + width: 100%; +} diff --git a/src/components/map/Handlers.tsx b/src/components/map/Handlers.tsx index 03f03d2..f438a09 100644 --- a/src/components/map/Handlers.tsx +++ b/src/components/map/Handlers.tsx @@ -2,6 +2,7 @@ import react, { useState } from 'react'; import { throttle } from 'lodash'; import { Point } from './types'; import { handlersConfig } from './config'; +import './Handler.css'; export interface HandlersProperties { /**Transform the map: @@ -17,7 +18,11 @@ export interface HandlersProperties { /** * * @param props - * @returns A div with handlers + * @returns A div with the following handlers + * * mouseLeave, mouseDown and mouseUp to track the mouse state + * * mouseMove to shift the map if the mouse is down + * + * TODO: Check that using clientX instead of pageX (to pass unit tests) works. */ export const Handlers: react.FC = ( props: HandlersProperties diff --git a/src/components/map/Map.tsx b/src/components/map/Map.tsx index d05bf2d..a203292 100644 --- a/src/components/map/Map.tsx +++ b/src/components/map/Map.tsx @@ -1,7 +1,8 @@ -import react from 'react'; +import react, { useState } from 'react'; +import Handlers from './Handlers'; import Tile from './Tile'; import TiledLayer from './TiledLayer'; -import { TileFactory } from './types'; +import { Point, TileFactory } from './types'; export interface MapProperties {} @@ -10,22 +11,63 @@ export interface MapProperties {} * @returns A Map component */ export const Map: react.FC = (props: MapProperties) => { + const [coordinateSystem, setCoordinateSystem] = useState({ + zoom: 1, + shift: { x: 0, y: 0 }, + }); + const simpleTileFactory: TileFactory = (keyObject) => ( ); + const transformMap = ( + deltaShift: Point | null, + deltaZoom: number | null, + zoomCenter: Point | null + ) => { + const actualDeltaShift = deltaShift === null ? { x: 0, y: 0 } : deltaShift; + const actualDeltaZoom = deltaZoom === null ? 1 : deltaZoom; + const actualZoomCenter = zoomCenter === null ? { x: 0, y: 0 } : zoomCenter; + var newCoordinateSystem = { + shift: { + x: + coordinateSystem.shift.x + + actualDeltaShift.x + + (coordinateSystem.shift.x - actualZoomCenter.x) * + (actualDeltaZoom - 1), + y: + coordinateSystem.shift.y + + actualDeltaShift.y + + (coordinateSystem.shift.y - actualZoomCenter.y) * + (actualDeltaZoom - 1), + }, + zoom: coordinateSystem.zoom * actualDeltaZoom, + }; + setCoordinateSystem(newCoordinateSystem); + }; + return ( - - - - - + <> + + + + + + + + + ); }; diff --git a/src/components/map/TiledLayer.test.tsx b/src/components/map/TiledLayer.test.tsx index e5c58ef..e6f7227 100644 --- a/src/components/map/TiledLayer.test.tsx +++ b/src/components/map/TiledLayer.test.tsx @@ -26,21 +26,21 @@ describe('The TiledLayer component ', () => { transform="translate(1, 2)" > - {"provider":"osm","zoomLevel":10,"x":6,"y":7} + {"provider":"osm","zoomLevel":10,"x":6,"y":10} - {"provider":"osm","zoomLevel":10,"x":7,"y":7} + {"provider":"osm","zoomLevel":10,"x":7,"y":10} - {"provider":"osm","zoomLevel":10,"x":8,"y":7} + {"provider":"osm","zoomLevel":10,"x":8,"y":10} @@ -77,42 +77,42 @@ describe('The TiledLayer component ', () => { transform="translate(1, 2)" > - {"provider":"osm","zoomLevel":10,"x":6,"y":7} + {"provider":"osm","zoomLevel":10,"x":6,"y":10} - {"provider":"osm","zoomLevel":10,"x":7,"y":7} + {"provider":"osm","zoomLevel":10,"x":7,"y":10} - {"provider":"osm","zoomLevel":10,"x":8,"y":7} + {"provider":"osm","zoomLevel":10,"x":8,"y":10} - {"provider":"osm","zoomLevel":10,"x":10,"y":5} + {"provider":"osm","zoomLevel":10,"x":10,"y":8} - {"provider":"osm","zoomLevel":10,"x":10,"y":6} + {"provider":"osm","zoomLevel":10,"x":10,"y":9} - {"provider":"osm","zoomLevel":10,"x":10,"y":7} + {"provider":"osm","zoomLevel":10,"x":10,"y":10} @@ -148,21 +148,21 @@ describe('The TiledLayer component ', () => { transform="translate(5, 0)" > - {"provider":"osm","zoomLevel":11,"x":10,"y":5} + {"provider":"osm","zoomLevel":11,"x":10,"y":8} - {"provider":"osm","zoomLevel":11,"x":10,"y":6} + {"provider":"osm","zoomLevel":11,"x":10,"y":9} - {"provider":"osm","zoomLevel":11,"x":10,"y":7} + {"provider":"osm","zoomLevel":11,"x":10,"y":10} @@ -189,56 +189,56 @@ describe('The TiledLayer component ', () => { transform="translate(-3, -1)" > - {"provider":"osm","zoomLevel":10,"x":2,"y":4} + {"provider":"osm","zoomLevel":10,"x":2,"y":7} - {"provider":"osm","zoomLevel":10,"x":3,"y":4} + {"provider":"osm","zoomLevel":10,"x":3,"y":7} - {"provider":"osm","zoomLevel":10,"x":2,"y":5} + {"provider":"osm","zoomLevel":10,"x":2,"y":8} - {"provider":"osm","zoomLevel":10,"x":3,"y":5} + {"provider":"osm","zoomLevel":10,"x":3,"y":8} - {"provider":"osm","zoomLevel":10,"x":2,"y":6} + {"provider":"osm","zoomLevel":10,"x":2,"y":9} - {"provider":"osm","zoomLevel":10,"x":3,"y":6} + {"provider":"osm","zoomLevel":10,"x":3,"y":9} - {"provider":"osm","zoomLevel":10,"x":2,"y":7} + {"provider":"osm","zoomLevel":10,"x":2,"y":10} - {"provider":"osm","zoomLevel":10,"x":3,"y":7} + {"provider":"osm","zoomLevel":10,"x":3,"y":10} diff --git a/src/components/map/TiledLayer.tsx b/src/components/map/TiledLayer.tsx index 8269c48..8f99bd3 100644 --- a/src/components/map/TiledLayer.tsx +++ b/src/components/map/TiledLayer.tsx @@ -46,7 +46,7 @@ export const TiledLayer: react.FC = ( provider: props.keyObject.provider, zoomLevel: props.keyObject.zoomLevel, x: props.keyObject.x + col, - y: props.keyObject.x + row, + y: props.keyObject.y + row, }; const key = tileUri(keyObject); if (!Object.hasOwn(tiles.current, key)) {