commit 7bb1b9666aa636783544cd44b0dd50afb0c773a5
parent 966026b3e7691b70802f3b2b3654c985f0a0e347
Author: Daniel Barlow <dan@telent.net>
Date: Sat, 23 Nov 2024 13:03:12 +0000
introduce TileMap type
Diffstat:
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git 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
@@ -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