aboutsummaryrefslogtreecommitdiffstats
path: root/src/Mapbox/Layer.elm
diff options
context:
space:
mode:
authorAndré Dietrich <andre.dietrich@ovgu.de>2020-01-07 18:02:43 +0100
committerAndré Dietrich <andre.dietrich@ovgu.de>2020-01-07 18:02:43 +0100
commit1d440169042ecb74482569637f480306ad331f26 (patch)
tree80ea57140c34d738788cae8d98018915e5aa802b /src/Mapbox/Layer.elm
parent42d5dacc1e2edeff15fabe507fdd6b4e335923d2 (diff)
parentd07b8909baedf4740b12f0c72d61b4f111ba2af2 (diff)
Merge branch 'master' of https://github.com/andre-dietrich/elm-mapbox
Diffstat (limited to 'src/Mapbox/Layer.elm')
-rw-r--r--src/Mapbox/Layer.elm57
1 files changed, 51 insertions, 6 deletions
diff --git a/src/Mapbox/Layer.elm b/src/Mapbox/Layer.elm
index 9f5e8a2..24f457d 100644
--- a/src/Mapbox/Layer.elm
+++ b/src/Mapbox/Layer.elm
@@ -1,9 +1,9 @@
module Mapbox.Layer exposing
( Layer, SourceId, encode
- , background, fill, symbol, line, raster, circle, fillExtrusion, heatmap, hillshade
+ , background, fill, json, jsonList, symbol, line, raster, circle, fillExtrusion, heatmap, hillshade
, Background, Fill, Symbol, Line, Raster, Circle, FillExtrusion, Heatmap, Hillshade
, LayerAttr
- , metadata, sourceLayer, minzoom, maxzoom, filter, visible
+ , metadata, sourceLayer, minzoom, maxzoom, filter, visible, visible2
, fillAntialias, fillColor, fillOpacity, fillOutlineColor, fillPattern, fillTranslate, fillTranslateAnchor
, lineBlur, lineCap, lineColor, lineDasharray, lineDasharray2, lineGapWidth, lineGradient, lineJoin, lineMiterLimit, lineOffset, lineOpacity, linePattern, lineRoundLimit, lineTranslate, lineTranslateAnchor, lineWidth
, circleBlur, circleColor, circleOpacity, circlePitchAlignment, circlePitchScale, circleRadius, circleStrokeColor, circleStrokeOpacity, circleStrokeWidth, circleTranslate, circleTranslateAnchor
@@ -13,6 +13,7 @@ module Mapbox.Layer exposing
, rasterBrightnessMax, rasterBrightnessMin, rasterContrast, rasterFadeDuration, rasterHueRotate, rasterOpacity, rasterResampling, rasterSaturation
, hillshadeAccentColor, hillshadeExaggeration, hillshadeHighlightColor, hillshadeIlluminationAnchor, hillshadeIlluminationDirection, hillshadeShadowColor
, backgroundColor, backgroundOpacity, backgroundPattern
+ , decode
)
{-| Layers specify what is actually rendered on the map and are rendered in order.
@@ -46,14 +47,14 @@ Paint properties are applied later in the rendering process. Changes to a paint
### Layer Types
-@docs background, fill, symbol, line, raster, circle, fillExtrusion, heatmap, hillshade
+@docs background, fill, json, jsonList, symbol, line, raster, circle, fillExtrusion, heatmap, hillshade
@docs Background, Fill, Symbol, Line, Raster, Circle, FillExtrusion, Heatmap, Hillshade
### General Attributes
@docs LayerAttr
-@docs metadata, sourceLayer, minzoom, maxzoom, filter, visible
+@docs metadata, sourceLayer, minzoom, maxzoom, filter, visible, visible2
### Fill Attributes
@@ -100,10 +101,16 @@ Paint properties are applied later in the rendering process. Changes to a paint
@docs backgroundColor, backgroundOpacity, backgroundPattern
+
+### List Decoder
+
+@docs decode
+
-}
import Array exposing (Array)
import Internal exposing (Supported)
+import Json.Decode as Decode exposing (Decoder)
import Json.Encode as Encode exposing (Value)
import Mapbox.Expression as Expression exposing (CameraExpression, Color, DataExpression, Expression, FormattedText)
@@ -173,8 +180,8 @@ encode (Layer value) =
layerImpl tipe id source attrs =
- [ ( "type", Encode.string tipe )
- , ( "id", Encode.string id )
+ [ ( "id", Encode.string id )
+ , ( "type", Encode.string tipe )
, ( "source", Encode.string source )
]
++ encodeAttrs attrs
@@ -271,6 +278,29 @@ hillshade =
layerImpl "hillshade"
+{-| Directly aass a json value layer
+-}
+json : Value -> Layer
+json =
+ Layer
+
+
+{-| Directly aass a json value layer
+-}
+jsonList : String -> List Layer
+jsonList =
+ Decode.decodeString (Decode.list Decode.value)
+ >> Result.withDefault []
+ >> List.map json
+
+
+{-| Directly aass a json value layer
+-}
+decode : Decoder (List Layer)
+decode =
+ Decode.list (Decode.value |> Decode.map json)
+
+
{-| -}
type LayerAttr tipe
= Top String Value
@@ -331,6 +361,21 @@ visible isVisible =
"none"
+{-| Directly use a boolean value to set a layer to visible or not.
+-}
+visible2 : Bool -> LayerAttr any
+visible2 vis =
+ (if vis then
+ "visible"
+
+ else
+ "none"
+ )
+ |> Expression.str
+ |> Expression.encode
+ |> Layout "visibility"
+
+
-- Fill