rename FineZoomLevel to ZoomLevel and ZoomLevel to TileZoomlevel

"bounded contexts": use the shorter name for the souplesse concept
and the longer name (only in MapTile) for OSM zoom levels
This commit is contained in:
Daniel Barlow 2024-11-24 21:07:01 +00:00
parent 02a30a7a10
commit 8f9e89ffcd
3 changed files with 20 additions and 21 deletions

View File

@ -24,7 +24,7 @@ import Svg.Attributes as S exposing
, fill , fill
, stroke, strokeWidth, strokeOpacity) , stroke, strokeWidth, strokeOpacity)
import Time import Time
import TileMap exposing (..) -- (tiles, FineZoomLevel, toZoomCoord, toCoord) import TileMap exposing (..)
import Url.Parser exposing (Parser, (<?>), int, map, s, string) import Url.Parser exposing (Parser, (<?>), int, map, s, string)
import Url.Parser.Query as Query import Url.Parser.Query as Query
import Url exposing (Url) import Url exposing (Url)
@ -80,7 +80,7 @@ init _ url navKey =
in in
((Model ((Model
(toCoord (Pos 0 0 Nothing)) (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)) (fetchTrack start duration))
-- SUBSCRIPTIONS -- SUBSCRIPTIONS
@ -187,7 +187,7 @@ updateModel msg model =
{ model { model
| track = Present trk | track = Present trk
, centre = toCoord (Point.centre trk) , centre = toCoord (Point.centre trk)
, zoom = FineZoomLevel (13 * 8) , zoom = ZoomLevel (13 * 8)
, startTime = start , startTime = start
, duration = duration , duration = duration
, markedTime = (start + 300, duration - 900) , markedTime = (start + 300, duration - 900)
@ -454,7 +454,7 @@ powerView = measureView "power" "#994444" (.power >> Maybe.map toFloat)
eleView = measureView "elevation" "#4444ee" (.pos >> .ele) 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 = trackView leftedge topedge zoom points =
let plot p = let plot p =
let (x, y) = pixelFromCoord (toCoord p.pos) zoom let (x, y) = pixelFromCoord (toCoord p.pos) zoom
@ -499,7 +499,7 @@ ifTrack model content =
Loading -> div [] [Html.text "loading"] Loading -> div [] [Html.text "loading"]
Empty -> div [] [Html.text "no points"] 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 = canvas centre zoom width height model =
let tm = TileMap centre zoom width height let tm = TileMap centre zoom width height
mapBounds = TileMap.bounds tm mapBounds = TileMap.bounds tm

View File

@ -5,7 +5,7 @@ module Model exposing
, Drag(..) , Drag(..)
, DragTarget(..) , DragTarget(..)
) )
import TileMap exposing (FineZoomLevel, Coord) import TileMap exposing (ZoomLevel, Coord)
import Point exposing (Point) import Point exposing (Point)
type DragTarget = Map | Graph | StartMark | EndMark | NoTarget type DragTarget = Map | Graph | StartMark | EndMark | NoTarget
@ -18,7 +18,7 @@ type TrackState = Empty | Loading | Failure String | Present (List Point)
type alias Model = type alias Model =
{ centre: Coord { centre: Coord
, zoom: FineZoomLevel , zoom: ZoomLevel
, drag: Drag , drag: Drag
, startTime : Float , startTime : Float
, duration : Float , duration : Float

View File

@ -1,6 +1,5 @@
module TileMap exposing (tiles module TileMap exposing (tiles
, FineZoomLevel(..) , ZoomLevel(..)
, ZoomLevel
, Coord , Coord
, TileMap(..) , TileMap(..)
, toCoord , toCoord
@ -24,21 +23,21 @@ type alias TileNumber = { x: Int, y: Int }
type alias Coord = { x: Float, y: Float } type alias Coord = { x: Float, y: Float }
-- zoom level -- zoom level
type alias ZoomLevel = Int type alias TileZoomLevel = Int
type FineZoomLevel = FineZoomLevel Int type ZoomLevel = ZoomLevel Int
type TileMap = TileMap Coord FineZoomLevel Int Int type TileMap = TileMap Coord ZoomLevel Int Int
zoomStep = 8 zoomStep = 8
toZoom : FineZoomLevel -> ZoomLevel toZoom : ZoomLevel -> TileZoomLevel
toZoom (FineZoomLevel f) = f // zoomStep toZoom (ZoomLevel f) = f // zoomStep
incZoom : FineZoomLevel -> Int -> FineZoomLevel incZoom : ZoomLevel -> Int -> ZoomLevel
incZoom (FineZoomLevel z) delta = incZoom (ZoomLevel z) delta =
FineZoomLevel (clamp 0 (20 * zoomStep) (z + delta)) ZoomLevel (clamp 0 (20 * zoomStep) (z + delta))
-- project lat/long to co-ordinates based on pseudocode at -- project lat/long to co-ordinates based on pseudocode at
@ -68,15 +67,15 @@ reflect c = Coord -c.x -c.y
translate base offset = translate base offset =
{ x = (base.x + offset.x), y = (base.y + offset.y) } { 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) = translatePixels old z_ (x, y) =
translate old (pixelsToCoord z_ (x, y)) translate old (pixelsToCoord z_ (x, y))
tileCovering : Coord -> ZoomLevel -> TileNumber tileCovering : Coord -> TileZoomLevel -> TileNumber
tileCovering c z = tileCovering c z =
TileNumber (truncate (toFloat (2 ^ z) * c.x)) (truncate (toFloat (2 ^ z) * c.y)) 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_ = pixelFromCoord c z_ =
let z = toZoom z_ let z = toZoom z_
{x,y} = tileCovering c (z + 8) {x,y} = tileCovering c (z + 8)
@ -104,7 +103,7 @@ bounds tmap =
} }
tileUrl : TileNumber -> ZoomLevel -> String tileUrl : TileNumber -> TileZoomLevel -> String
tileUrl {x,y} z = tileUrl {x,y} z =
String.concat ["https://a.tile.openstreetmap.org", String.concat ["https://a.tile.openstreetmap.org",
"/", String.fromInt z, "/", String.fromInt z,