prefer FineZoomLevel to ZoomLevel almost everywhere
we only use the coarse zoom internally in TileMap
This commit is contained in:
parent
33d59e1696
commit
02a30a7a10
@ -124,7 +124,7 @@ handleDragFinish model target (x, y) =
|
|||||||
case target of
|
case target of
|
||||||
Map ->
|
Map ->
|
||||||
{ model |
|
{ model |
|
||||||
centre = translatePixels model.centre (toZoom model.zoom) (x, y)
|
centre = translatePixels model.centre model.zoom (x, y)
|
||||||
}
|
}
|
||||||
Graph ->
|
Graph ->
|
||||||
{ model |
|
{ model |
|
||||||
@ -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 -> ZoomLevel -> List Point -> Svg Msg
|
trackView : Int -> Int -> FineZoomLevel -> 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 -> ZoomLevel -> Int -> Int -> Model -> Html Msg
|
canvas : Coord -> FineZoomLevel -> 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
|
||||||
@ -539,8 +539,8 @@ timeWheelDecoder =
|
|||||||
|
|
||||||
viewDiv : Model -> Html Msg
|
viewDiv : Model -> Html Msg
|
||||||
viewDiv model =
|
viewDiv model =
|
||||||
let coord = translate model.centre (pixelsToCoord (toZoom model.zoom) (dragDelta Map model.drag))
|
let coord = translate model.centre (pixelsToCoord model.zoom (dragDelta Map model.drag))
|
||||||
canvasV = canvas coord (toZoom model.zoom) portalWidth portalHeight model
|
canvasV = canvas coord model.zoom portalWidth portalHeight model
|
||||||
epos e = Tuple.mapBoth floor floor e.pointer.clientPos
|
epos e = Tuple.mapBoth floor floor e.pointer.clientPos
|
||||||
in div [ style "display" "flex"
|
in div [ style "display" "flex"
|
||||||
, style "column-gap" "15px"
|
, style "column-gap" "15px"
|
||||||
@ -554,7 +554,6 @@ viewDiv model =
|
|||||||
, style "position" "relative"
|
, style "position" "relative"
|
||||||
, style "overflow" "hidden"]
|
, style "overflow" "hidden"]
|
||||||
[canvasV]
|
[canvasV]
|
||||||
, text ("Zoom level " ++ (String.fromInt (toZoom model.zoom)))
|
|
||||||
, span []
|
, span []
|
||||||
[ button [ onClick (MapScale -zoomStep) ] [ text "-" ]
|
[ button [ onClick (MapScale -zoomStep) ] [ text "-" ]
|
||||||
, button [ onClick (MapScale zoomStep) ] [ text "+" ]
|
, button [ onClick (MapScale zoomStep) ] [ text "+" ]
|
||||||
|
@ -28,7 +28,7 @@ type alias ZoomLevel = Int
|
|||||||
type FineZoomLevel = FineZoomLevel Int
|
type FineZoomLevel = FineZoomLevel Int
|
||||||
|
|
||||||
|
|
||||||
type TileMap = TileMap Coord ZoomLevel Int Int
|
type TileMap = TileMap Coord FineZoomLevel Int Int
|
||||||
|
|
||||||
zoomStep = 8
|
zoomStep = 8
|
||||||
|
|
||||||
@ -55,9 +55,10 @@ toCoord pos =
|
|||||||
in
|
in
|
||||||
Coord x y
|
Coord x y
|
||||||
|
|
||||||
pixelsToCoord z (x,y) =
|
pixelsToCoord z_ (x,y) =
|
||||||
let x_float = toFloat x / toFloat ( 2 ^ (z + 8))
|
let scale = 8 + toZoom z_
|
||||||
y_float = toFloat y / toFloat ( 2 ^ (z + 8))
|
x_float = toFloat x / toFloat ( 2 ^ scale)
|
||||||
|
y_float = toFloat y / toFloat ( 2 ^ scale)
|
||||||
in Coord x_float y_float
|
in Coord x_float y_float
|
||||||
|
|
||||||
reflect : Coord -> Coord
|
reflect : Coord -> Coord
|
||||||
@ -67,23 +68,26 @@ 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 -> ZoomLevel -> (Int, Int) -> Coord
|
translatePixels : Coord -> FineZoomLevel -> (Int, Int) -> Coord
|
||||||
translatePixels old z (x, y) = translate old (pixelsToCoord z (x, y))
|
translatePixels old z_ (x, y) =
|
||||||
|
translate old (pixelsToCoord z_ (x, y))
|
||||||
|
|
||||||
tileCovering : Coord -> ZoomLevel -> TileNumber
|
tileCovering : Coord -> ZoomLevel -> 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 -> ZoomLevel -> (Int, Int)
|
pixelFromCoord : Coord -> FineZoomLevel -> (Int, Int)
|
||||||
pixelFromCoord c z =
|
pixelFromCoord c z_ =
|
||||||
let {x,y} = tileCovering c (z + 8)
|
let z = toZoom z_
|
||||||
|
{x,y} = tileCovering c (z + 8)
|
||||||
in (x,y)
|
in (x,y)
|
||||||
|
|
||||||
boundingTiles : TileMap -> (TileNumber, TileNumber)
|
boundingTiles : TileMap -> (TileNumber, TileNumber)
|
||||||
boundingTiles (TileMap centre z width height) =
|
boundingTiles (TileMap centre z1 width height) =
|
||||||
-- find the tiles needed to cover the area (`width` x `height`)
|
-- find the tiles needed to cover the area (`width` x `height`)
|
||||||
-- about the point at `centre`
|
-- about the point at `centre`
|
||||||
let delta = pixelsToCoord z ((width // 2), (height // 2))
|
let z = toZoom z1
|
||||||
|
delta = pixelsToCoord z1 ((width // 2), (height // 2))
|
||||||
minCoord = translate centre (reflect delta)
|
minCoord = translate centre (reflect delta)
|
||||||
maxCoord = translate centre delta
|
maxCoord = translate centre delta
|
||||||
in ((tileCovering minCoord z),
|
in ((tileCovering minCoord z),
|
||||||
@ -117,8 +121,9 @@ tiles tmap =
|
|||||||
(mintile, maxtile) = boundingTiles tmap
|
(mintile, maxtile) = boundingTiles tmap
|
||||||
xs = List.range mintile.x maxtile.x
|
xs = List.range mintile.x maxtile.x
|
||||||
ys = List.range mintile.y maxtile.y
|
ys = List.range mintile.y maxtile.y
|
||||||
|
zoom_ = toZoom zoom
|
||||||
in
|
in
|
||||||
List.map
|
List.map
|
||||||
(\ y -> div []
|
(\ y -> div []
|
||||||
(List.map (\ x -> tileImg zoom (TileNumber x y)) xs))
|
(List.map (\ x -> tileImg zoom_ (TileNumber x y)) xs))
|
||||||
ys
|
ys
|
||||||
|
Loading…
Reference in New Issue
Block a user