aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJakub Hampl <kopomir@gmail.com>2018-07-13 16:26:15 +0100
committerJakub Hampl <kopomir@gmail.com>2018-07-13 16:26:15 +0100
commit23c3623bda77a4601cfec3dfd7d9961b7d4fb83c (patch)
treebe73de4926df482396ba8d9f2c5f6000f5552f3d /src
parentcc6d143dd8124e13059c26125e70237795e9a9a4 (diff)
Various small fixes
Diffstat (limited to 'src')
-rw-r--r--src/LngLat.elm5
-rw-r--r--src/Mapbox/Cmd/Option.elm21
-rw-r--r--src/Mapbox/Cmd/Template.elm66
-rw-r--r--src/Mapbox/Element.elm6
-rw-r--r--src/Mapbox/Expression.elm2
-rw-r--r--src/js/main.js4
6 files changed, 46 insertions, 58 deletions
diff --git a/src/LngLat.elm b/src/LngLat.elm
index 896dc73..537b125 100644
--- a/src/LngLat.elm
+++ b/src/LngLat.elm
@@ -1,6 +1,9 @@
module LngLat exposing (LngLat, encodeAsPair, encodeAsObject, decodeFromPair, decodeFromObject, map)
-{-| @docs LngLat, encodeAsPair, encodeAsObject, decodeFromPair, decodeFromObject, map
+{-| Encodes geographic position.
+
+@docs LngLat, encodeAsPair, encodeAsObject, decodeFromPair, decodeFromObject, map
+
-}
import Json.Encode as Encode exposing (Value)
diff --git a/src/Mapbox/Cmd/Option.elm b/src/Mapbox/Cmd/Option.elm
index 6157de4..3e2a889 100644
--- a/src/Mapbox/Cmd/Option.elm
+++ b/src/Mapbox/Cmd/Option.elm
@@ -1,4 +1,4 @@
-module Mapbox.Cmd.Option exposing (..)
+module Mapbox.Cmd.Option exposing (duration, easing, offset, animate, curve, minZoom, speed, screenSpeed, maxDuration, center, zoom, bearing, pitch, around, padding, Padding, linear, maxZoom, layers, filter, intersectsPoint, intersectsBox)
{-|
@@ -23,7 +23,10 @@ Options common to `jumpTo`, `easeTo`, and `flyTo`, controlling the desired locat
@docs padding, Padding, linear, maxZoom
-@docs layers, filter
+
+### Querying rendered features
+
+@docs layers, filter, intersectsPoint, intersectsBox
-}
@@ -186,3 +189,17 @@ layers =
filter : Expression DataExpression Bool -> Option { a | filter : Supported }
filter =
Mapbox.Expression.encode >> Option "filter"
+
+
+{-| Only include layers that instersect this point.
+-}
+intersectsPoint : LngLat -> Option { a | query : Supported }
+intersectsPoint =
+ LngLat.encodeAsPair >> Option "query"
+
+
+{-| Only include layers that instersect the box (defined as south west / north east corners).
+-}
+intersectsBox : ( LngLat, LngLat ) -> Option { a | query : Supported }
+intersectsBox =
+ encodePair (LngLat.encodeAsPair) >> Option "query"
diff --git a/src/Mapbox/Cmd/Template.elm b/src/Mapbox/Cmd/Template.elm
index d0f306e..0889c29 100644
--- a/src/Mapbox/Cmd/Template.elm
+++ b/src/Mapbox/Cmd/Template.elm
@@ -1,4 +1,4 @@
-module Mapbox.Cmd.Template exposing (Id, Outgoing, Option, Supported, panBy, panTo, zoomTo, zoomIn, zoomOut, rotateTo, jumpTo, easeTo, flyTo, stop, fitBounds, setRTLTextPlugin, Response(..), queryResults, getBounds, queryRenderedFeatures, Query(..), resize)
+module Mapbox.Cmd.Template exposing (Id, Outgoing, Option, Supported, panBy, panTo, zoomTo, zoomIn, zoomOut, rotateTo, jumpTo, easeTo, flyTo, stop, fitBounds, setRTLTextPlugin, queryResults, getBounds, queryRenderedFeatures, resize)
{-| This module has a bunch of essentially imperative commands for your map.
@@ -26,7 +26,7 @@ You can of course customize the module you copy into your codebase to support th
### Querying the map
-@docs Response, queryResults, getBounds, queryRenderedFeatures, Query
+@docs queryResults, getBounds, queryRenderedFeatures
-}
@@ -49,10 +49,13 @@ type alias Id =
String
+{-| This is exported here to simply for convenience. See `Cmd.Option` for more docs.
+-}
type alias Option support =
Internal.Option support
+{-| -}
type alias Supported =
Internal.Supported
@@ -340,26 +343,6 @@ getBounds prt id reqId =
makeCmd prt id "getBounds" [ ( "requestId", Encode.int reqId ) ]
-{-| The geometry of the query region. Either a point, a bounding box (specified in terms of southwest and northeast points), or what is currently visible in the viewport.
--}
-type Query
- = Viewport
- | Point LngLat
- | Box LngLat LngLat
-
-
-encodeQuery query =
- case query of
- Viewport ->
- Encode.string "viewport"
-
- Point lngLat ->
- LngLat.encodeAsPair lngLat
-
- Box sw ne ->
- encodePair LngLat.encodeAsPair ( sw, ne )
-
-
{-| Returns an array of GeoJSON Feature objects representing visible features that satisfy the query parameters. Takes a numerical ID that allows you to associate the question with the answer.
The response: The properties value of each returned feature object contains the properties of its source feature. For GeoJSON sources, only string and numeric property values are supported (i.e. null, Array, and Object values are not supported).
@@ -373,63 +356,46 @@ The topmost rendered feature appears first in the returned array, and subsequent
Because features come from tiled vector data or GeoJSON data that is converted to tiles internally, feature geometries may be split or duplicated across tile boundaries and, as a result, features may appear multiple times in query results. For example, suppose there is a highway running through the bounding rectangle of a query. The results of the query will be those parts of the highway that lie within the map tiles covering the bounding rectangle, even if the highway extends into other tiles, and the portion of the highway within each map tile will be returned as a separate feature. Similarly, a point feature near a tile boundary may appear in multiple tiles due to tile buffering.
-}
-queryRenderedFeatures : Outgoing msg -> Id -> Int -> List (Option { layers : Supported, filter : Supported }) -> Query -> Cmd msg
-queryRenderedFeatures prt id reqId options query =
+queryRenderedFeatures : Outgoing msg -> Id -> Int -> List (Option { layers : Supported, filter : Supported, query : Supported }) -> Cmd msg
+queryRenderedFeatures prt id reqId options =
makeCmd prt
id
"queryRenderedFeatures"
[ ( "requestId", Encode.int reqId )
- , ( "query", encodeQuery query )
, encodeOptions options
]
-{-| A response to the queries. See the relevant methods for more information.
--}
-type Response
- = GetBounds Int ( LngLat, LngLat )
- | QueryRenderedFeatures Int (List Value)
- | Error String
-
-
{-| Wraps an incoming port so that you can get nicer subscritions:
port elmMapboxIncoming : (Value -> msg) -> Sub msg
-
- -- exposed
-
- queryResults : (Response -> msg) -> Sub msg
-
- queryResuls =
- Mapbox.Cmd.queryResults elmMapboxIncoming
-
-}
-queryResults : ((Value -> msg) -> Sub msg) -> (Response -> msg) -> Sub msg
-queryResults prt tagger =
- prt (decodeResponse >> tagger)
+queryResults : ((Value -> msg) -> Sub msg) -> (Int -> ( LngLat, LngLat ) -> response) -> (Int -> List Value -> response) -> (String -> response) -> (response -> msg) -> Sub msg
+queryResults prt getBounds queryRenderedFeatures error tagger =
+ prt (decodeResponse getBounds queryRenderedFeatures error >> tagger)
-responseDecoder =
+responseDecoder getBounds queryRenderedFeatures =
Decode.field "type" Decode.string
|> Decode.andThen
(\s ->
case s of
"getBounds" ->
- Decode.map2 GetBounds (Decode.field "id" Decode.int) (Decode.field "bounds" (decodePair LngLat.decodeFromPair))
+ Decode.map2 getBounds (Decode.field "id" Decode.int) (Decode.field "bounds" (decodePair LngLat.decodeFromPair))
"queryRenderedFeatures" ->
- Decode.map2 QueryRenderedFeatures (Decode.field "id" Decode.int) (Decode.field "features" (Decode.list Decode.value))
+ Decode.map2 queryRenderedFeatures (Decode.field "id" Decode.int) (Decode.field "features" (Decode.list Decode.value))
_ ->
Decode.fail <| "Unrecognized response type: " ++ s
)
-decodeResponse value =
- case Decode.decodeValue responseDecoder value of
+decodeResponse getBounds queryRenderedFeatures error value =
+ case Decode.decodeValue (responseDecoder getBounds queryRenderedFeatures) value of
Ok res ->
res
Err e ->
- Error e
+ error e
diff --git a/src/Mapbox/Element.elm b/src/Mapbox/Element.elm
index 83f818e..f7382ca 100644
--- a/src/Mapbox/Element.elm
+++ b/src/Mapbox/Element.elm
@@ -58,14 +58,16 @@ map attrs style =
{-| This is literally:
- <link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.45.0/mapbox-gl.css' rel='stylesheet' />
+ <link
+ href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.46.0/mapbox-gl.css'
+ rel='stylesheet' />
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.
-}
css : Html msg
css =
- node "link" [ attribute "href" "https://api.tiles.mapbox.com/mapbox-gl-js/v0.45.0/mapbox-gl.css", attribute "rel" "stylesheet" ] []
+ node "link" [ attribute "href" "https://api.tiles.mapbox.com/mapbox-gl-js/v0.46.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 af8298c..efc2803 100644
--- a/src/Mapbox/Expression.elm
+++ b/src/Mapbox/Expression.elm
@@ -153,7 +153,7 @@ This way you can use the language without much syntactic fuss and you have easy
**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 form Elm), namely functions and let-in expressions.
+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.
@docs Expression, DataExpression, CameraExpression
diff --git a/src/js/main.js b/src/js/main.js
index ce720ca..255396e 100644
--- a/src/js/main.js
+++ b/src/js/main.js
@@ -121,7 +121,7 @@ function wrapElmApplication(elmApp, settings = {}) {
const keys = Object.keys(prevValue);
let newValue = {};
keys.forEach(k => {
- if (state[k] === undefined) {
+ if (state[k] === undefined ) {
newValue[k] = undefined;
}
});
@@ -343,7 +343,7 @@ function wrapElmApplication(elmApp, settings = {}) {
type: "queryRenderedFeatures",
id: event.requestId,
features:
- event.query === "viewport"
+ event.query
? map.queryRenderedFeatures(processOptions(event.options))
: map.queryRenderedFeatures(
event.query,