diff --git a/svgmap/src/components/map/Map.tsx b/svgmap/src/components/map/Map.tsx index d078b67..15dd38e 100644 --- a/svgmap/src/components/map/Map.tsx +++ b/svgmap/src/components/map/Map.tsx @@ -22,7 +22,7 @@ const Map: react.FC = (props: MapProperties) => { Math.ceil((Math.max(props.width, props.height) * 2) / 256) + 2; const boardSize = nbTiles * 256; - const [shift, setShift] = useState({ x: 0, y: 0 }); + const [shift, setShift] = useState({ x: -boardSize / 2, y: -boardSize / 2 }); const [zoom, setZoom] = useState(1); const addShift = (deltaShift: { x: number; y: number }) => { @@ -52,17 +52,17 @@ const Map: react.FC = (props: MapProperties) => { useEffect(() => { const firstVisibleTiles = { - x: Math.max(Math.floor(-shift.x / 256), 0), - y: Math.max(Math.floor(-shift.y / 256), 0), + x: Math.max(Math.floor(-shift.x / 256 / zoom), 0), + y: Math.max(Math.floor(-shift.y / 256 / zoom), 0), }; const lastVisibleTiles = { x: Math.min( - Math.ceil(firstVisibleTiles.x + props.width / 256), + Math.ceil(firstVisibleTiles.x + props.width / 256 / zoom), nbTiles - 1 ), y: Math.min( - Math.ceil(firstVisibleTiles.y + props.height / 256), + Math.ceil(firstVisibleTiles.y + props.height / 256 / zoom), nbTiles - 1 ), }; @@ -83,6 +83,7 @@ const Map: react.FC = (props: MapProperties) => { col >= firstVisibleTiles.x && col <= lastVisibleTiles.x ) { + console.log(`Adding tile ${row}/${col}`); tileRow.push( = (props: TileProperties) => { - console.log(`Rendering `); +// console.log(`Rendering `); const g = useRef(null); const timeout = (ms: number) => {