rename Zoom -> MapZoom to avoid confusion with timeline zoom

This commit is contained in:
Daniel Barlow 2024-11-14 09:59:08 +00:00
parent 46ee6dc1f5
commit 7d9273190e

View File

@ -4,7 +4,7 @@ import Browser
import Browser.Navigation as Nav
import Html exposing (Html, button, div, span, text, img, pre)
import Html.Attributes as H exposing (src, style, width, height)
import Html.Events exposing (onClick)
import Html.Events exposing (onClick, on)
import Html.Events.Extra.Pointer as Pointer
import Maybe exposing (Maybe)
import Json.Decode as D
@ -53,7 +53,7 @@ main =
type alias Coord = { x: Float, y: Float }
-- zoom level
type alias Zoom = Int
type alias MapZoom = Int
type alias TileNumber = { x: Int, y: Int }
@ -86,20 +86,20 @@ reflect c = Coord -c.x -c.y
translate base offset =
{ base | x = (base.x + offset.x), y = (base.y + offset.y) }
translatePixels : Coord -> Zoom -> (Int, Int) -> Coord
translatePixels : Coord -> MapZoom -> (Int, Int) -> Coord
translatePixels old z (x, y) = translate old (pixelsToCoord z (x, y))
tileCovering : Coord -> Zoom -> TileNumber
tileCovering : Coord -> MapZoom -> TileNumber
tileCovering c z =
TileNumber (truncate (toFloat (2 ^ z) * c.x)) (truncate (toFloat (2 ^ z) * c.y))
pixelFromCoord : Coord -> Zoom -> (Int, Int)
pixelFromCoord : Coord -> MapZoom -> (Int, Int)
pixelFromCoord c z =
let {x,y} = tileCovering c (z + 8)
in (x,y)
boundingTiles : Coord -> Zoom -> Int -> Int -> (TileNumber, TileNumber)
boundingTiles : Coord -> MapZoom -> Int -> Int -> (TileNumber, TileNumber)
boundingTiles centre z width height =
-- find the tiles needed to cover the area (`width` x `height`)
-- about the point at `centre`
@ -129,7 +129,7 @@ dragDelta d =
type TrackState = Empty | Loading | Failure String | Present (List Point)
type alias Model =
{ centre: Coord
, zoom: Zoom
, zoom: MapZoom
, drag: Drag
, startTime : Int
, duration : Int
@ -164,8 +164,8 @@ fetchTrack start duration = Http.get
-- UPDATE
type Msg
= ZoomIn
| ZoomOut
= MapZoomIn
| MapZoomOut
| Scroll Int Int
| PointerDown (Int, Int)
| PointerMove (Int, Int)
@ -181,10 +181,10 @@ update msg model = (newModel msg model, Cmd.none)
newModel msg model =
case msg of
ZoomIn ->
MapZoomIn ->
{ model | zoom = model.zoom + 1 }
ZoomOut ->
MapZoomOut ->
{ model | zoom = model.zoom - 1 }
Scroll x y ->
@ -210,7 +210,7 @@ newModel msg model =
-- VIEW
tileUrl : TileNumber -> Zoom -> String
tileUrl : TileNumber -> MapZoom -> String
tileUrl {x,y} z =
String.concat ["https://a.tile.openstreetmap.org",
"/", String.fromInt z,
@ -277,7 +277,7 @@ powerView = measureView "power" "#994444" (.power >> Maybe.map toFloat)
eleView = measureView "elevation" "#4444ee" (.pos >> .ele)
trackView : Int -> Int -> Zoom -> List Point -> Svg Msg
trackView : Int -> Int -> MapZoom -> List Point -> Svg Msg
trackView leftedge topedge zoom points =
let plot p =
let (x, y) = pixelFromCoord (toCoord p.pos.lat p.pos.lon) zoom
@ -366,8 +366,8 @@ viewDiv model =
[canvasV]
, text ("Zoom level " ++ (String.fromInt model.zoom))
, span []
[ button [ onClick ZoomOut ] [ text "-" ]
, button [ onClick ZoomIn ] [ text "+" ]
[ button [ onClick MapZoomOut ] [ text "-" ]
, button [ onClick MapZoomIn ] [ text "+" ]
, button [ onClick (Scroll 0 -10) ] [ text "^" ]
, button [ onClick (Scroll 0 10) ] [ text "V" ]
, button [ onClick (Scroll -10 0) ] [ text "<" ]