introduce TileMap type
This commit is contained in:
parent
966026b3e7
commit
7bb1b9666a
@ -515,9 +515,10 @@ ifTrack model content =
|
||||
Loading -> div [] [Html.text "loading"]
|
||||
Empty -> div [] [Html.text "no points"]
|
||||
|
||||
|
||||
canvas : Coord -> ZoomLevel -> Int -> Int -> Model -> Html Msg
|
||||
canvas centre zoom width height model =
|
||||
let (mintile, maxtile) = boundingTiles centre zoom width height
|
||||
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
|
||||
@ -538,7 +539,7 @@ canvas centre zoom width height model =
|
||||
,Pointer.onUp (\e -> DragFinish (epos e))
|
||||
,Pointer.onMove (\e -> Drag (epos e))
|
||||
,Pointer.onDown (\e -> DragStart Map (epos e)) ]
|
||||
(tv :: tiles centre zoom width height)
|
||||
(tv :: tiles tm)
|
||||
|
||||
|
||||
portalWidth = 600
|
||||
|
@ -2,6 +2,7 @@ module TileMap exposing (tiles
|
||||
, FineZoomLevel(..)
|
||||
, ZoomLevel
|
||||
, Coord
|
||||
, TileMap(..)
|
||||
, toCoord
|
||||
, toZoom
|
||||
, translate
|
||||
@ -26,6 +27,9 @@ type alias Coord = { x: Float, y: Float }
|
||||
type alias ZoomLevel = Int
|
||||
type FineZoomLevel = FineZoomLevel Int
|
||||
|
||||
|
||||
type TileMap = TileMap Coord ZoomLevel Int Int
|
||||
|
||||
zoomStep = 8
|
||||
|
||||
toZoom : FineZoomLevel -> ZoomLevel
|
||||
@ -75,8 +79,8 @@ pixelFromCoord c z =
|
||||
let {x,y} = tileCovering c (z + 8)
|
||||
in (x,y)
|
||||
|
||||
boundingTiles : Coord -> ZoomLevel -> Int -> Int -> (TileNumber, TileNumber)
|
||||
boundingTiles centre z width height =
|
||||
boundingTiles : TileMap -> (TileNumber, TileNumber)
|
||||
boundingTiles (TileMap centre z width height) =
|
||||
-- find the tiles needed to cover the area (`width` x `height`)
|
||||
-- about the point at `centre`
|
||||
let delta = pixelsToCoord z ((width // 2), (height // 2))
|
||||
@ -97,8 +101,9 @@ tileImg zoom tilenumber = img [ width 256,
|
||||
height 256,
|
||||
src (tileUrl tilenumber zoom) ] []
|
||||
|
||||
tiles centre zoom width height =
|
||||
let (mintile, maxtile) = boundingTiles centre zoom width height
|
||||
tiles tmap =
|
||||
let (TileMap centre zoom width height) = tmap
|
||||
(mintile, maxtile) = boundingTiles tmap
|
||||
xs = List.range mintile.x maxtile.x
|
||||
ys = List.range mintile.y maxtile.y
|
||||
in
|
||||
|
Loading…
Reference in New Issue
Block a user