diff options
Diffstat (limited to 'style-generator')
-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) |