parse actual lat/lon from gpx trkpt nodes
This commit is contained in:
parent
4922e4d5d9
commit
b78dbda7b8
@ -1,8 +1,7 @@
|
|||||||
module Track exposing (Track, parse)
|
module Track exposing (Track, Point, parse)
|
||||||
|
|
||||||
import Result
|
import Result
|
||||||
import Xml.Decode as XD exposing (path, single, list, float)
|
import Xml.Decode as XD exposing (path, list, floatAttr)
|
||||||
|
|
||||||
|
|
||||||
type alias Point =
|
type alias Point =
|
||||||
{ lat : Float
|
{ lat : Float
|
||||||
@ -12,11 +11,11 @@ type alias Point =
|
|||||||
type alias Track = List Point
|
type alias Track = List Point
|
||||||
|
|
||||||
pointDecoder = XD.map2 Point
|
pointDecoder = XD.map2 Point
|
||||||
(XD.path ["ele"] (single float))
|
(floatAttr "lat")
|
||||||
(XD.path ["ele"] (single float))
|
(floatAttr "lon")
|
||||||
|
|
||||||
gpxDecoder =
|
gpxDecoder =
|
||||||
(XD.path [ "trk", "trkseg", "trkpt" ] (XD.list pointDecoder))
|
(path [ "trk", "trkseg", "trkpt" ] (list pointDecoder))
|
||||||
|
|
||||||
|
|
||||||
parse str = XD.run gpxDecoder str
|
parse str = XD.run gpxDecoder str
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
module TrackTest exposing (specs)
|
module TrackTest exposing (specs)
|
||||||
import Fixtures
|
import Fixtures
|
||||||
|
|
||||||
import Track exposing (Track)
|
import Track exposing (Track, Point)
|
||||||
import Test exposing (..)
|
import Test exposing (..)
|
||||||
import Expect exposing (Expectation)
|
import Expect exposing (Expectation)
|
||||||
|
|
||||||
@ -12,8 +12,14 @@ specs =
|
|||||||
\_ ->
|
\_ ->
|
||||||
let
|
let
|
||||||
r = Track.parse Fixtures.threepoints
|
r = Track.parse Fixtures.threepoints
|
||||||
|
expected =
|
||||||
|
[ (Point 51.600643 -0.01856)
|
||||||
|
, (Point 51.600679 -0.018179)
|
||||||
|
, (Point 51.600697 -0.018064)
|
||||||
|
]
|
||||||
|
|
||||||
in
|
in
|
||||||
case r of
|
case r of
|
||||||
(Ok trk) -> Expect.equal (List.length trk) 3
|
(Ok trk) -> Expect.equalLists trk expected
|
||||||
_ -> Expect.fail "not ok"
|
_ -> Expect.fail "not ok"
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user