From 7bb1b9666aa636783544cd44b0dd50afb0c773a5 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sat, 23 Nov 2024 13:03:12 +0000 Subject: [PATCH] introduce TileMap type --- frontend/src/Main.elm | 7 ++++--- frontend/src/TileMap.elm | 13 +++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/frontend/src/Main.elm b/frontend/src/Main.elm index fc802b5..d9a0b1f 100644 --- a/frontend/src/Main.elm +++ b/frontend/src/Main.elm @@ -515,9 +515,10 @@ ifTrack model content = Loading -> div [] [Html.text "loading"] Empty -> div [] [Html.text "no points"] - +canvas : Coord -> ZoomLevel -> Int -> Int -> Model -> Html Msg canvas centre zoom width height model = - let (mintile, maxtile) = boundingTiles centre zoom width height + let tm = TileMap centre zoom width height + (mintile, maxtile) = boundingTiles tm -- offset is pixel difference between centre (which *should* -- be the middle of the image) and actual middle of the canvas (pixelCentreX,pixelCentreY) = pixelFromCoord centre zoom @@ -538,7 +539,7 @@ canvas centre zoom width height model = ,Pointer.onUp (\e -> DragFinish (epos e)) ,Pointer.onMove (\e -> Drag (epos e)) ,Pointer.onDown (\e -> DragStart Map (epos e)) ] - (tv :: tiles centre zoom width height) + (tv :: tiles tm) portalWidth = 600 diff --git a/frontend/src/TileMap.elm b/frontend/src/TileMap.elm index 59811f1..3c093d9 100644 --- a/frontend/src/TileMap.elm +++ b/frontend/src/TileMap.elm @@ -2,6 +2,7 @@ module TileMap exposing (tiles , FineZoomLevel(..) , ZoomLevel , Coord + , TileMap(..) , toCoord , toZoom , translate @@ -26,6 +27,9 @@ type alias Coord = { x: Float, y: Float } type alias ZoomLevel = Int type FineZoomLevel = FineZoomLevel Int + +type TileMap = TileMap Coord ZoomLevel Int Int + zoomStep = 8 toZoom : FineZoomLevel -> ZoomLevel @@ -75,8 +79,8 @@ pixelFromCoord c z = let {x,y} = tileCovering c (z + 8) in (x,y) -boundingTiles : Coord -> ZoomLevel -> Int -> Int -> (TileNumber, TileNumber) -boundingTiles centre z width height = +boundingTiles : TileMap -> (TileNumber, TileNumber) +boundingTiles (TileMap centre z width height) = -- find the tiles needed to cover the area (`width` x `height`) -- about the point at `centre` let delta = pixelsToCoord z ((width // 2), (height // 2)) @@ -97,8 +101,9 @@ tileImg zoom tilenumber = img [ width 256, height 256, src (tileUrl tilenumber zoom) ] [] -tiles centre zoom width height = - let (mintile, maxtile) = boundingTiles centre zoom width height +tiles tmap = + let (TileMap centre zoom width height) = tmap + (mintile, maxtile) = boundingTiles tmap xs = List.range mintile.x maxtile.x ys = List.range mintile.y maxtile.y in