From 9bd079e10dfa68df2f2fec5adb35df90edb3525f Mon Sep 17 00:00:00 2001 From: Jakub Hampl Date: Fri, 15 Feb 2019 20:50:23 +0000 Subject: Mapbox Upgrade + Simplified Enums (#9) --- src/Internal.elm | 11 + src/Mapbox/Element.elm | 4 +- src/Mapbox/Expression.elm | 577 ++++++++++++++++------------------------------ src/Mapbox/Layer.elm | 412 +++++++++++++++------------------ src/Mapbox/Source.elm | 41 +++- src/Mapbox/Style.elm | 17 +- src/js/main.js | 22 +- 7 files changed, 463 insertions(+), 621 deletions(-) create mode 100644 src/Internal.elm (limited to 'src') diff --git a/src/Internal.elm b/src/Internal.elm new file mode 100644 index 0000000..82512bc --- /dev/null +++ b/src/Internal.elm @@ -0,0 +1,11 @@ +module Internal exposing (Expression(..), Supported) + +import Json.Encode exposing (Value) + + +type Expression exprType resultType + = Expression Value + + +type Supported + = Supported diff --git a/src/Mapbox/Element.elm b/src/Mapbox/Element.elm index b14f54a..7802983 100644 --- a/src/Mapbox/Element.elm +++ b/src/Mapbox/Element.elm @@ -64,7 +64,7 @@ map attrs style = {-| This is literally: You can include the required styles yourself if it fits better with the way you deploy your assets, this is meant as a quick way to get started. @@ -72,7 +72,7 @@ You can include the required styles yourself if it fits better with the way you -} css : Html msg css = - node "link" [ attribute "href" "https://api.tiles.mapbox.com/mapbox-gl-js/v0.52.0/mapbox-gl.css", attribute "rel" "stylesheet" ] [] + node "link" [ attribute "href" "https://api.tiles.mapbox.com/mapbox-gl-js/v0.53.0/mapbox-gl.css", attribute "rel" "stylesheet" ] [] {-| The minimum zoom level of the map (0-24). diff --git a/src/Mapbox/Expression.elm b/src/Mapbox/Expression.elm index 109a440..a2ae1ce 100644 --- a/src/Mapbox/Expression.elm +++ b/src/Mapbox/Expression.elm @@ -1,159 +1,26 @@ -module Mapbox.Expression - exposing - ( Anchor - , Auto - , CameraExpression - , Collator - , Color - , DataExpression - , Expression - , FormattedString - , FormattedText - , Interpolation(..) - , LineCap - , LineJoin - , Object - , Position - , RasterResampling - , SymbolPlacement - , SymbolZOrder - , TextFit - , TextJustify - , TextTransform - , abs - , acos - , all - , anchorAuto - , anchorMap - , anchorViewport - , any - , append - , asin - , assertArray - , assertArrayOfBools - , assertArrayOfFloats - , assertArrayOfStrings - , assertBool - , assertFloat - , assertObject - , assertString - , at - , atan - , bool - , ceil - , coalesce - , collator - , conditionally - , cos - , count - , defaultCollator - , divideBy - , downcase - , e - , encode - , false - , featureState - , float - , floats - , floor - , fontScaledBy - , format - , formatted - , geometryType - , get - , getProperty - , greaterThan - , greaterThanOrEqual - , greaterThanOrEqualWithCollator - , greaterThanWithCollator - , has - , hasProperty - , heatmapDensity - , id - , ifElse - , int - , interpolate - , isEqual - , isEqualWithCollator - , isSupportedScript - , length - , lessThan - , lessThanOrEqual - , lessThanOrEqualWithCollator - , lessThanWithCollator - , lineCapButt - , lineCapRound - , lineCapSquare - , lineJoinBevel - , lineJoinMiter - , lineJoinRound - , lineProgress - , ln - , ln2 - , log10 - , log2 - , makeRGBAColor - , makeRGBColor - , matchesFloat - , matchesStr - , minus - , modBy - , multiply - , not - , notEqual - , notEqualWithCollator - , object - , orderSource - , orderViewportY - , pi - , plus - , positionBottom - , positionBottomLeft - , positionBottomRight - , positionCenter - , positionLeft - , positionRight - , positionTop - , positionTopLeft - , positionTopRight - , properties - , raiseBy - , rasterResamplingLinear - , rasterResamplingNearest - , resolvedLocale - , rgba - , rgbaChannels - , round - , sin - , sqrt - , step - , str - , strings - , symbolPlacementLine - , symbolPlacementLineCenter - , symbolPlacementPoint - , tan - , textFitBoth - , textFitHeight - , textFitNone - , textFitWidth - , textJustifyCenter - , textJustifyLeft - , textJustifyRight - , textTransformLowercase - , textTransformNone - , textTransformUppercase - , toBool - , toColor - , toFloat - , toFormattedText - , toString - , true - , typeof - , upcase - , withFont - , zoom - ) +module Mapbox.Expression exposing + ( Expression, DataExpression, CameraExpression + , encode + , Color, Object, Collator, FormattedText + , true, false, bool, int, float, str, rgba, floats, strings, object, collator, defaultCollator + , assertArray, assertArrayOfStrings, assertArrayOfFloats, assertArrayOfBools, assertBool, assertFloat, assertObject, assertString + , toBool, toColor, toFloat, toString, toFormattedText + , formatNumber, NumberFormatOption, locale, currency, minFractionDigits, maxFractionDigits + , typeof + , at, get, has, count, length + , featureState, geometryType, id, properties, getProperty, hasProperty + , isEqual, notEqual, lessThan, lessThanOrEqual, greaterThan, greaterThanOrEqual + , isEqualWithCollator, notEqualWithCollator, lessThanWithCollator, lessThanOrEqualWithCollator, greaterThanWithCollator, greaterThanOrEqualWithCollator + , not, all, any + , ifElse, conditionally, matchesStr, matchesFloat, coalesce + , interpolate, Interpolation(..), step + , append, downcase, upcase, isSupportedScript, resolvedLocale + , format, FormattedString, formatted, fontScaledBy, withFont + , makeRGBColor, makeRGBAColor, rgbaChannels + , minus, multiply, divideBy, modBy, plus, raiseBy, sqrt, abs, ceil, floor, round, cos, sin, tan, acos, asin, atan, e, pi, ln, ln2, log10, log2 + , zoom, heatmapDensity, lineProgress + , map, viewport, auto, center, left, right, top, bottom, topLeft, topRight, bottomLeft, bottomRight, none, width, height, both, butt, rounded, square, bevel, miter, point, lineCenter, line, uppercase, lowercase, linear, nearest, viewportY, source + ) {-| Expressions form a little language that can be used to compute values for various layer properties. @@ -185,6 +52,21 @@ In the expression language you can do this in a similar fassion: , ( 1000, int 20 ) ] + +### Table of contents + + - [Types](#types) + - [Lookup](#lookup) + - [Feature data](#feature-data) + - [Decision](#decision) + - [Ramps, scales, curves](#ramps-scales-curves) + - [String](#string) + - [Formatted Text](#formatted-text) + - [Color](#color) + - [Math](#math) + - [Misx](#misc) + - [Enums](#enums) + **Note**: If you are familiar with the JS version of the style spec, we have made a few changes. Argument order has been switched for many functions to support using pipeline style more naturally. Some functions use overloading in the original, these have been renamed to not be overloaded. Finally, we have chosen not to represent some parts of the spec that are superflous (especially when used from Elm), namely functions and let-in expressions. @@ -223,6 +105,8 @@ You can also use these functions to explicitly cast to a particular type: @docs toBool, toColor, toFloat, toString, toFormattedText +@docs formatNumber, NumberFormatOption, locale, currency, minFractionDigits, maxFractionDigits + @docs typeof @@ -280,25 +164,24 @@ Control flow: @docs minus, multiply, divideBy, modBy, plus, raiseBy, sqrt, abs, ceil, floor, round, cos, sin, tan, acos, asin, atan, e, pi, ln, ln2, log10, log2 -### Zoom - -@docs zoom - - -### Heatmap +### Misc -@docs heatmapDensity, lineProgress +@docs zoom, heatmapDensity, lineProgress ### Enums -These are required for various layer properties. +These are required for various layer properties. They are not documented here as they are overloaded - you will find descriptions +of their effects at the relevant layer property. -@docs Anchor, anchorMap, anchorViewport, anchorAuto, Auto, Position, positionCenter, positionLeft, positionRight, positionTop, positionBottom, positionTopLeft, positionTopRight, positionBottomLeft, positionBottomRight, TextFit, textFitNone, textFitWidth, textFitHeight, textFitBoth, LineCap, lineCapButt, lineCapRound, lineCapSquare, LineJoin, lineJoinBevel, lineJoinRound, lineJoinMiter, SymbolPlacement, symbolPlacementPoint, symbolPlacementLine, symbolPlacementLineCenter, TextJustify, textJustifyLeft, textJustifyCenter, textJustifyRight, TextTransform, textTransformNone, textTransformUppercase, textTransformLowercase, RasterResampling, rasterResamplingLinear, rasterResamplingNearest, SymbolZOrder, orderViewportY, orderSource +**Note:** You may notice that these have slightly odd types. These types allow them to be overloaded for multiple properties, but still remain type safe. Don't worry about these too much! + +@docs map, viewport, auto, center, left, right, top, bottom, topLeft, topRight, bottomLeft, bottomRight, none, width, height, both, butt, rounded, square, bevel, miter, point, lineCenter, line, uppercase, lowercase, linear, nearest, viewportY, source -} import Array exposing (Array) +import Internal exposing (..) import Json.Encode exposing (Value) @@ -324,8 +207,8 @@ The `exprType` can be: The intent is to help you not break your style by using a DataExpression (for example) where it isn't supported. However, this isn't entirely foolproof, so some caution is advised. -} -type Expression exprType resultType - = Expression Value +type alias Expression exprType resultType = + Internal.Expression exprType resultType {-| A camera expression is any expression that uses the zoom operator. Such expressions allow the appearance of a layer @@ -396,302 +279,183 @@ type Collator -- Enums -{-| Encodes the relation to which something is measured or aligned to. The exact details are explained in the docs of each property supporting this. Some properties support the `anchorAuto` value, these have the type `Anchor Auto`, other don't and have the type `Anchor Never`. --} -type Anchor supportsAuto - = Anchor - - -{-| Relativeto the map. --} -anchorMap : Expression exprType (Anchor a) -anchorMap = +{-| -} +map : Expression exprType { a | map : Supported } +map = Expression (Json.Encode.string "map") -{-| Relative to the viewport. --} -anchorViewport : Expression exprType (Anchor a) -anchorViewport = +{-| -} +viewport : Expression exprType { a | viewport : Supported } +viewport = Expression (Json.Encode.string "viewport") {-| -} -type Auto - = Auto - - -{-| Automatic behaviour, that may vary based on circumstance between viewport and map. --} -anchorAuto : Expression exprType (Anchor Auto) -anchorAuto = +auto : Expression exprType { a | auto : Supported } +auto = Expression (Json.Encode.string "auto") -{-| Which part of the object is placed closest to the Anchor. --} -type Position - = Position - - {-| -} -positionCenter : Expression exprType Position -positionCenter = +center : Expression exprType { a | center : Supported } +center = Expression (Json.Encode.string "center") {-| -} -positionLeft : Expression exprType Position -positionLeft = +left : Expression exprType { a | left : Supported } +left = Expression (Json.Encode.string "left") {-| -} -positionRight : Expression exprType Position -positionRight = +right : Expression exprType { a | right : Supported } +right = Expression (Json.Encode.string "right") {-| -} -positionTop : Expression exprType Position -positionTop = +top : Expression exprType { a | top : Supported } +top = Expression (Json.Encode.string "top") {-| -} -positionBottom : Expression exprType Position -positionBottom = +bottom : Expression exprType { a | bottom : Supported } +bottom = Expression (Json.Encode.string "bottom") {-| -} -positionTopLeft : Expression exprType Position -positionTopLeft = +topLeft : Expression exprType { a | topLeft : Supported } +topLeft = Expression (Json.Encode.string "top-left") {-| -} -positionTopRight : Expression exprType Position -positionTopRight = +topRight : Expression exprType { a | topRight : Supported } +topRight = Expression (Json.Encode.string "top-right") {-| -} -positionBottomLeft : Expression exprType Position -positionBottomLeft = +bottomLeft : Expression exprType { a | bottomLeft : Supported } +bottomLeft = Expression (Json.Encode.string "bottom-left") {-| -} -positionBottomRight : Expression exprType Position -positionBottomRight = +bottomRight : Expression exprType { a | bottomRight : Supported } +bottomRight = Expression (Json.Encode.string "bottom-right") -{-| Scaling an icon to fit associated text. --} -type TextFit - = TextFit - - -{-| The icon is displayed at its intrinsic aspect ratio. --} -textFitNone : Expression exprType TextFit -textFitNone = +{-| -} +none : Expression exprType { a | none : Supported } +none = Expression (Json.Encode.string "none") -{-| The icon is scaled in the x-dimension to fit the width of the text. --} -textFitWidth : Expression exprType TextFit -textFitWidth = +{-| -} +width : Expression exprType { a | width : Supported } +width = Expression (Json.Encode.string "width") -{-| The icon is scaled in the y-dimension to fit the height of the text. --} -textFitHeight : Expression exprType TextFit -textFitHeight = +{-| -} +height : Expression exprType { a | height : Supported } +height = Expression (Json.Encode.string "height") -{-| The icon is scaled in both x- and y-dimensions. --} -textFitBoth : Expression exprType TextFit -textFitBoth = +{-| -} +both : Expression exprType { a | both : Supported } +both = Expression (Json.Encode.string "both") -{-| Display of line endings. --} -type LineCap - = LineCap - - -{-| A cap with a squared-off end which is drawn to the exact endpoint of the line. --} -lineCapButt : Expression exprType LineCap -lineCapButt = +{-| -} +butt : Expression exprType { a | butt : Supported } +butt = Expression (Json.Encode.string "butt") -{-| A cap with a rounded end which is drawn beyond the endpoint of the line at a radius of one-half of the line's width and centered on the endpoint of the line. --} -lineCapRound : Expression exprType LineCap -lineCapRound = +{-| -} +rounded : Expression exprType { a | rounded : Supported } +rounded = Expression (Json.Encode.string "round") -{-| A cap with a squared-off end which is drawn beyond the endpoint of the line at a distance of one-half of the line's width. --} -lineCapSquare : Expression exprType LineCap -lineCapSquare = +{-| -} +square : Expression exprType { a | square : Supported } +square = Expression (Json.Encode.string "square") -{-| Display of lines when joining. --} -type LineJoin - = LineJoin - - -{-| A join with a squared-off end which is drawn beyond the endpoint of the line at a distance of one-half of the line's width. --} -lineJoinBevel : Expression exprType LineJoin -lineJoinBevel = +{-| -} +bevel : Expression exprType { a | bevel : Supported } +bevel = Expression (Json.Encode.string "bevel") -{-| A join with a rounded end which is drawn beyond the endpoint of the line at a radius of one-half of the line's width and centered on the endpoint of the line. --} -lineJoinRound : Expression exprType LineJoin -lineJoinRound = - Expression (Json.Encode.string "round") - - -{-| A join with a sharp, angled corner which is drawn with the outer sides beyond the endpoint of the path until they meet. --} -lineJoinMiter : Expression exprType LineJoin -lineJoinMiter = +{-| -} +miter : Expression exprType { a | miter : Supported } +miter = Expression (Json.Encode.string "miter") -{-| Label placement relative to its geometry. --} -type SymbolPlacement - = SymbolPlacement - - -{-| The label is placed at the point where the geometry is located. --} -symbolPlacementPoint : Expression exprType SymbolPlacement -symbolPlacementPoint = +{-| -} +point : Expression exprType { a | point : Supported } +point = Expression (Json.Encode.string "point") -{-| The label is placed at the center of the line of the geometry. Can only be used on LineString and Polygon geometries. Note that a single feature in a vector tile may contain multiple line geometries. --} -symbolPlacementLineCenter : Expression exprType SymbolPlacement -symbolPlacementLineCenter = +{-| -} +lineCenter : Expression exprType { a | lineCenter : Supported } +lineCenter = Expression (Json.Encode.string "line-center") -{-| The label is placed along the line of the geometry. Can only be used on LineString and Polygon geometries. --} -symbolPlacementLine : Expression exprType SymbolPlacement -symbolPlacementLine = +{-| -} +line : Expression exprType { a | line : Supported } +line = Expression (Json.Encode.string "line") {-| -} -type TextJustify - = TextJustify - - -{-| The text is aligned to the left. --} -textJustifyLeft : Expression exprType TextJustify -textJustifyLeft = - Expression (Json.Encode.string "left") - - -{-| The text is centered. --} -textJustifyCenter : Expression exprType TextJustify -textJustifyCenter = - Expression (Json.Encode.string "center") - - -{-| The text is aligned to the right. --} -textJustifyRight : Expression exprType TextJustify -textJustifyRight = - Expression (Json.Encode.string "right") - - -{-| Specifies how to capitalize text. --} -type TextTransform - = TextTransform - - -{-| The text is not altered. --} -textTransformNone : Expression exprType TextTransform -textTransformNone = - Expression (Json.Encode.string "none") - - -{-| Forces all letters to be displayed in uppercase. --} -textTransformUppercase : Expression exprType TextTransform -textTransformUppercase = +uppercase : Expression exprType { a | uppercase : Supported } +uppercase = Expression (Json.Encode.string "uppercase") -{-| Forces all letters to be displayed in lowercase. --} -textTransformLowercase : Expression exprType TextTransform -textTransformLowercase = +{-| -} +lowercase : Expression exprType { a | lowercase : Supported } +lowercase = Expression (Json.Encode.string "lowercase") {-| -} -type RasterResampling - = RasterResampling - - -{-| (Bi)linear filtering interpolates pixel values using the weighted average of the four closest original source pixels creating a smooth but blurry look when overscaled. --} -rasterResamplingLinear : Expression exprType RasterResampling -rasterResamplingLinear = +linear : Expression exprType { a | linear : Supported } +linear = Expression (Json.Encode.string "linear") -{-| Nearest neighbor filtering interpolates pixel values using the nearest original source pixel creating a sharp but pixelated look when overscaled. --} -rasterResamplingNearest : Expression exprType RasterResampling -rasterResamplingNearest = +{-| -} +nearest : Expression exprType { a | nearest : Supported } +nearest = Expression (Json.Encode.string "nearest") -{-| Specifies the order in which overlapping symbols in the same layer are rendered --} -type SymbolZOrder - = SymbolZOrder - - -{-| Symbols will be sorted by their y-position relative to the viewport. --} -orderViewportY : Expression exprType SymbolZOrder -orderViewportY = +{-| -} +viewportY : Expression exprType { a | viewportY : Supported } +viewportY = Expression (Json.Encode.string "viewport-y") -{-| Symbols will be rendered in the same order as the source data with no sorting applied. --} -orderSource : Expression exprType SymbolZOrder -orderSource = +{-| -} +source : Expression exprType { a | source : Supported } +source = Expression (Json.Encode.string "source") @@ -758,17 +522,64 @@ list = Json.Encode.list encode >> Expression >> call1 "literal" +{-| -} +type NumberFormatOption + = NFOption String Value + + +{-| Specifies the locale to use as a BCP 47 language tag. Defaults to the current locale. +-} +locale : Expression exprType String -> NumberFormatOption +locale = + encode >> NFOption "locale" + + +{-| If set, will include a currency symbol in the resulting number (such as "JP¥" or "€"). Should be a ISO 4217 currency code. +-} +currency : Expression exprType String -> NumberFormatOption +currency = + encode >> NFOption "currency" + + +{-| Formatter will include at least this many digits after the decimal point. Defaults to 0. +-} +minFractionDigits : Expression exprType Float -> NumberFormatOption +minFractionDigits = + encode >> NFOption "min-fraction-digits" + + +{-| Formatter will include at most this many digits after the decimal point. Defaults to 3. +-} +maxFractionDigits : Expression exprType Float -> NumberFormatOption +maxFractionDigits = + encode >> NFOption "max-fraction-digits" + + +{-| Converts the input number into a string representation following locale dependent formatting rules. +-} +formatNumber : List NumberFormatOption -> Expression exprType Float -> Expression exprType String +formatNumber options number = + Expression + (Json.Encode.list identity + (Json.Encode.string "number-format" + :: encode number + :: [ Json.Encode.object (List.map (\(NFOption k v) -> ( k, v )) options) + ] + ) + ) + + {-| Returns a `Collator` for use in locale-dependent comparison operations. The first argument specifies if the comparison should be case sensitive. The second specifies if it is diacritic sensitive. The final locale argument specifies the IETF language tag of the locale to use. -} collator : Expression e1 Bool -> Expression e2 Bool -> Expression e3 String -> Expression e4 Collator -collator (Expression caseSensitive) (Expression diacriticSensitive) (Expression locale) = +collator (Expression caseSensitive) (Expression diacriticSensitive) (Expression lcle) = Expression (Json.Encode.list identity (Json.Encode.string "collator" :: [ Json.Encode.object [ ( "case-sensitive", caseSensitive ) , ( "diacritic-sensitive", diacriticSensitive ) - , ( "locale", locale ) + , ( "locale", lcle ) ] ] ) @@ -1186,10 +997,10 @@ coalesce = {-| The ternary operator: Layer.iconImage <| - ifElse - (greaterThan (getProperty (str "size")) (float 30)) - (str "hospital-32") - (str "clinic-32") + ifElse + (greaterThan (getProperty (str "size")) (float 30)) + (str "hospital-32") + (str "clinic-32") -} ifElse : Expression exprType1 Bool -> Expression exprType2 output -> Expression exprType3 output -> Expression exprType1 output @@ -1207,12 +1018,13 @@ conditionally vals (Expression default) = {-| Selects the output whose label value matches the input value, or the fallback value if no match is found. getProperty (str "type") - |> matchesStr - [ ("hospital", str "icon-hospital") - , ("clinic", str "icon-medical") - ] - (str "icon-generic") -- fallback value - |> Layer.iconImage + |> matchesStr + [ ( "hospital", str "icon-hospital" ) + , ( "clinic", str "icon-medical" ) + ] + (str "icon-generic") + -- fallback value + |> Layer.iconImage -} matchesStr : List ( String, Expression exprType2 output ) -> Expression exprType1 output -> Expression exprType3 String -> Expression exprType3 output @@ -1227,12 +1039,13 @@ matchesStr options (Expression default) (Expression input) = {-| Selects the output whose label value matches the input value, or the fallback value if no match is found. getProperty (str "size") - |> matchesFloat - [ (1, str "icon-hospital") - , (2, str "icon-medical") - ] - (str "icon-generic") -- fallback value - |> Layer.iconImage + |> matchesFloat + [ ( 1, str "icon-hospital" ) + , ( 2, str "icon-medical" ) + ] + (str "icon-generic") + -- fallback value + |> Layer.iconImage -} matchesFloat : List ( Float, Expression exprType2 output ) -> Expression exprType1 output -> Expression exprType3 Float -> Expression exprType3 output diff --git a/src/Mapbox/Layer.elm b/src/Mapbox/Layer.elm index 375a9d6..1eb4509 100644 --- a/src/Mapbox/Layer.elm +++ b/src/Mapbox/Layer.elm @@ -1,148 +1,19 @@ -module Mapbox.Layer - exposing - ( Background - , Circle - , Fill - , FillExtrusion - , Heatmap - , Hillshade - , Layer - , LayerAttr - , Line - , Raster - , SourceId - , Symbol - , background - , backgroundColor - , backgroundOpacity - , backgroundPattern - , circle - , circleBlur - , circleColor - , circleOpacity - , circlePitchAlignment - , circlePitchScale - , circleRadius - , circleStrokeColor - , circleStrokeOpacity - , circleStrokeWidth - , circleTranslate - , circleTranslateAnchor - , encode - , fill - , fillAntialias - , fillColor - , fillExtrusion - , fillExtrusionBase - , fillExtrusionColor - , fillExtrusionHeight - , fillExtrusionOpacity - , fillExtrusionPattern - , fillExtrusionTranslate - , fillExtrusionTranslateAnchor - , fillExtrusionVerticalGradient - , fillOpacity - , fillOutlineColor - , fillPattern - , fillTranslate - , fillTranslateAnchor - , filter - , heatmap - , heatmapColor - , heatmapIntensity - , heatmapOpacity - , heatmapRadius - , heatmapWeight - , hillshade - , hillshadeAccentColor - , hillshadeExaggeration - , hillshadeHighlightColor - , hillshadeIlluminationAnchor - , hillshadeIlluminationDirection - , hillshadeShadowColor - , iconAllowOverlap - , iconAnchor - , iconColor - , iconHaloBlur - , iconHaloColor - , iconHaloWidth - , iconIgnorePlacement - , iconImage - , iconKeepUpright - , iconOffset - , iconOpacity - , iconOptional - , iconPadding - , iconPitchAlignment - , iconRotate - , iconRotationAlignment - , iconSize - , iconTextFit - , iconTextFitPadding - , iconTranslate - , iconTranslateAnchor - , line - , lineBlur - , lineCap - , lineColor - , lineDasharray - , lineGapWidth - , lineGradient - , lineJoin - , lineMiterLimit - , lineOffset - , lineOpacity - , linePattern - , lineRoundLimit - , lineTranslate - , lineTranslateAnchor - , lineWidth - , maxzoom - , metadata - , minzoom - , raster - , rasterBrightnessMax - , rasterBrightnessMin - , rasterContrast - , rasterFadeDuration - , rasterHueRotate - , rasterOpacity - , rasterResampling - , rasterSaturation - , sourceLayer - , symbol - , symbolAvoidEdges - , symbolPlacement - , symbolSpacing - , symbolZOrder - , textAllowOverlap - , textAnchor - , textColor - , textField - , textFont - , textHaloBlur - , textHaloColor - , textHaloWidth - , textIgnorePlacement - , textJustify - , textKeepUpright - , textLetterSpacing - , textLineHeight - , textMaxAngle - , textMaxWidth - , textOffset - , textOpacity - , textOptional - , textPadding - , textPitchAlignment - , textRotate - , textRotationAlignment - , textSize - , textTransform - , textTranslate - , textTranslateAnchor - , visible - ) +module Mapbox.Layer exposing + ( Layer, SourceId, encode + , background, fill, symbol, line, raster, circle, fillExtrusion, heatmap, hillshade + , Background, Fill, Symbol, Line, Raster, Circle, FillExtrusion, Heatmap, Hillshade + , LayerAttr + , metadata, sourceLayer, minzoom, maxzoom, filter, visible + , fillAntialias, fillColor, fillOpacity, fillOutlineColor, fillPattern, fillTranslate, fillTranslateAnchor + , lineBlur, lineCap, lineColor, lineDasharray, lineGapWidth, lineGradient, lineJoin, lineMiterLimit, lineOffset, lineOpacity, linePattern, lineRoundLimit, lineTranslate, lineTranslateAnchor, lineWidth + , circleBlur, circleColor, circleOpacity, circlePitchAlignment, circlePitchScale, circleRadius, circleStrokeColor, circleStrokeOpacity, circleStrokeWidth, circleTranslate, circleTranslateAnchor + , heatmapColor, heatmapIntensity, heatmapOpacity, heatmapRadius, heatmapWeight + , fillExtrusionBase, fillExtrusionColor, fillExtrusionHeight, fillExtrusionOpacity, fillExtrusionPattern, fillExtrusionTranslate, fillExtrusionTranslateAnchor, fillExtrusionVerticalGradient + , iconAllowOverlap, iconAnchor, iconColor, iconHaloBlur, iconHaloColor, iconHaloWidth, iconIgnorePlacement, iconImage, iconKeepUpright, iconOffset, iconOpacity, iconOptional, iconPadding, iconPitchAlignment, iconRotate, iconRotationAlignment, iconSize, iconTextFit, iconTextFitPadding, iconTranslate, iconTranslateAnchor, symbolAvoidEdges, symbolPlacement, symbolSortKey, symbolSpacing, symbolZOrder, textAllowOverlap, textAnchor, textColor, textField, textFont, textHaloBlur, textHaloColor, textHaloWidth, textIgnorePlacement, textJustify, textKeepUpright, textLetterSpacing, textLineHeight, textMaxAngle, textMaxWidth, textOffset, textOpacity, textOptional, textPadding, textPitchAlignment, textRotate, textRotationAlignment, textSize, textTransform, textTranslate, textTranslateAnchor + , rasterBrightnessMax, rasterBrightnessMin, rasterContrast, rasterFadeDuration, rasterHueRotate, rasterOpacity, rasterResampling, rasterSaturation + , hillshadeAccentColor, hillshadeExaggeration, hillshadeHighlightColor, hillshadeIlluminationAnchor, hillshadeIlluminationDirection, hillshadeShadowColor + , backgroundColor, backgroundOpacity, backgroundPattern + ) {-| Layers specify what is actually rendered on the map and are rendered in order. @@ -155,6 +26,19 @@ Layout properties are applied early in the rendering process and define how data Paint properties are applied later in the rendering process. Changes to a paint property are cheap and happen synchronously. +#### Skip to: + + - [Fill Attributes](#fill-attibutes) + - [Line Attributes](#line-attibutes) + - [Circle Attributes](#circle-attibutes) + - [Heatmap Attributes](#heatmap-attibutes) + - [FillExtrusion Attributes](#fillextrusion-attibutes) + - [Symbol Attributes](#symbol-attibutes) + - [Raster Attributes](#raster-attibutes) + - [Hillshade Attributes](#hillshade-attibutes) + - [Background Attributes](#background-attibutes) + + ### Working with layers @docs Layer, SourceId, encode @@ -199,7 +83,7 @@ Paint properties are applied later in the rendering process. Changes to a paint ### Symbol Attributes -@docs iconAllowOverlap, iconAnchor, iconColor, iconHaloBlur, iconHaloColor, iconHaloWidth, iconIgnorePlacement, iconImage, iconKeepUpright, iconOffset, iconOpacity, iconOptional, iconPadding, iconPitchAlignment, iconRotate, iconRotationAlignment, iconSize, iconTextFit, iconTextFitPadding, iconTranslate, iconTranslateAnchor, symbolAvoidEdges, symbolPlacement, symbolSpacing, symbolZOrder, textAllowOverlap, textAnchor, textColor, textField, textFont, textHaloBlur, textHaloColor, textHaloWidth, textIgnorePlacement, textJustify, textKeepUpright, textLetterSpacing, textLineHeight, textMaxAngle, textMaxWidth, textOffset, textOpacity, textOptional, textPadding, textPitchAlignment, textRotate, textRotationAlignment, textSize, textTransform, textTranslate, textTranslateAnchor +@docs iconAllowOverlap, iconAnchor, iconColor, iconHaloBlur, iconHaloColor, iconHaloWidth, iconIgnorePlacement, iconImage, iconKeepUpright, iconOffset, iconOpacity, iconOptional, iconPadding, iconPitchAlignment, iconRotate, iconRotationAlignment, iconSize, iconTextFit, iconTextFitPadding, iconTranslate, iconTranslateAnchor, symbolAvoidEdges, symbolPlacement, symbolSortKey, symbolSpacing, symbolZOrder, textAllowOverlap, textAnchor, textColor, textField, textFont, textHaloBlur, textHaloColor, textHaloWidth, textIgnorePlacement, textJustify, textKeepUpright, textLetterSpacing, textLineHeight, textMaxAngle, textMaxWidth, textOffset, textOpacity, textOptional, textPadding, textPitchAlignment, textRotate, textRotationAlignment, textSize, textTransform, textTranslate, textTranslateAnchor ### Raster Attributes @@ -219,8 +103,9 @@ Paint properties are applied later in the rendering process. Changes to a paint -} import Array exposing (Array) +import Internal exposing (Supported) import Json.Encode as Encode exposing (Value) -import Mapbox.Expression as Expression exposing (Anchor, Auto, CameraExpression, Color, DataExpression, Expression, FormattedText, LineCap, LineJoin, Position, RasterResampling, SymbolPlacement, SymbolZOrder, TextFit, TextJustify, TextTransform) +import Mapbox.Expression as Expression exposing (CameraExpression, Color, DataExpression, Expression, FormattedText) {-| Represents a layer. @@ -443,13 +328,13 @@ visible vis = -- Fill -{-| Controls the frame of reference for `fillTranslate`. Paint property. Defaults to `anchorMap`. Requires `fillTranslate`. +{-| Controls the frame of reference for `fillTranslate`. Paint property. Defaults to `map`. Requires `fillTranslate`. - - `anchorMap`: The fill is translated relative to the map. - - `anchorViewport`: The fill is translated relative to the viewport. + - `map`: The fill is translated relative to the map. + - `viewport`: The fill is translated relative to the viewport. -} -fillTranslateAnchor : Expression CameraExpression (Anchor Never) -> LayerAttr Fill +fillTranslateAnchor : Expression CameraExpression { map : Supported, viewport : Supported } -> LayerAttr Fill fillTranslateAnchor = Expression.encode >> Paint "fill-translate-anchor" @@ -515,13 +400,13 @@ lineBlur = Expression.encode >> Paint "line-blur" -{-| Controls the frame of reference for `lineTranslate`. Paint property. Defaults to `anchorMap`. Requires `lineTranslate`. +{-| Controls the frame of reference for `lineTranslate`. Paint property. Defaults to `map`. Requires `lineTranslate`. - - `anchorMap`: The line is translated relative to the map. - - `anchorViewport`: The line is translated relative to the viewport. + - `map`: The line is translated relative to the map. + - `viewport`: The line is translated relative to the viewport. -} -lineTranslateAnchor : Expression CameraExpression (Anchor Never) -> LayerAttr Line +lineTranslateAnchor : Expression CameraExpression { map : Supported, viewport : Supported } -> LayerAttr Line lineTranslateAnchor = Expression.encode >> Paint "line-translate-anchor" @@ -580,16 +465,26 @@ lineColor = Expression.encode >> Paint "line-color" -{-| The display of line endings. Layout property. Defaults to `lineCapButt`. +{-| The display of line endings. Layout property. Defaults to `butt`. + + - `butt`: A cap with a squared-off end which is drawn to the exact endpoint of the line. + - `rounded`: A cap with a rounded end which is drawn beyond the endpoint of the line at a radius of one-half of the line's width and centered on the endpoint of the line. + - `square`: A cap with a squared-off end which is drawn beyond the endpoint of the line at a distance of one-half of the line's width. + -} -lineCap : Expression CameraExpression LineCap -> LayerAttr Line +lineCap : Expression CameraExpression { butt : Supported, rounded : Supported, square : Supported } -> LayerAttr Line lineCap = Expression.encode >> Layout "line-cap" -{-| The display of lines when joining. Layout property. Defaults to `lineJoinMiter`. +{-| The display of lines when joining. Layout property. Defaults to `miter`. + + - `bevel`: A join with a squared-off end which is drawn beyond the endpoint of the line at a distance of one-half of the line's width. + - `rounded`: A join with a rounded end which is drawn beyond the endpoint of the line at a radius of one-half of the line's width and centered on the endpoint of the line. + - `miter`: A join with a sharp, angled corner which is drawn with the outer sides beyond the endpoint of the path until they meet. + -} -lineJoin : Expression any LineJoin -> LayerAttr Line +lineJoin : Expression any { bevel : Supported, rounded : Supported, miter : Supported } -> LayerAttr Line lineJoin = Expression.encode >> Layout "line-join" @@ -656,35 +551,35 @@ circleRadius = Expression.encode >> Paint "circle-radius" -{-| Controls the frame of reference for `circleTranslate`. Paint property. Defaults to `anchorMap`. Requires `circleTranslate`. +{-| Controls the frame of reference for `circleTranslate`. Paint property. Defaults to `map`. Requires `circleTranslate`. - - `anchorMap`: The circle is translated relative to the map. - - `anchorViewport`: The circle is translated relative to the viewport. + - `map`: The circle is translated relative to the map. + - `viewport`: The circle is translated relative to the viewport. -} -circleTranslateAnchor : Expression CameraExpression (Anchor Never) -> LayerAttr Circle +circleTranslateAnchor : Expression CameraExpression { map : Supported, viewport : Supported } -> LayerAttr Circle circleTranslateAnchor = Expression.encode >> Paint "circle-translate-anchor" -{-| Controls the scaling behavior of the circle when the map is pitched. Paint property. Defaults to `anchorMap`. +{-| Controls the scaling behavior of the circle when the map is pitched. Paint property. Defaults to `map`. - - `anchorMap`: Circles are scaled according to their apparent distance to the camera. - - `anchorViewport`: Circles are not scaled. + - `map`: Circles are scaled according to their apparent distance to the camera. + - `viewport`: Circles are not scaled. -} -circlePitchScale : Expression CameraExpression (Anchor Never) -> LayerAttr Circle +circlePitchScale : Expression CameraExpression { map : Supported, viewport : Supported } -> LayerAttr Circle circlePitchScale = Expression.encode >> Paint "circle-pitch-scale" -{-| Orientation of circle when map is pitched. Paint property. Defaults to `anchorViewport`. +{-| Orientation of circle when map is pitched. Paint property. Defaults to `viewport`. - - `anchorMap`: The circle is aligned to the plane of the map. - - `anchorViewport`: The circle is aligned to the plane of the viewport. + - `map`: The circle is aligned to the plane of the map. + - `viewport`: The circle is aligned to the plane of the viewport. -} -circlePitchAlignment : Expression CameraExpression (Anchor Never) -> LayerAttr Circle +circlePitchAlignment : Expression CameraExpression { map : Supported, viewport : Supported } -> LayerAttr Circle circlePitchAlignment = Expression.encode >> Paint "circle-pitch-alignment" @@ -808,13 +703,13 @@ heatmapOpacity = -- FillExtrusion -{-| Controls the frame of reference for `fillExtrusionTranslate`. Paint property. Defaults to `anchorMap`. Requires `fillExtrusionTranslate`. +{-| Controls the frame of reference for `fillExtrusionTranslate`. Paint property. Defaults to `map`. Requires `fillExtrusionTranslate`. - - `anchorMap`: The fill extrusion is translated relative to the map. - - `anchorViewport`: The fill extrusion is translated relative to the viewport. + - `map`: The fill extrusion is translated relative to the map. + - `viewport`: The fill extrusion is translated relative to the viewport. -} -fillExtrusionTranslateAnchor : Expression CameraExpression (Anchor Never) -> LayerAttr FillExtrusion +fillExtrusionTranslateAnchor : Expression CameraExpression { map : Supported, viewport : Supported } -> LayerAttr FillExtrusion fillExtrusionTranslateAnchor = Expression.encode >> Paint "fill-extrusion-translate-anchor" @@ -884,31 +779,36 @@ fillExtrusionVerticalGradient = -- Symbol -{-| Controls the frame of reference for `iconTranslate`. Paint property. Defaults to `anchorMap`. Requires `iconImage`. Requires `iconTranslate`. +{-| Controls the frame of reference for `iconTranslate`. Paint property. Defaults to `map`. Requires `iconImage`. Requires `iconTranslate`. - - `anchorMap`: Icons are translated relative to the map. - - `anchorViewport`: Icons are translated relative to the viewport. + - `map`: Icons are translated relative to the map. + - `viewport`: Icons are translated relative to the viewport. -} -iconTranslateAnchor : Expression CameraExpression (Anchor Never) -> LayerAttr Symbol +iconTranslateAnchor : Expression CameraExpression { map : Supported, viewport : Supported } -> LayerAttr Symbol iconTranslateAnchor = Expression.encode >> Paint "icon-translate-anchor" -{-| Controls the frame of reference for `textTranslate`. Paint property. Defaults to `anchorMap`. Requires `textField`. Requires `textTranslate`. +{-| Controls the frame of reference for `textTranslate`. Paint property. Defaults to `map`. Requires `textField`. Requires `textTranslate`. - - `anchorMap`: The text is translated relative to the map. - - `anchorViewport`: The text is translated relative to the viewport. + - `map`: The text is translated relative to the map. + - `viewport`: The text is translated relative to the viewport. -} -textTranslateAnchor : Expression CameraExpression (Anchor Never) -> LayerAttr Symbol +textTranslateAnchor : Expression CameraExpression { map : Supported, viewport : Supported } -> LayerAttr Symbol textTranslateAnchor = Expression.encode >> Paint "text-translate-anchor" -{-| Controls the order in which overlapping symbols in the same layer are rendered Layout property. Defaults to `orderViewportY`. +{-| Controls the order in which overlapping symbols in the same layer are rendered Layout property. Defaults to `auto`. + + - `auto`: If `symbolSortKey` is set, sort based on that. Otherwise sort symbols by their position relative to the viewport. + - `viewportY`: Symbols will be sorted by their y-position relative to the viewport. + - `source`: Symbols will be rendered in the same order as the source data with no sorting applied. + -} -symbolZOrder : Expression CameraExpression SymbolZOrder -> LayerAttr Symbol +symbolZOrder : Expression CameraExpression { auto : Supported, viewportY : Supported, source : Supported } -> LayerAttr Symbol symbolZOrder = Expression.encode >> Layout "symbol-z-order" @@ -1019,7 +919,7 @@ iconOptional = Expression.encode >> Layout "icon-optional" -{-| If true, the icon may be flipped to prevent it from being rendered upside-down. Layout property. Defaults to `false`. Requires `iconImage`. Requires `iconRotationAlignment` to be `map`. Requires `symbolPlacement` to be `symbolPlacementLine`, or `symbolPlacementLineCenter`. +{-| If true, the icon may be flipped to prevent it from being rendered upside-down. Layout property. Defaults to `false`. Requires `iconImage`. Requires `iconRotationAlignment` to be `map`. Requires `symbolPlacement` to be `line`, or `lineCenter`. -} iconKeepUpright : Expression CameraExpression Bool -> LayerAttr Symbol iconKeepUpright = @@ -1040,7 +940,7 @@ symbolAvoidEdges = Expression.encode >> Layout "symbol-avoid-edges" -{-| If true, the text may be flipped vertically to prevent it from being rendered upside-down. Layout property. Defaults to `true`. Requires `textField`. Requires `textRotationAlignment` to be `map`. Requires `symbolPlacement` to be `symbolPlacementLine`, or `symbolPlacementLineCenter`. +{-| If true, the text may be flipped vertically to prevent it from being rendered upside-down. Layout property. Defaults to `true`. Requires `textField`. Requires `textRotationAlignment` to be `map`. Requires `symbolPlacement` to be `line`, or `lineCenter`. -} textKeepUpright : Expression CameraExpression Bool -> LayerAttr Symbol textKeepUpright = @@ -1054,39 +954,44 @@ textAllowOverlap = Expression.encode >> Layout "text-allow-overlap" -{-| In combination with `symbolPlacement`, determines the rotation behavior of icons. Layout property. Defaults to `anchorAuto`. Requires `iconImage`. +{-| In combination with `symbolPlacement`, determines the rotation behavior of icons. Layout property. Defaults to `auto`. Requires `iconImage`. - - `anchorMap`: When `symbolPlacement` is set to `symbolPlacementPoint`, aligns icons east-west. When `symbolPlacement` is set to `symbolPlacementLine` or `symbolPlacementLineCenter`, aligns icon x-axes with the line. - - `anchorViewport`: Produces icons whose x-axes are aligned with the x-axis of the viewport, regardless of the value of `symbolPlacement`. - - `anchorAuto`: When `symbolPlacement` is set to `symbolPlacementPoint`, this is equivalent to `anchorViewport`. When `symbolPlacement` is set to `symbolPlacementLine` or `symbolPlacementLineCenter`, this is equivalent to `anchorMap`. + - `map`: When `symbolPlacement` is set to `point`, aligns icons east-west. When `symbolPlacement` is set to `line` or `lineCenter`, aligns icon x-axes with the line. + - `viewport`: Produces icons whose x-axes are aligned with the x-axis of the viewport, regardless of the value of `symbolPlacement`. + - `auto`: When `symbolPlacement` is set to `point`, this is equivalent to `viewport`. When `symbolPlacement` is set to `line` or `lineCenter`, this is equivalent to `map`. -} -iconRotationAlignment : Expression CameraExpression (Anchor Auto) -> LayerAttr Symbol +iconRotationAlignment : Expression CameraExpression { map : Supported, viewport : Supported, auto : Supported } -> LayerAttr Symbol iconRotationAlignment = Expression.encode >> Layout "icon-rotation-alignment" -{-| In combination with `symbolPlacement`, determines the rotation behavior of the individual glyphs forming the text. Layout property. Defaults to `anchorAuto`. Requires `textField`. +{-| In combination with `symbolPlacement`, determines the rotation behavior of the individual glyphs forming the text. Layout property. Defaults to `auto`. Requires `textField`. - - `anchorMap`: When `symbolPlacement` is set to `symbolPlacementPoint`, aligns text east-west. When `symbolPlacement` is set to `symbolPlacementLine` or `symbolPlacementLineCenter`, aligns text x-axes with the line. - - `anchorViewport`: Produces glyphs whose x-axes are aligned with the x-axis of the viewport, regardless of the value of `symbolPlacement`. - - `anchorAuto`: When `symbolPlacement` is set to `symbolPlacementPoint`, this is equivalent to `anchorViewport`. When `symbolPlacement` is set to `symbolPlacementLine` or `symbolPlacementLineCenter`, this is equivalent to `anchorMap`. + - `map`: When `symbolPlacement` is set to `point`, aligns text east-west. When `symbolPlacement` is set to `line` or `lineCenter`, aligns text x-axes with the line. + - `viewport`: Produces glyphs whose x-axes are aligned with the x-axis of the viewport, regardless of the value of `symbolPlacement`. + - `auto`: When `symbolPlacement` is set to `point`, this is equivalent to `viewport`. When `symbolPlacement` is set to `line` or `lineCenter`, this is equivalent to `map`. -} -textRotationAlignment : Expression CameraExpression (Anchor Auto) -> LayerAttr Symbol +textRotationAlignment : Expression CameraExpression { map : Supported, viewport : Supported, auto : Supported } -> LayerAttr Symbol textRotationAlignment = Expression.encode >> Layout "text-rotation-alignment" -{-| Label placement relative to its geometry. Layout property. Defaults to `symbolPlacementPoint`. +{-| Label placement relative to its geometry. Layout property. Defaults to `point`. + + - `point`: The label is placed at the point where the geometry is located. + - `line`: The label is placed along the line of the geometry. Can only be used on `lineString` and `polygon` geometries. + - `lineCenter`: The label is placed at the center of the line of the geometry. Can only be used on `lineString` and `polygon` geometries. Note that a single feature in a vector tile may contain multiple line geometries. + -} -symbolPlacement : Expression CameraExpression SymbolPlacement -> LayerAttr Symbol +symbolPlacement : Expression CameraExpression { point : Supported, line : Supported, lineCenter : Supported } -> LayerAttr Symbol symbolPlacement = Expression.encode >> Layout "symbol-placement" {-| Maximum angle change between adjacent characters. Layout property. -Units in degrees. Defaults to `45`. Requires `textField`. Requires `symbolPlacement` to be `symbolPlacementLine`, or `symbolPlacementLineCenter`. +Units in degrees. Defaults to `45`. Requires `textField`. Requires `symbolPlacement` to be `line`, or `lineCenter`. -} textMaxAngle : Expression CameraExpression Float -> LayerAttr Symbol textMaxAngle = @@ -1115,40 +1020,62 @@ textOffset = Expression.encode >> Layout "text-offset" -{-| Orientation of icon when map is pitched. Layout property. Defaults to `anchorAuto`. Requires `iconImage`. +{-| Orientation of icon when map is pitched. Layout property. Defaults to `auto`. Requires `iconImage`. - - `anchorMap`: The icon is aligned to the plane of the map. - - `anchorViewport`: The icon is aligned to the plane of the viewport. - - `anchorAuto`: Automatically matches the value of `iconRotationAlignment`. + - `map`: The icon is aligned to the plane of the map. + - `viewport`: The icon is aligned to the plane of the viewport. + - `auto`: Automatically matches the value of `iconRotationAlignment`. -} -iconPitchAlignment : Expression CameraExpression (Anchor Auto) -> LayerAttr Symbol +iconPitchAlignment : Expression CameraExpression { map : Supported, viewport : Supported, auto : Supported } -> LayerAttr Symbol iconPitchAlignment = Expression.encode >> Layout "icon-pitch-alignment" -{-| Orientation of text when map is pitched. Layout property. Defaults to `anchorAuto`. Requires `textField`. +{-| Orientation of text when map is pitched. Layout property. Defaults to `auto`. Requires `textField`. - - `anchorMap`: The text is aligned to the plane of the map. - - `anchorViewport`: The text is aligned to the plane of the viewport. - - `anchorAuto`: Automatically matches the value of `textRotationAlignment`. + - `map`: The text is aligned to the plane of the map. + - `viewport`: The text is aligned to the plane of the viewport. + - `auto`: Automatically matches the value of `textRotationAlignment`. -} -textPitchAlignment : Expression CameraExpression (Anchor Auto) -> LayerAttr Symbol +textPitchAlignment : Expression CameraExpression { map : Supported, viewport : Supported, auto : Supported } -> LayerAttr Symbol textPitchAlignment = Expression.encode >> Layout "text-pitch-alignment" -{-| Part of the icon placed closest to the anchor. Layout property. Defaults to `positionCenter`. Requires `iconImage`. +{-| Part of the icon placed closest to the anchor. Layout property. Defaults to `center`. Requires `iconImage`. + + - `center`: The center of the icon is placed closest to the anchor. + - `left`: The left side of the icon is placed closest to the anchor. + - `right`: The right side of the icon is placed closest to the anchor. + - `top`: The top of the icon is placed closest to the anchor. + - `bottom`: The bottom of the icon is placed closest to the anchor. + - `topLeft`: The top left corner of the icon is placed closest to the anchor. + - `topRight`: The top right corner of the icon is placed closest to the anchor. + - `bottomLeft`: The bottom left corner of the icon is placed closest to the anchor. + - `bottomRight`: The bottom right corner of the icon is placed closest to the anchor. + -} -iconAnchor : Expression any Position -> LayerAttr Symbol +iconAnchor : Expression any { center : Supported, left : Supported, right : Supported, top : Supported, bottom : Supported, topLeft : Supported, topRight : Supported, bottomLeft : Supported, bottomRight : Supported } -> LayerAttr Symbol iconAnchor = Expression.encode >> Layout "icon-anchor" -{-| Part of the text placed closest to the anchor. Layout property. Defaults to `positionCenter`. Requires `textField`. +{-| Part of the text placed closest to the anchor. Layout property. Defaults to `center`. Requires `textField`. + + - `center`: The center of the text is placed closest to the anchor. + - `left`: The left side of the text is placed closest to the anchor. + - `right`: The right side of the text is placed closest to the anchor. + - `top`: The top of the text is placed closest to the anchor. + - `bottom`: The bottom of the text is placed closest to the anchor. + - `topLeft`: The top left corner of the text is placed closest to the anchor. + - `topRight`: The top right corner of the text is placed closest to the anchor. + - `bottomLeft`: The bottom left corner of the text is placed closest to the anchor. + - `bottomRight`: The bottom right corner of the text is placed closest to the anchor. + -} -textAnchor : Expression any Position -> LayerAttr Symbol +textAnchor : Expression any { center : Supported, left : Supported, right : Supported, top : Supported, bottom : Supported, topLeft : Supported, topRight : Supported, bottomLeft : Supported, bottomRight : Supported } -> LayerAttr Symbol textAnchor = Expression.encode >> Layout "text-anchor" @@ -1169,9 +1096,15 @@ textRotate = Expression.encode >> Layout "text-rotate" -{-| Scales the icon to fit around the associated text. Layout property. Defaults to `textFitNone`. Requires `iconImage`. Requires `textField`. +{-| Scales the icon to fit around the associated text. Layout property. Defaults to `none`. Requires `iconImage`. Requires `textField`. + + - `none`: The icon is displayed at its intrinsic aspect ratio. + - `width`: The icon is scaled in the x-dimension to fit the width of the text. + - `height`: The icon is scaled in the y-dimension to fit the height of the text. + - `both`: The icon is scaled in both x- and y-dimensions. + -} -iconTextFit : Expression CameraExpression TextFit -> LayerAttr Symbol +iconTextFit : Expression CameraExpression { none : Supported, width : Supported, height : Supported, both : Supported } -> LayerAttr Symbol iconTextFit = Expression.encode >> Layout "icon-text-fit" @@ -1188,7 +1121,7 @@ iconSize = {-| Size of the additional area added to dimensions determined by `iconTextFit`, in clockwise order: top, right, bottom, left. Layout property. -Units in pixels. Defaults to `0,0,0,0`. Requires `iconImage`. Requires `textField`. Requires `iconTextFit` to be `textFitBoth`, or `textFitWidth`, or `textFitHeight`. +Units in pixels. Defaults to `0,0,0,0`. Requires `iconImage`. Requires `textField`. Requires `iconTextFit` to be `both`, or `width`, or `height`. -} iconTextFitPadding : Expression CameraExpression (Array Float) -> LayerAttr Symbol iconTextFitPadding = @@ -1217,16 +1150,33 @@ textPadding = Expression.encode >> Layout "text-padding" -{-| Specifies how to capitalize text, similar to the CSS `textTransform` property. Layout property. Defaults to `textTransformNone`. Requires `textField`. +{-| Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key wehn they overlap. Features with a lower sort key will have priority over other features when doing placement. Layout property. -} -textTransform : Expression any TextTransform -> LayerAttr Symbol +symbolSortKey : Expression CameraExpression Float -> LayerAttr Symbol +symbolSortKey = + Expression.encode >> Layout "symbol-sort-key" + + +{-| Specifies how to capitalize text, similar to the CSS `textTransform` property. Layout property. Defaults to `none`. Requires `textField`. + + - `none`: The text is not altered. + - `uppercase`: Forces all letters to be displayed in uppercase. + - `lowercase`: Forces all letters to be displayed in lowercase. + +-} +textTransform : Expression any { none : Supported, uppercase : Supported, lowercase : Supported } -> LayerAttr Symbol textTransform = Expression.encode >> Layout "text-transform" -{-| Text justification options. Layout property. Defaults to `textJustifyCenter`. Requires `textField`. +{-| Text justification options. Layout property. Defaults to `center`. Requires `textField`. + + - `left`: The text is aligned to the left. + - `center`: The text is centered. + - `right`: The text is aligned to the right. + -} -textJustify : Expression any TextJustify -> LayerAttr Symbol +textJustify : Expression any { left : Supported, center : Supported, right : Supported } -> LayerAttr Symbol textJustify = Expression.encode >> Layout "text-justify" @@ -1317,7 +1267,7 @@ textOpacity = Expression.encode >> Paint "text-opacity" -{-| Value to use for a text label. Layout property. Defaults to ``. +{-| Value to use for a text label. Layout property. Defaults to `""`. -} textField : Expression any FormattedText -> LayerAttr Symbol textField = @@ -1397,9 +1347,13 @@ rasterOpacity = Expression.encode >> Paint "raster-opacity" -{-| The resampling/interpolation method to use for overscaling, also known as texture magnification filter Paint property. Defaults to `rasterResamplingLinear`. +{-| The resampling/interpolation method to use for overscaling, also known as texture magnification filter Paint property. Defaults to `linear`. + + - `linear`: (Bi)linear filtering interpolates pixel values using the weighted average of the four closest original source pixels creating a smooth but blurry look when overscaled + - `nearest`: Nearest neighbor filtering interpolates pixel values using the nearest original source pixel creating a sharp but pixelated look when overscaled + -} -rasterResampling : Expression CameraExpression RasterResampling -> LayerAttr Raster +rasterResampling : Expression CameraExpression { linear : Supported, nearest : Supported } -> LayerAttr Raster rasterResampling = Expression.encode >> Paint "raster-resampling" @@ -1408,13 +1362,13 @@ rasterResampling = -- Hillshade -{-| Direction of light source when map is rotated. Paint property. Defaults to `anchorViewport`. +{-| Direction of light source when map is rotated. Paint property. Defaults to `viewport`. - - `anchorMap`: The hillshade illumination is relative to the north direction. - - `anchorViewport`: The hillshade illumination is relative to the top of the viewport. + - `map`: The hillshade illumination is relative to the north direction. + - `viewport`: The hillshade illumination is relative to the top of the viewport. -} -hillshadeIlluminationAnchor : Expression CameraExpression (Anchor Never) -> LayerAttr Hillshade +hillshadeIlluminationAnchor : Expression CameraExpression { map : Supported, viewport : Supported } -> LayerAttr Hillshade hillshadeIlluminationAnchor = Expression.encode >> Paint "hillshade-illumination-anchor" @@ -1429,7 +1383,7 @@ hillshadeExaggeration = Expression.encode >> Paint "hillshade-exaggeration" -{-| The direction of the light source used to generate the hillshading with 0 as the top of the viewport if `hillshadeIlluminationAnchor` is set to `anchorViewport` and due north if `hillshadeIlluminationAnchor` is set to `anchorMap`. Paint property. +{-| The direction of the light source used to generate the hillshading with 0 as the top of the viewport if `hillshadeIlluminationAnchor` is set to `viewport` and due north if `hillshadeIlluminationAnchor` is set to `map`. Paint property. Should be between `0` and `359` inclusive. Defaults to `335`. diff --git a/src/Mapbox/Source.elm b/src/Mapbox/Source.elm index 38bb319..68d1862 100644 --- a/src/Mapbox/Source.elm +++ b/src/Mapbox/Source.elm @@ -1,4 +1,14 @@ -module Mapbox.Source exposing (Coords, GeoJSONSource, Id, RasterSource, Scheme(..), Source, SourceOption, Url, VectorSource, animatedCanvas, attribution, bounds, buffer, cluster, clusterRadius, encode, generateIds, geoJSONFromUrl, geoJSONFromValue, getId, image, lineMetrics, maxzoom, minzoom, raster, rasterDEMMapbox, rasterDEMTerrarium, rasterFromUrl, scheme, staticCanvas, tileSize, tolerance, vector, vectorFromUrl, video) +module Mapbox.Source exposing + ( Source, SourceOption + , Id, Url + , vector, vectorFromUrl, VectorSource + , raster, tileSize, rasterFromUrl, RasterSource + , rasterDEMMapbox, rasterDEMTerrarium + , geoJSONFromUrl, geoJSONFromValue, GeoJSONSource, buffer, tolerance, cluster, clusterRadius, clusterProperties, lineMetrics, generateIds + , Coords, image, video, staticCanvas, animatedCanvas + , bounds, minzoom, maxzoom, attribution, scheme, Scheme(..) + , encode, getId + ) {-| @@ -27,7 +37,7 @@ module Mapbox.Source exposing (Coords, GeoJSONSource, Id, RasterSource, Scheme(. ### GeoJSON -@docs geoJSONFromUrl, geoJSONFromValue, GeoJSONSource, buffer, tolerance, cluster, clusterRadius, lineMetrics, generateIds +@docs geoJSONFromUrl, geoJSONFromValue, GeoJSONSource, buffer, tolerance, cluster, clusterRadius, clusterProperties, lineMetrics, generateIds ### Image, Video & Canvas @@ -48,8 +58,10 @@ Tiled sources can also take the following attributes: -} +import Internal import Json.Encode exposing (Value) import LngLat exposing (LngLat) +import Mapbox.Expression as Expression exposing (DataExpression, Expression) {-| Every layer is identified by an id. @@ -194,6 +206,31 @@ clusterMaxZoom = Json.Encode.float >> SourceOption "clusterMaxZoom" +{-| When clustering, you may want to aggregate values from the points included in the cluster. This function allows you to associate a name that will be the property name with a fold that computes the aggregation. For example: + + clusterProperties + [ ( "sum", E.plus, E.getProperty (str "scalerank") ) + , ( "max", \point aggregate -> E.max aggregate point, E.getProperty (str "scalerank") ) + ] + +Would produce clusters with two additional properties: `sum` and `max`, which you could then further use in data driven styling. + +-} +clusterProperties : List ( String, Expression DataExpression a -> Expression DataExpression b -> Expression DataExpression b, Expression DataExpression a ) -> SourceOption GeoJSONSource +clusterProperties = + List.map + (\( name, fold, map ) -> + ( name + , Json.Encode.list identity + [ Expression.encode <| fold (Expression.getProperty (Expression.str name)) (Internal.Expression (Json.Encode.list Json.Encode.string [ "accumulated" ])) + , Expression.encode <| map + ] + ) + ) + >> Json.Encode.object + >> SourceOption "clusterProperties" + + {-| Whether to calculate line distance metrics. This is required for line layers that specify `lineGradient` values. -} lineMetrics : Bool -> SourceOption GeoJSONSource diff --git a/src/Mapbox/Style.elm b/src/Mapbox/Style.elm index cbb9f56..c33de45 100644 --- a/src/Mapbox/Style.elm +++ b/src/Mapbox/Style.elm @@ -1,4 +1,10 @@ -module Mapbox.Style exposing (Light, MiscAttr, Style(..), StyleDef, Transition, dark, defaultBearing, defaultCenter, defaultLight, defaultPitch, defaultTransition, defaultZoomLevel, encode, glyphs, light, metadata, name, outdoors, satellite, satelliteStreets, sprite, streets) +module Mapbox.Style exposing + ( Style(..), encode, StyleDef +