From 09249b8f3e88e70fc78a7d1f8b91e89c5962661b Mon Sep 17 00:00:00 2001 From: Patrick Sier Date: Wed, 7 Aug 2019 07:22:42 -0500 Subject: Adds support for inline TileJSON in style generator (#45) --- style-generator/src/Decoder.elm | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'style-generator') 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) -- cgit v1.2.3