diff --git a/frontend/src/Main.elm b/frontend/src/Main.elm index c04328d..7a548c8 100644 --- a/frontend/src/Main.elm +++ b/frontend/src/Main.elm @@ -24,7 +24,7 @@ import Svg.Attributes as S exposing , fill , stroke, strokeWidth, strokeOpacity) import Time -import TileMap exposing (..) -- (tiles, FineZoomLevel, toZoomCoord, toCoord) +import TileMap exposing (..) import Url.Parser exposing (Parser, (), int, map, s, string) import Url.Parser.Query as Query import Url exposing (Url) @@ -80,7 +80,7 @@ init _ url navKey = in ((Model (toCoord (Pos 0 0 Nothing)) - (FineZoomLevel (1*8)) None 0 0 (0,0) Loading), + (ZoomLevel (1*8)) None 0 0 (0,0) Loading), (fetchTrack start duration)) -- SUBSCRIPTIONS @@ -187,7 +187,7 @@ updateModel msg model = { model | track = Present trk , centre = toCoord (Point.centre trk) - , zoom = FineZoomLevel (13 * 8) + , zoom = ZoomLevel (13 * 8) , startTime = start , duration = duration , markedTime = (start + 300, duration - 900) @@ -454,7 +454,7 @@ powerView = measureView "power" "#994444" (.power >> Maybe.map toFloat) eleView = measureView "elevation" "#4444ee" (.pos >> .ele) -trackView : Int -> Int -> FineZoomLevel -> List Point -> Svg Msg +trackView : Int -> Int -> ZoomLevel -> List Point -> Svg Msg trackView leftedge topedge zoom points = let plot p = let (x, y) = pixelFromCoord (toCoord p.pos) zoom @@ -499,7 +499,7 @@ ifTrack model content = Loading -> div [] [Html.text "loading"] Empty -> div [] [Html.text "no points"] -canvas : Coord -> FineZoomLevel -> Int -> Int -> Model -> Html Msg +canvas : Coord -> ZoomLevel -> Int -> Int -> Model -> Html Msg canvas centre zoom width height model = let tm = TileMap centre zoom width height mapBounds = TileMap.bounds tm diff --git a/frontend/src/Model.elm b/frontend/src/Model.elm index 3231fd7..9a6fe24 100644 --- a/frontend/src/Model.elm +++ b/frontend/src/Model.elm @@ -5,7 +5,7 @@ module Model exposing , Drag(..) , DragTarget(..) ) -import TileMap exposing (FineZoomLevel, Coord) +import TileMap exposing (ZoomLevel, Coord) import Point exposing (Point) type DragTarget = Map | Graph | StartMark | EndMark | NoTarget @@ -18,7 +18,7 @@ type TrackState = Empty | Loading | Failure String | Present (List Point) type alias Model = { centre: Coord - , zoom: FineZoomLevel + , zoom: ZoomLevel , drag: Drag , startTime : Float , duration : Float diff --git a/frontend/src/TileMap.elm b/frontend/src/TileMap.elm index 87605b1..2ed9d8f 100644 --- a/frontend/src/TileMap.elm +++ b/frontend/src/TileMap.elm @@ -1,6 +1,5 @@ module TileMap exposing (tiles - , FineZoomLevel(..) - , ZoomLevel + , ZoomLevel(..) , Coord , TileMap(..) , toCoord @@ -24,21 +23,21 @@ type alias TileNumber = { x: Int, y: Int } type alias Coord = { x: Float, y: Float } -- zoom level -type alias ZoomLevel = Int -type FineZoomLevel = FineZoomLevel Int +type alias TileZoomLevel = Int +type ZoomLevel = ZoomLevel Int -type TileMap = TileMap Coord FineZoomLevel Int Int +type TileMap = TileMap Coord ZoomLevel Int Int zoomStep = 8 -toZoom : FineZoomLevel -> ZoomLevel -toZoom (FineZoomLevel f) = f // zoomStep +toZoom : ZoomLevel -> TileZoomLevel +toZoom (ZoomLevel f) = f // zoomStep -incZoom : FineZoomLevel -> Int -> FineZoomLevel -incZoom (FineZoomLevel z) delta = - FineZoomLevel (clamp 0 (20 * zoomStep) (z + delta)) +incZoom : ZoomLevel -> Int -> ZoomLevel +incZoom (ZoomLevel z) delta = + ZoomLevel (clamp 0 (20 * zoomStep) (z + delta)) -- project lat/long to co-ordinates based on pseudocode at @@ -68,15 +67,15 @@ reflect c = Coord -c.x -c.y translate base offset = { x = (base.x + offset.x), y = (base.y + offset.y) } -translatePixels : Coord -> FineZoomLevel -> (Int, Int) -> Coord +translatePixels : Coord -> ZoomLevel -> (Int, Int) -> Coord translatePixels old z_ (x, y) = translate old (pixelsToCoord z_ (x, y)) -tileCovering : Coord -> ZoomLevel -> TileNumber +tileCovering : Coord -> TileZoomLevel -> TileNumber tileCovering c z = TileNumber (truncate (toFloat (2 ^ z) * c.x)) (truncate (toFloat (2 ^ z) * c.y)) -pixelFromCoord : Coord -> FineZoomLevel -> (Int, Int) +pixelFromCoord : Coord -> ZoomLevel -> (Int, Int) pixelFromCoord c z_ = let z = toZoom z_ {x,y} = tileCovering c (z + 8) @@ -104,7 +103,7 @@ bounds tmap = } -tileUrl : TileNumber -> ZoomLevel -> String +tileUrl : TileNumber -> TileZoomLevel -> String tileUrl {x,y} z = String.concat ["https://a.tile.openstreetmap.org", "/", String.fromInt z,