centre map on loaded track
This commit is contained in:
parent
8c187fe3c9
commit
f379d2d9b9
@ -166,7 +166,7 @@ init _ url navKey =
|
||||
Just (Timeline (Just s) (Just d)) -> (s, d)
|
||||
_ -> (10,10)
|
||||
in
|
||||
((Model (toCoord 51.60 -0.01) (FineZoomLevel (13*8)) None 0 0 Empty),
|
||||
((Model (toCoord 0 0) (FineZoomLevel (1*8)) None 0 0 Empty),
|
||||
(fetchTrack start duration))
|
||||
|
||||
-- SUBSCRIPTIONS
|
||||
@ -198,6 +198,11 @@ type Msg
|
||||
| UrlChanged
|
||||
| Dribble String
|
||||
|
||||
|
||||
coordFromPos p =
|
||||
let {lat, lon } = p
|
||||
in toCoord lat lon
|
||||
|
||||
update : Msg -> Model -> (Model, Cmd Msg)
|
||||
|
||||
update msg model = (updateModel msg model, Cmd.none)
|
||||
@ -243,6 +248,8 @@ updateModel msg model =
|
||||
in
|
||||
{ model
|
||||
| track = Present trk
|
||||
, centre = coordFromPos (Point.centre trk)
|
||||
, zoom = FineZoomLevel ( 13 * 8)
|
||||
, startTime = floor start
|
||||
, duration = ceiling duration
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
module Point exposing(Pos, Point, decoder, downsample, duration, subseq, startTime)
|
||||
module Point exposing(Pos, Point, decoder, downsample, duration, subseq, startTime, centre)
|
||||
|
||||
import Json.Decode as D
|
||||
|
||||
@ -68,6 +68,30 @@ startTime points =
|
||||
(p::ps) -> Just p.time
|
||||
_ -> Nothing
|
||||
|
||||
type Bound = Bound Pos Pos | NoBound
|
||||
|
||||
extendBound : Pos -> Bound -> Bound
|
||||
extendBound pos b =
|
||||
let {lat, lon} = pos
|
||||
in case b of
|
||||
(Bound p1 p2) ->
|
||||
Bound
|
||||
(Pos (min lat p1.lat) (min lon p1.lon) Nothing)
|
||||
(Pos (max lat p2.lat) (max lon p2.lon) Nothing)
|
||||
NoBound ->
|
||||
Bound pos pos
|
||||
|
||||
bounds points =
|
||||
List.foldr extendBound NoBound (List.map .pos points)
|
||||
|
||||
centre points =
|
||||
case bounds points of
|
||||
Bound min max -> Pos
|
||||
((max.lat + min.lat) / 2)
|
||||
((max.lon + min.lon) / 2)
|
||||
Nothing
|
||||
NoBound -> Pos 0 0 Nothing
|
||||
|
||||
subseq points start dur =
|
||||
case points of
|
||||
[] -> []
|
||||
|
Loading…
Reference in New Issue
Block a user