From 11d932001ed65fed690b835e5eef504f90845533 Mon Sep 17 00:00:00 2001 From: Jakub Hampl Date: Wed, 1 Aug 2018 09:38:06 +0100 Subject: Misc fixes --- src/Mapbox/Element.elm | 14 +-- src/Mapbox/Expression.elm | 228 ++++++++++++++++++++++++---------------------- src/Mapbox/Layer.elm | 136 +++++++++++++-------------- src/Mapbox/Source.elm | 2 +- src/Mapbox/Style.elm | 2 +- src/js/main.js | 9 +- 6 files changed, 199 insertions(+), 192 deletions(-) (limited to 'src') diff --git a/src/Mapbox/Element.elm b/src/Mapbox/Element.elm index f7382ca..14b6873 100644 --- a/src/Mapbox/Element.elm +++ b/src/Mapbox/Element.elm @@ -1,4 +1,4 @@ -module Mapbox.Element exposing (map, css, MapboxAttr, token, id, maxZoom, minZoom, maxBounds, renderWorldCopies, EventData, TouchEvent, eventFeaturesFilter, eventFeaturesLayers, onMouseDown, onMouseUp, onMouseOver, onMouseMove, onClick, onDblClick, onMouseOut, onContextMenu, onZoom, onZoomStart, onZoomEnd, onRotate, onRotateStart, onRotateEnd, onTouchEnd, onTouchMove, onTouchCancel) +module Mapbox.Element exposing (EventData, MapboxAttr, TouchEvent, css, eventFeaturesFilter, eventFeaturesLayers, id, map, maxBounds, maxZoom, minZoom, onClick, onContextMenu, onDblClick, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onRotate, onRotateEnd, onRotateStart, onTouchCancel, onTouchEnd, onTouchMove, onZoom, onZoomEnd, onZoomStart, renderWorldCopies, token) {-| This library wraps a Custom Element that actually renders a map. @@ -25,8 +25,8 @@ import Json.Decode as Decode exposing (Decoder, Value) import Json.Encode as Encode import LngLat exposing (LngLat) import Mapbox.Expression exposing (DataExpression, Expression) -import Mapbox.Style exposing (Style) import Mapbox.Helpers exposing (encodePair) +import Mapbox.Style exposing (Style) {-| This is the type that all attributes have. @@ -51,15 +51,15 @@ map attrs style = (Mapbox.Style.encode style |> property "mapboxStyle" ) - :: (List.map (\(MapboxAttr attr) -> attr) attrs) + :: List.map (\(MapboxAttr attr) -> attr) attrs in - node "elm-mapbox-map" props [] + node "elm-mapbox-map" props [] {-| 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. @@ -67,7 +67,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.46.0/mapbox-gl.css", attribute "rel" "stylesheet" ] [] + node "link" [ attribute "href" "https://api.tiles.mapbox.com/mapbox-gl-js/v0.47.0/mapbox-gl.css", attribute "rel" "stylesheet" ] [] {-| The minimum zoom level of the map (0-24). @@ -398,4 +398,4 @@ controlledMap { center, zoom, bearing, pitch } attrs style = :: property "pitch" (Encode.float pitch) :: List.map (\(MapboxAttr attr) -> attr) attrs in - node "elm-mapbox-map" props [] + node "elm-mapbox-map" props [] diff --git a/src/Mapbox/Expression.elm b/src/Mapbox/Expression.elm index 31c53c7..d800188 100644 --- a/src/Mapbox/Expression.elm +++ b/src/Mapbox/Expression.elm @@ -1,150 +1,150 @@ module Mapbox.Expression exposing - ( Expression - , DataExpression + ( Anchor(..) + , AnchorAuto , CameraExpression - , encode + , Collator , Color + , DataExpression + , Expression + , Interpolation(..) + , LineCap + , LineJoin , Object - , Collator - , defaultCollator - , true - , false - , bool - , int - , float - , str - , rgba - , floats - , strings - , object - , collator + , Position + , RasterResampling + , SymbolPlacement + , TextFit + , TextJustify + , TextTransform + , abs + , acos + , all + , anchorAutoAuto + , anchorAutoMap + , anchorAutoViewport + , anchorMap + , anchorViewport + , any + , append + , asin , assertArray - , assertArrayOfStrings - , assertArrayOfFloats , assertArrayOfBools + , assertArrayOfFloats + , assertArrayOfStrings , assertBool , assertFloat , assertObject , assertString - , toBool - , toColor - , toFloat - , toString - , typeof , at - , get - , has + , atan + , bool + , ceil + , coalesce + , collator + , conditionally + , cos , count - , length + , defaultCollator + , divideBy + , downcase + , e + , encode + , false , featureState + , float + , floats + , floor , geometryType - , id - , properties + , get , getProperty - , hasProperty - , isEqual - , notEqual - , lessThan - , lessThanOrEqual , greaterThan , greaterThanOrEqual - , isEqualWithCollator - , notEqualWithCollator - , lessThanWithCollator - , lessThanOrEqualWithCollator - , greaterThanWithCollator , greaterThanOrEqualWithCollator - , not - , all - , any + , greaterThanWithCollator + , has + , hasProperty + , heatmapDensity + , id , ifElse - , conditionally - , matchesStr - , matchesFloat - , coalesce + , int , interpolate - , Interpolation(..) - , step - , append - , downcase - , upcase + , isEqual + , isEqualWithCollator , isSupportedScript - , resolvedLocale - , makeRGBColor - , makeRGBAColor - , rgbaChannels - , minus - , multiply - , divideBy - , modBy - , plus - , raiseBy - , sqrt - , abs - , ceil - , floor - , round - , cos - , sin - , tan - , acos - , asin - , atan - , e - , pi + , length + , lessThan + , lessThanOrEqual + , lessThanOrEqualWithCollator + , lessThanWithCollator + , lineCapButt + , lineCapRound + , lineCapSquare + , lineJoinBevel + , lineJoinMiter + , lineJoinRound + , lineProgress , ln , ln2 , log10 , log2 - , zoom - , heatmapDensity - , lineProgress - , Anchor(..) - , anchorMap - , anchorViewport - , AnchorAuto - , anchorAutoMap - , anchorAutoViewport - , anchorAutoAuto - , Position + , makeRGBAColor + , makeRGBColor + , matchesFloat + , matchesStr + , minus + , modBy + , multiply + , not + , notEqual + , notEqualWithCollator + , object + , pi + , plus + , positionBottom + , positionBottomLeft + , positionBottomRight , positionCenter , positionLeft , positionRight , positionTop - , positionBottom , positionTopLeft , positionTopRight - , positionBottomLeft - , positionBottomRight - , TextFit - , textFitNone - , textFitWidth - , textFitHeight - , textFitBoth - , LineCap - , lineCapButt - , lineCapRound - , lineCapSquare - , LineJoin - , lineJoinBevel - , lineJoinRound - , lineJoinMiter - , SymbolPlacement - , symbolPlacementPoint + , properties + , raiseBy + , rasterResamplingLinear + , rasterResamplingNearest + , resolvedLocale + , rgba + , rgbaChannels + , round + , sin + , sqrt + , step + , str + , strings , symbolPlacementLine , symbolPlacementLineCenter - , TextJustify - , textJustifyLeft + , symbolPlacementPoint + , tan + , textFitBoth + , textFitHeight + , textFitNone + , textFitWidth , textJustifyCenter + , textJustifyLeft , textJustifyRight - , TextTransform + , textTransformLowercase , textTransformNone , textTransformUppercase - , textTransformLowercase - , RasterResampling - , rasterResamplingLinear - , rasterResamplingNearest + , toBool + , toColor + , toFloat + , toString + , true + , typeof + , upcase + , zoom ) {-| Expressions form a little language that can be used to compute values for various layer properties. @@ -779,6 +779,12 @@ assertBool = call1 "boolean" +{-| -} +assertBoolWithFalback : Bool -> Expression exprType any -> Expression exprType Bool +assertBoolWithFalback fallback value = + call2 "boolean" value (bool fallback) + + -- assertAtLeastOneBool : List (Expression exprType any) -> Expression exprType Bool -- assertAtLeastOneBool = @@ -1099,7 +1105,7 @@ matchesStr options (Expression default) (Expression input) = properOptions = List.concatMap (\( label, Expression output ) -> [ Json.Encode.string label, output ]) options in - call "match" (input :: properOptions ++ [ default ]) + call "match" (input :: properOptions ++ [ default ]) {-| Selects the output whose label value matches the input value, or the fallback value if no match is found. @@ -1119,7 +1125,7 @@ matchesFloat options (Expression default) (Expression input) = properOptions = List.concatMap (\( label, Expression output ) -> [ Json.Encode.float label, output ]) options in - call "match" (input :: properOptions ++ [ default ]) + call "match" (input :: properOptions ++ [ default ]) {-| Interpolation types: diff --git a/src/Mapbox/Layer.elm b/src/Mapbox/Layer.elm index 20e7af5..ce0fa67 100644 --- a/src/Mapbox/Layer.elm +++ b/src/Mapbox/Layer.elm @@ -1,55 +1,22 @@ module Mapbox.Layer exposing - ( Layer - , SourceId - , Background - , Fill - , Symbol - , Line - , Raster + ( Background , Circle + , Fill , FillExtrusion , Heatmap , Hillshade + , Layer , LayerAttr - , encode + , Line + , Raster + , SourceId + , Symbol , background - , fill - , symbol - , line - , raster + , backgroundColor + , backgroundOpacity + , backgroundPattern , circle - , fillExtrusion - , heatmap - , hillshade - , 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 @@ -61,11 +28,11 @@ module Mapbox.Layer , circleStrokeWidth , circleTranslate , circleTranslateAnchor - , heatmapColor - , heatmapIntensity - , heatmapOpacity - , heatmapRadius - , heatmapWeight + , encode + , fill + , fillAntialias + , fillColor + , fillExtrusion , fillExtrusionBase , fillExtrusionColor , fillExtrusionHeight @@ -73,6 +40,25 @@ module Mapbox.Layer , fillExtrusionPattern , fillExtrusionTranslate , fillExtrusionTranslateAnchor + , fillOpacity + , fillOutlineColor + , fillPattern + , fillTranslate + , fillTranslateAnchor + , filter + , heatmap + , heatmapColor + , heatmapIntensity + , heatmapOpacity + , heatmapRadius + , heatmapWeight + , hillshade + , hillshadeAccentColor + , hillshadeExaggeration + , hillshadeHighlightColor + , hillshadeIlluminationAnchor + , hillshadeIlluminationDirection + , hillshadeShadowColor , iconAllowOverlap , iconAnchor , iconColor @@ -94,6 +80,36 @@ module Mapbox.Layer , 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 @@ -123,30 +139,14 @@ module Mapbox.Layer , textTransform , textTranslate , textTranslateAnchor - , rasterBrightnessMax - , rasterBrightnessMin - , rasterContrast - , rasterResampling - , rasterFadeDuration - , rasterHueRotate - , rasterOpacity - , rasterSaturation - , hillshadeAccentColor - , hillshadeExaggeration - , hillshadeHighlightColor - , hillshadeIlluminationAnchor - , hillshadeIlluminationDirection - , hillshadeShadowColor - , backgroundColor - , backgroundOpacity - , backgroundPattern + , visible ) {-| Layers specify what is actually rendered on the map and are rendered in order. Except for layers of the background type, each layer needs to refer to a source. Layers take the data that they get from a source, optionally filter features, and then define how those features are styled. -There are two kinds of properties: *Layout* and *Paint* properties. +There are two kinds of properties: _Layout_ and _Paint_ properties. Layout properties are applied early in the rendering process and define how data for that layer is passed to the GPU. Changes to a layout property require an asynchronous "layout" step. @@ -218,7 +218,7 @@ Paint properties are applied later in the rendering process. Changes to a paint import Array exposing (Array) import Json.Encode as Encode exposing (Value) -import Mapbox.Expression as Expression exposing (Anchor, AnchorAuto, CameraExpression, Color, DataExpression, Expression, LineCap, LineJoin, Position, SymbolPlacement, TextFit, TextJustify, TextTransform, RasterResampling) +import Mapbox.Expression as Expression exposing (Anchor, AnchorAuto, CameraExpression, Color, DataExpression, Expression, LineCap, LineJoin, Position, RasterResampling, SymbolPlacement, TextFit, TextJustify, TextTransform) {-| Represents a layer. @@ -313,7 +313,7 @@ encodeAttrs attrs = { top = [], layout = [], paint = [] } attrs in - ( "layout", Encode.object layout ) :: ( "paint", Encode.object paint ) :: top + ( "layout", Encode.object layout ) :: ( "paint", Encode.object paint ) :: top {-| The background color or pattern of the map. diff --git a/src/Mapbox/Source.elm b/src/Mapbox/Source.elm index 7677df8..5cc571d 100644 --- a/src/Mapbox/Source.elm +++ b/src/Mapbox/Source.elm @@ -1,4 +1,4 @@ -module Mapbox.Source exposing (Source, SourceOption, raster, tileSize, rasterFromUrl, RasterSource, scheme, Scheme(..), rasterDEMMapbox, rasterDEMTerrarium, geoJSONFromUrl, geoJSONFromValue, GeoJSONSource, buffer, tolerance, cluster, clusterRadius, lineMetrics, Coords, image, video, staticCanvas, animatedCanvas, bounds, minzoom, maxzoom, attribution, encode, getId, Id, Url, vector, vectorFromUrl, VectorSource) +module Mapbox.Source exposing (Coords, GeoJSONSource, Id, RasterSource, Scheme(..), Source, SourceOption, Url, VectorSource, animatedCanvas, attribution, bounds, buffer, cluster, clusterRadius, encode, geoJSONFromUrl, geoJSONFromValue, getId, image, lineMetrics, maxzoom, minzoom, raster, rasterDEMMapbox, rasterDEMTerrarium, rasterFromUrl, scheme, staticCanvas, tileSize, tolerance, vector, vectorFromUrl, video) {-| diff --git a/src/Mapbox/Style.elm b/src/Mapbox/Style.elm index 1793067..500cf47 100644 --- a/src/Mapbox/Style.elm +++ b/src/Mapbox/Style.elm @@ -1,4 +1,4 @@ -module Mapbox.Style exposing (Style(..), StyleDef, encode, Light, defaultLight, Transition, defaultTransition, MiscAttr, sprite, glyphs, name, defaultCenter, defaultZoomLevel, defaultBearing, defaultPitch, metadata, streets, outdoors, light, dark, satellite, satelliteStreets) +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) {-| A Mapbox style is a document that defines the visual appearance of a map: what data to draw, the order to draw it in, and how to style the data when drawing it. A style document is a JSON object with specific root level and nested properties. This specification defines and describes these properties. diff --git a/src/js/main.js b/src/js/main.js index 255396e..eff72ed 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -108,6 +108,7 @@ function wrapElmApplication(elmApp, settings = {}) { return this._featureState; } set featureState(value) { + // TODO: Clean this up function makeId({id, source, sourceLayer}) { return `${id}::${source}::${sourceLayer}`; @@ -171,7 +172,7 @@ function wrapElmApplication(elmApp, settings = {}) { ) { wrapped = e => { e.features = this._map.queryRenderedFeatures( - [e.lngLat.lng, e.lngLat.lat], + e.point, { layers: this.eventFeaturesLayers, filter: this.eventFeaturesFilter @@ -182,14 +183,14 @@ function wrapElmApplication(elmApp, settings = {}) { } else if (["touchend", "touchmove", "touchcancel"].includes(type)) { wrapped = e => { e.features = this._map.queryRenderedFeatures( - [e.lngLat.lng, e.lngLat.lat], + [e.point], { layers: this.eventFeaturesLayers, filter: this.eventFeaturesFilter } ); - e.perPointFeatures = e.lngLats.map(({ lng, lat }) => - this._map.queryRenderedFeatures([lng, lat], { + e.perPointFeatures = e.points.map(point => + this._map.queryRenderedFeatures(point, { layers: this.eventFeaturesLayers, filter: this.eventFeaturesFilter }) -- cgit v1.2.3