set Model start/duration from points
This commit is contained in:
parent
aa36f74762
commit
c10e5ea70d
@ -158,7 +158,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 None start duration Empty),
|
||||
((Model (toCoord 51.60 -0.01) (FineZoomLevel (13*8)) None None 0 0 Empty),
|
||||
(fetchTrack start duration))
|
||||
|
||||
-- SUBSCRIPTIONS
|
||||
@ -234,7 +234,15 @@ updateModel msg model =
|
||||
}
|
||||
Loaded result ->
|
||||
case result of
|
||||
Ok trk -> { model | track = Present trk }
|
||||
Ok trk ->
|
||||
let start = Maybe.withDefault 0 (Point.startTime trk)
|
||||
duration = Point.duration trk
|
||||
in
|
||||
{ model
|
||||
| track = Present trk
|
||||
, startTime = floor start
|
||||
, duration = ceiling duration
|
||||
}
|
||||
Err (Http.BadBody e) -> { model | track = Debug.log e (Failure "e") }
|
||||
Err e -> { model | track = Debug.log "unknown error" (Failure "e") }
|
||||
NewUrlRequest -> model
|
||||
|
@ -1,4 +1,4 @@
|
||||
module Point exposing(Pos, Point, decoder, downsample, duration, subseq)
|
||||
module Point exposing(Pos, Point, decoder, downsample, duration, subseq, startTime)
|
||||
|
||||
import Json.Decode as D
|
||||
|
||||
@ -63,6 +63,11 @@ duration points =
|
||||
(p::ps) -> (last p ps).time - p.time
|
||||
_ -> 0
|
||||
|
||||
startTime points =
|
||||
case points of
|
||||
(p::ps) -> Just p.time
|
||||
_ -> Nothing
|
||||
|
||||
subseq points start dur =
|
||||
case points of
|
||||
[] -> []
|
||||
|
Loading…
Reference in New Issue
Block a user