commit d8180febe79b8b0a4f36e77a484a426f22a451d8
parent 7bb1b9666aa636783544cd44b0dd50afb0c773a5
Author: Daniel Barlow <dan@telent.net>
Date: Sat, 23 Nov 2024 13:47:56 +0000
expose pixel bounds from TileMap not boundingTiles
Diffstat:
2 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/frontend/src/Main.elm b/frontend/src/Main.elm
@@ -469,7 +469,6 @@ powerView = measureView "power" "#994444" (.power >> Maybe.map toFloat)
eleView = measureView "elevation" "#4444ee" (.pos >> .ele)
-
trackView : Int -> Int -> ZoomLevel -> List Point -> Svg Msg
trackView leftedge topedge zoom points =
let plot p =
@@ -518,21 +517,15 @@ ifTrack model content =
canvas : Coord -> ZoomLevel -> Int -> Int -> Model -> Html Msg
canvas centre zoom width height model =
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
- leftedge = mintile.x * 256
- topedge = mintile.y * 256
- offsetX = pixelCentreX - (width // 2) - leftedge
- offsetY = pixelCentreY - (height // 2) - topedge
- pixWidth = (1 + maxtile.x - mintile.x) * 256
- pixHeight = (1 + maxtile.y - mintile.y) * 256
+ mapBounds = TileMap.bounds tm
+ (pixelCentreX, pixelCentreY) = pixelFromCoord centre zoom
+ offsetX = pixelCentreX - (width // 2) - mapBounds.left
+ offsetY = pixelCentreY - (height // 2) - mapBounds.top
epos e = Tuple.mapBoth floor floor e.pointer.clientPos
- tv = ifTrack model (trackView leftedge topedge zoom)
+ tv = ifTrack model (trackView mapBounds.left mapBounds.top zoom)
in div [style "position" "absolute"
- ,style "width" (px pixWidth)
- ,style "height" (px pixHeight)
+ ,style "width" (px mapBounds.width)
+ ,style "height" (px mapBounds.height)
,style "left" (px -offsetX)
,style "top" (px -offsetY)
,style "lineHeight" (px 0)
diff --git a/frontend/src/TileMap.elm b/frontend/src/TileMap.elm
@@ -8,7 +8,7 @@ module TileMap exposing (tiles
, translate
, translatePixels
, incZoom
- , boundingTiles
+ , bounds
, pixelsToCoord
, pixelFromCoord
, zoomStep)
@@ -89,6 +89,17 @@ boundingTiles (TileMap centre z width height) =
in ((tileCovering minCoord z),
(translate (tileCovering maxCoord z) (TileNumber 1 1)))
+bounds : TileMap -> { left : Int, top : Int, width: Int, height: Int }
+bounds tmap =
+ let (mintile, maxtile) = boundingTiles tmap
+ in {
+ left = mintile.x * 256,
+ top = mintile.y * 256,
+ width = (1 + maxtile.x - mintile.x) * 256,
+ height = (1 + maxtile.y - mintile.y) * 256
+ }
+
+
tileUrl : TileNumber -> ZoomLevel -> String
tileUrl {x,y} z =
String.concat ["https://a.tile.openstreetmap.org",