diff options
| author | Patrick Sier <pjsier@users.noreply.github.com> | 2019-08-07 07:22:42 -0500 | 
|---|---|---|
| committer | Jakub Hampl <kopomir@gmail.com> | 2019-08-07 13:22:42 +0100 | 
| commit | 09249b8f3e88e70fc78a7d1f8b91e89c5962661b (patch) | |
| tree | b392851f6fc7364803f1b25b455395dc56878ca7 /style-generator/src | |
| parent | 139623233f47fda9593fba160664c8e016c088ee (diff) | |
Adds support for inline TileJSON in style generator (#45)
Diffstat (limited to 'style-generator/src')
| -rw-r--r-- | style-generator/src/Decoder.elm | 41 | 
1 files changed, 36 insertions, 5 deletions
| diff --git a/style-generator/src/Decoder.elm b/style-generator/src/Decoder.elm index 5acb722..1df0a73 100644 --- a/style-generator/src/Decoder.elm +++ b/style-generator/src/Decoder.elm @@ -43,6 +43,16 @@ layerName nm =          } +sourceName nm = +    Advanced.aliasedName +        { modulePath = layerNs +        , aliasName = +            "Source" +        , name = nm +        , typeName = Nothing +        } + +  styleCode : Decoder String  styleCode =      D.map file style @@ -211,14 +221,30 @@ decodeSource =              (\t ->                  case t of                      "vector" -> -                        D.field "url" D.string -                            |> D.map -                                (\url -> +                        D.oneOf +                            [ D.field "url" D.string +                                |> D.map +                                    (\url -> +                                        \id -> +                                            call2 (Advanced.aliasedName { modulePath = sourceNs, aliasName = "Source", name = "vectorFromUrl", typeName = Nothing }) +                                                (string id) +                                                (string url) +                                    ) +                            , D.map6 +                                (\tiles bounds minzoom maxzoom attribution scheme ->                                      \id -> -                                        call2 (Advanced.aliasedName { modulePath = sourceNs, aliasName = "Source", name = "vectorFromUrl", typeName = Nothing }) +                                        call3 (Advanced.aliasedName { modulePath = sourceNs, aliasName = "Source", name = "vector", typeName = Nothing })                                              (string id) -                                            (string url) +                                            (list (List.map string tiles)) +                                            (list ([ bounds, minzoom, maxzoom, attribution, scheme ] |> List.filterMap identity))                                  ) +                                (D.field "tiles" (D.list D.string)) +                                (sourceField "bounds" "bounds" (D.list D.float) (\l -> List.map float l |> list)) +                                (sourceField "minzoom" "minzoom" D.float float) +                                (sourceField "maxzoom" "maxzoom" D.float float) +                                (sourceField "attribution" "attribution" D.string string) +                                (sourceField "scheme" "scheme" D.string string) +                            ]                      "raster" ->                          D.map @@ -235,6 +261,11 @@ decodeSource =              ) +sourceField : String -> String -> Decoder a -> (a -> Expression) -> Decoder (Maybe Expression) +sourceField name elmName decoder toExpr = +    D.maybe (D.field name (D.map (\item -> call1 (sourceName elmName) (toExpr item)) decoder)) + +  decodeMisc =      D.map6 (\sprite glyphs name zoom bearing pitch -> [ sprite, glyphs, name, zoom, bearing, pitch ] |> List.filterMap identity |> list)          (miscField "sprite" "sprite" D.string string) | 
