aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md92
-rw-r--r--docs/MapCommands.md144
-rw-r--r--elm-package.json12
-rw-r--r--examples/Example01.elm21
-rw-r--r--examples/MapCommands.elm179
-rw-r--r--src/LngLat.elm58
-rw-r--r--src/Mapbox/Cmd/Internal.elm14
-rw-r--r--src/Mapbox/Cmd/Option.elm188
-rw-r--r--src/Mapbox/Cmd/Template.elm (renamed from src/Mapbox/Cmd.elm)213
-rw-r--r--src/Mapbox/Element.elm51
-rw-r--r--src/Mapbox/Helpers.elm4
-rw-r--r--src/Mapbox/Source.elm28
-rw-r--r--src/Mapbox/Style.elm7
-rw-r--r--src/js/main.js16
14 files changed, 540 insertions, 487 deletions
diff --git a/README.md b/README.md
index a9c6b95..b50830c 100644
--- a/README.md
+++ b/README.md
@@ -46,13 +46,14 @@ module Example01 exposing (main)
import Html exposing (div, text)
import Html.Attributes exposing (style)
-import Json.Decode exposing (Value)
+import LngLat exposing (LngLat)
+import MapCommands
+import Mapbox.Cmd.Option as Opt
import Mapbox.Element exposing (..)
import Mapbox.Expression as E exposing (false, float, int, str, true)
import Mapbox.Layer as Layer
import Mapbox.Source as Source
import Mapbox.Style as Style exposing (Style(..))
-import MapCommands
main =
@@ -65,7 +66,7 @@ main =
init =
- ( { position = ( 0, 0 ) }, Cmd.none )
+ ( { position = LngLat 0 0 }, Cmd.none )
type Msg
@@ -73,55 +74,57 @@ type Msg
| Click EventData
-mapPair f ( a, b ) =
- ( f a, f b )
-
-
update msg model =
case msg of
Hover { lngLat } ->
( { model | position = lngLat }, Cmd.none )
Click { lngLat } ->
- ( model, MapCommands.fitBounds [] ( mapPair (\a -> a - 0.2) lngLat, mapPair (\a -> a + 0.2) lngLat ) )
-
-style =
- Style
- { transition = Style.defaultTransition
- , light = Style.defaultLight
- , sources =
- [ Source.vectorFromUrl "composite" "mapbox://mapbox.mapbox-terrain-v2,mapbox.mapbox-streets-v7" ]
- , misc =
- [ Style.name "light"
- , Style.defaultCenter 20.39789404164037 43.22523201923144
- , Style.defaultZoomLevel 1.5967483759772743
- , Style.sprite "mapbox://sprites/user/cjht22eqw0lfc2ro6z0qhlm29"
- , Style.glyphs "mapbox://fonts/user/{fontstack}/{range}.pbf"
- ]
- , layers =
- [ Layer.background "background"
- [ E.rgba 246 246 244 1 |> Layer.backgroundColor
- ]
- , Layer.fill "landcover"
- "composite"
- [ Layer.sourceLayer "landcover"
- , E.any
- [ E.getProperty (str "class") |> E.isEqual (str "wood")
- , E.getProperty (str "class") |> E.isEqual (str "scrub")
- , E.getProperty (str "class") |> E.isEqual (str "grass")
- , E.getProperty (str "class") |> E.isEqual (str "crop")
- ]
- |> Layer.filter
- , Layer.fillColor (E.rgba 227 227 227 1)
- , Layer.fillOpacity (float 0.6)
- ]
- ]
- }
+ ( model, MapCommands.fitBounds [ Opt.linear True, Opt.maxZoom 10 ] ( LngLat.map (\a -> a - 0.2) lngLat, LngLat.map (\a -> a + 0.2) lngLat ) )
+
view model =
div [ style [ ( "width", "100vw" ), ( "height", "100vh" ) ] ]
[ css
- , map [ onMouseMove Hover, onClick Click, id MapCommands.id ] style
+ , map
+ [ maxZoom 5
+ , onMouseMove Hover
+ , onClick Click
+ , id "my-map"
+ ]
+ (Style
+ { transition = Style.defaultTransition
+ , light = Style.defaultLight
+ , sources =
+ [ Source.vectorFromUrl "composite" "mapbox://mapbox.mapbox-terrain-v2,mapbox.mapbox-streets-v7" ]
+ , misc =
+ [ Style.name "light"
+ , Style.defaultCenter <| LngLat 20.39789404164037 43.22523201923144
+ , Style.defaultZoomLevel 1.5967483759772743
+ , Style.sprite "mapbox://sprites/astrosat/cjht22eqw0lfc2ro6z0qhlm29"
+ , Style.glyphs "mapbox://fonts/astrosat/{fontstack}/{range}.pbf"
+ ]
+ , layers =
+ [ Layer.background "background"
+ [ E.rgba 246 246 244 1 |> Layer.backgroundColor
+ ]
+ , Layer.fill "landcover"
+ "composite"
+ [ Layer.sourceLayer "landcover"
+ , E.any
+ [ E.getProperty (str "class") |> E.isEqual (str "wood")
+ , E.getProperty (str "class") |> E.isEqual (str "scrub")
+ , E.getProperty (str "class") |> E.isEqual (str "grass")
+ , E.getProperty (str "class") |> E.isEqual (str "crop")
+ ]
+ |> Layer.filter
+
+ , Layer.fillColor (E.ifElse (E.coalesce [ (E.featureState (str "hover")), false ]) (E.rgba 20 227 227 1) (E.rgba 227 227 227 1))
+ , Layer.fillOpacity (float 0.6)
+ ]
+ ]
+ }
+ )
, div [ style [ ( "position", "absolute" ), ( "bottom", "20px" ), ( "left", "20px" ) ] ] [ text (toString model.position) ]
]
```
@@ -149,9 +152,8 @@ var app = elmMapbox(Elm.MyApp.fullscreen({
The `elmMapbox` function accepts an options object that takes the following options:
- `token`: the Mapbox token. If you don't pass it here, you will need to use the `token` Elm attribute.
- - `outgoingPort`: the name of the outgoing port. Default: `elmMapboxOutgoing`.
- - `incomingPort`: the name of the incoming port. Default `elmMapboxIncoming`.
- - `easingFunctions`: an object whose values are easing functions (i.e. they take a number between 0..1 and return a number between 0..1). You can refer to these with the `easing` option in the Cmd module.
+ - `easingFunctions`: an object whose values are easing functions (i.e. they take a number between 0..1 and return a number between 0..1). You can refer to these with the `easing` option in the Cmd.Option module.
+ - `onMount` a callback that gives you access to the mapbox instance whenever a map gets instantiated. Mostly useful for registering plugins.
### License
diff --git a/docs/MapCommands.md b/docs/MapCommands.md
new file mode 100644
index 0000000..e6a09fd
--- /dev/null
+++ b/docs/MapCommands.md
@@ -0,0 +1,144 @@
+# MapCommands
+
+This module has a bunch of essentially imperative commands for your map.
+
+#### `id : String`
+
+Maps should use this as their DOM id.
+
+## Moving the map around
+
+#### `panBy : List (Option { duration : S, easing : S, offset : S, animate : S }) -> ( Int, Int ) -> Cmd msg`
+
+Pans the map by the specified offset.
+
+#### `panTo : List (Option { duration : S, easing : S, offset : S, animate : S }) -> LngLat -> Cmd msg`
+
+Pans the map to the specified location, with an animated transition.
+
+
+#### `zoomTo : List (Option { duration : S, easing : S, offset : S, animate : S }) -> Float -> Cmd msg`
+
+Zooms the map to the specified zoom level, with an animated transition.
+
+#### `zoomIn : List (Option { duration : S, easing : S, offset : S, animate : S }) -> Cmd msg`
+
+Increases the map's zoom level by 1.
+
+
+#### `zoomOut : List (Option { duration : S, easing : S, offset : S, animate : S }) -> Cmd msg`
+
+Decreases the map's zoom level by 1.
+
+#### `rotateTo : List (Option { duration : S, easing : S, offset : S, animate : S }) -> Float -> Cmd msg`
+
+Rotates the map to the specified bearing, with an animated transition. The bearing is the compass direction that is "up"; for example, a bearing of 90° orients the map so that east is up.
+
+#### `jumpTo : List (Option { center : S, zoom : S, bearing : S, pitch : S, around : S }) -> Cmd msg`
+
+Changes any combination of center, zoom, bearing, and pitch, without an animated transition. The map will retain its current values for any details not specified in options.
+
+#### `easeTo : List (Option { ... }) -> Cmd msg`
+
+Changes any combination of center, zoom, bearing, and pitch, with an animated transition between old and new values. The map will retain its current values for any details not specified in options.
+
+Supported options:
+
+- `center`
+- `zoom`
+- `bearing`
+- `pitch`
+- `around`
+- `duration`
+- `easing`
+- `offset`
+- `animate`
+
+#### `flyTo : List (Option { ... }) -> Cmd msg`
+
+Changes any combination of center, zoom, bearing, and pitch, animating the transition along a curve that evokes flight. The animation seamlessly incorporates zooming and panning to help the user maintain her bearings even after traversing a great distance.
+
+Supported options:
+
+- `center`
+- `zoom`
+- `bearing`
+- `pitch`
+- `around`
+- `duration`
+- `easing`
+- `offset`
+- `animate`
+- `curve`
+- `minZoom`
+- `speed`
+- `screenSpeed`
+- `maxDuration`
+
+#### `stop : Cmd msg`
+
+Stops any animated transition underway.
+
+## Fitting bounds
+
+#### `fitBounds : List (Option { ... }) -> ( LngLat, LngLat ) -> Cmd msg`
+
+Pans and zooms the map to contain its visible area within the specified geographical bounds. This function will also reset the map's bearing to 0 if bearing is nonzero.
+
+Supported options:
+
+- `padding`
+- `easing`
+- `linear`
+- `offset`
+- `maxZoom`
+
+
+## Right-to-left
+
+#### `setRTLTextPlugin : String -> Cmd msg`
+
+Sets the map's [RTL text plugin](https://www.mapbox.com/mapbox-gl-js/plugins/#mapbox-gl-rtl-text). Necessary for supporting languages like Arabic and Hebrew that are written right-to-left. Takes a URL pointing to the Mapbox RTL text plugin source.
+
+
+## Querying the map
+
+```
+type Response
+ = GetBounds Int ( LngLat, LngLat )
+ | QueryRenderedFeatures Int (List Value)
+ | Error String
+```
+
+#### `queryResults : (Response -> msg) -> Sub msg`
+
+Receive results from the queries.
+
+
+#### `getBounds : Int -> Cmd msg`
+
+Responds with the map's geographical bounds. Takes a numerical ID that allows you to associate the question with the answer.
+
+### `queryRenderedFeatures : Int -> List (Option { layers : S, filter : S }) -> Query -> Cmd msg`
+
+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).
+
+Each feature includes a top-level layer property whose value is an object representing the style layer to which the feature belongs. Layout and paint properties in this object contain values which are fully evaluated for the given zoom level and feature.
+
+Features from layers whose visibility property is "none", or from layers whose zoom range excludes the current zoom level are not included. Symbol features that have been hidden due to text or icon collision are not included. Features from all other layers are included, including features that may have no visible contribution to the rendered result; for example, because the layer's opacity or color alpha component is set to 0.
+
+The topmost rendered feature appears first in the returned array, and subsequent features are sorted by descending z-order. Features that are rendered multiple times (due to wrapping across the antimeridian at low zoom levels) are returned only once (though subject to the following caveat).
+
+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.
+
+
+```
+type Query
+ = Viewport
+ | Point LngLat
+ | Box LngLat LngLat
+```
+
+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.
diff --git a/elm-package.json b/elm-package.json
index ffcf4d4..3fa2f75 100644
--- a/elm-package.json
+++ b/elm-package.json
@@ -1,18 +1,20 @@
{
"version": "1.0.0",
- "summary": "helpful summary of your project, less than 80 characters",
- "repository": "https://github.com/user/project.git",
- "license": "BSD3",
+ "summary": "An advanced mapping library",
+ "repository": "https://github.com/gampleman/elm-mapbox.git",
+ "license": "MIT",
"source-directories": [
"./src"
],
"exposed-modules": [
"Mapbox.Element",
- "Mapbox.Cmd",
+ "Mapbox.Cmd.Template",
+ "Mapbox.Cmd.Option",
"Mapbox.Style",
"Mapbox.Source",
"Mapbox.Layer",
- "Mapbox.Expression"
+ "Mapbox.Expression",
+ "LngLat"
],
"dependencies": {
"elm-lang/core": "5.1.1 <= v < 6.0.0",
diff --git a/examples/Example01.elm b/examples/Example01.elm
index cac4bf9..8348f84 100644
--- a/examples/Example01.elm
+++ b/examples/Example01.elm
@@ -2,9 +2,9 @@ module Example01 exposing (main)
import Html exposing (div, text)
import Html.Attributes exposing (style)
-import Json.Decode exposing (Value)
-import Json.Encode
+import LngLat exposing (LngLat)
import MapCommands
+import Mapbox.Cmd.Option as Opt
import Mapbox.Element exposing (..)
import Mapbox.Expression as E exposing (false, float, int, str, true)
import Mapbox.Layer as Layer
@@ -22,7 +22,7 @@ main =
init =
- ( { position = ( 0, 0 ), selectedFeatures = [] }, Cmd.none )
+ ( { position = LngLat 0 0 }, Cmd.none )
type Msg
@@ -30,17 +30,13 @@ type Msg
| Click EventData
-mapPair f ( a, b ) =
- ( f a, f b )
-
-
update msg model =
case msg of
- Hover { lngLat, renderedFeatures } ->
- ( { model | position = lngLat, selectedFeatures = renderedFeatures }, Cmd.none )
+ Hover { lngLat } ->
+ ( { model | position = lngLat }, Cmd.none )
Click { lngLat } ->
- ( model, MapCommands.fitBounds [ MapCommands.linear True ] ( mapPair (\a -> a - 0.2) lngLat, mapPair (\a -> a + 0.2) lngLat ) )
+ ( model, MapCommands.fitBounds [ Opt.linear True, Opt.maxZoom 10 ] ( LngLat.map (\a -> a - 0.2) lngLat, LngLat.map (\a -> a + 0.2) lngLat ) )
view model =
@@ -51,9 +47,6 @@ view model =
, onMouseMove Hover
, onClick Click
, id "my-map"
- , model.selectedFeatures
- |> List.map (\f -> ( f, [ ( "hover", Json.Encode.bool True ) ] ))
- |> featureState
]
(Style
{ transition = Style.defaultTransition
@@ -62,7 +55,7 @@ view model =
[ Source.vectorFromUrl "composite" "mapbox://mapbox.mapbox-terrain-v2,mapbox.mapbox-streets-v7,astrosat.07pz1g3y" ]
, misc =
[ Style.name "light"
- , Style.defaultCenter 20.39789404164037 43.22523201923144
+ , Style.defaultCenter <| LngLat 20.39789404164037 43.22523201923144
, Style.defaultZoomLevel 1.5967483759772743
, Style.sprite "mapbox://sprites/astrosat/cjht22eqw0lfc2ro6z0qhlm29"
, Style.glyphs "mapbox://fonts/astrosat/{fontstack}/{range}.pbf"
diff --git a/examples/MapCommands.elm b/examples/MapCommands.elm
index 1670eca..ad6a60c 100644
--- a/examples/MapCommands.elm
+++ b/examples/MapCommands.elm
@@ -1,32 +1,18 @@
-port module MapCommands exposing (id, duration, easing, offset, animate, panBy, panTo, zoomTo, zoomIn, zoomOut, rotateTo, jumpTo, easeTo, flyTo, curve, minZoom, speed, screenSpeed, maxDuration, stop, center, zoom, bearing, pitch, around, fitBounds, padding, linear, maxZoom, setRTLTextPlugin, Response, queryResults, getBounds, queryRenderedFeatures, Query, layers, filter)
+port module MapCommands exposing (id, panBy, panTo, zoomTo, zoomIn, zoomOut, rotateTo, jumpTo, easeTo, flyTo, stop, fitBounds, setRTLTextPlugin, Response, queryResults, getBounds, queryRenderedFeatures, Query)
{-| This module has a bunch of essentially imperative commands for your map.
-@docs Option
-
-
-### Animation options
-
-Options common to map movement commands that involve animation, such as panBy and easeTo, controlling the duration and easing function of the animation. All properties are optional.
-
-@docs duration, easing, offset, animate
+@docs id
### Moving the map around
-@docs panBy, panTo, zoomTo, zoomIn, zoomOut, rotateTo, jumpTo, easeTo, flyTo, curve, minZoom, speed, screenSpeed, maxDuration, stop
-
+@docs panBy, panTo, zoomTo, zoomIn, zoomOut, rotateTo, jumpTo, easeTo, flyTo, stop
-### Camera Options
-Options common to `jumpTo`, `easeTo`, and `flyTo`, controlling the desired location, zoom, bearing, and pitch of the camera. All properties are optional, and when a property is omitted, the current camera value for that property will remain unchanged.
+### Fitting bounds
-@docs center, zoom, bearing, pitch, around
-
-
-### Fiting bounds
-
-@docs fitBounds, padding, Padding, linear, maxZoom
+@docs fitBounds
### Right-to-left
@@ -36,15 +22,13 @@ Options common to `jumpTo`, `easeTo`, and `flyTo`, controlling the desired locat
### Querying the map
-@docs Response, queryResults, getBounds, queryRenderedFeatures, Query, layers, filter
+@docs Response, queryResults, getBounds, queryRenderedFeatures, Query
-}
-import Mapbox.Cmd as Template exposing (Option, Supported)
-import Json.Decode as Decode
+import Mapbox.Cmd.Template as Template exposing (Option, Supported)
import Json.Encode as Encode exposing (Value)
-import Mapbox.Element exposing (LngLat, Viewport)
-import Mapbox.Expression exposing (DataExpression, Expression)
+import LngLat exposing (LngLat)
port elmMapboxOutgoing : Value -> Cmd msg
@@ -57,135 +41,6 @@ id =
"my-map"
-
--- AnimationOptions
-
-
-{-| The animation's duration, measured in milliseconds.
--}
-duration : Int -> Option { a | duration : Supported }
-duration =
- Template.duration
-
-
-{-| The name of an easing function. These must be passed to `elmMapbox`
-in the `easingFunctions` option.
--}
-easing : String -> Option { a | easing : Supported }
-easing =
- Template.easing
-
-
-{-| Offset of the target center relative to real map container center at the end of animation.
--}
-offset : ( Int, Int ) -> Option { a | offset : Supported }
-offset =
- Template.offset
-
-
-{-| If false, no animation will occur.
--}
-animate : Bool -> Option { a | animate : Supported }
-animate =
- Template.animate
-
-
-{-| The desired center.
--}
-center : LngLat -> Option { a | center : Supported }
-center =
- Template.center
-
-
-{-| The desired zoom level.
--}
-zoom : Float -> Option { a | zoom : Supported }
-zoom =
- Template.zoom
-
-
-{-| The desired bearing, in degrees. The bearing is the compass direction that is "up"; for example, a bearing of 90° orients the map so that east is up.
--}
-bearing : Float -> Option { a | bearing : Supported }
-bearing =
- Template.bearing
-
-
-{-| The desired pitch, in degrees.
--}
-pitch : Float -> Option { a | pitch : Supported }
-pitch =
- Template.pitch
-
-
-{-| If `zoom` is specified, `around` determines the point around which the zoom is centered.
--}
-around : LngLat -> Option { a | around : Supported }
-around =
- Template.around
-
-
-{-| The amount of padding in pixels to add to the given bounds.
--}
-padding : Template.Padding -> Option { a | padding : Supported }
-padding =
- Template.padding
-
-
-{-| If true, the map transitions using `easeTo` . If false, the map transitions using `flyTo`.
--}
-linear : Bool -> Option { a | linear : Supported }
-linear =
- Template.linear
-
-
-{-| The maximum zoom level to allow when the map view transitions to the specified bounds.
--}
-maxZoom : Float -> Option { a | maxZoom : Supported }
-maxZoom =
- Template.maxZoom
-
-
-{-| The zooming "curve" that will occur along the flight path.
-A high value maximizes zooming for an exaggerated animation, while a
-low value minimizes zooming for an effect closer to `easeTo`.
-1.42 is the average value selected by participants in the user study discussed in [van Wijk (2003)](https://www.win.tue.nl/~vanwijk/zoompan.pdf).
-A value of `6 ^ 0.25` would be equivalent to the root mean squared average velocity. A value of 1 would produce a circular motion.
--}
-curve : Float -> Option { a | curve : Supported }
-curve =
- Template.curve
-
-
-{-| The zero-based zoom level at the peak of the flight path.
-If `curve` is specified, this option is ignored.
--}
-minZoom : Float -> Option { a | minZoom : Supported }
-minZoom =
- Template.minZoom
-
-
-{-| The average speed of the animation defined in relation to `curve`. A speed of 1.2 means that the map appears to move along the flight path by 1.2 times `curve` screenfuls every second. A screenful is the map's visible span. It does not correspond to a fixed physical distance, but varies by zoom level.
--}
-speed : Float -> Option { a | speed : Supported }
-speed =
- Template.speed
-
-
-{-| The average speed of the animation measured in screenfuls per second, assuming a linear timing curve. If `speed` is specified, this option is ignored.
--}
-screenSpeed : Float -> Option { a | screenSpeed : Supported }
-screenSpeed =
- Template.screenSpeed
-
-
-{-| The animation's maximum duration, measured in milliseconds. If duration exceeds maximum duration, it resets to 0.
--}
-maxDuration : Float -> Option { a | maxDuration : Supported }
-maxDuration =
- Template.maxDuration
-
-
{-| Resizes the map according to the dimensions of its container element.
This command must be sent after the map's container is resized, or when the map is shown after being initially hidden with CSS.
@@ -214,7 +69,7 @@ fitBounds =
Template.fitBounds elmMapboxOutgoing id
-{-| Pans the map by the specified offest.
+{-| Pans the map by the specified offset.
-}
panBy :
List
@@ -427,20 +282,6 @@ queryRenderedFeatures =
Template.queryRenderedFeatures elmMapboxOutgoing id
-{-| A list of style layer IDs for the query to inspect. Only features within these layers will be returned. If this parameter is not set, all layers will be checked.
--}
-layers : List String -> Option { a | layers : Supported }
-layers =
- Template.layers
-
-
-{-| A filter to limit query results.
--}
-filter : Expression DataExpression Bool -> Option { a | filter : Supported }
-filter =
- Template.filter
-
-
{-| A response to the queries. See the relevant methods for more information.
-}
type alias Response =
@@ -450,7 +291,7 @@ type alias Response =
port elmMapboxIncoming : (Value -> msg) -> Sub msg
-{-| Recieve results from the queries
+{-| Receive results from the queries
-}
queryResults : (Response -> msg) -> Sub msg
queryResults =
diff --git a/src/LngLat.elm b/src/LngLat.elm
new file mode 100644
index 0000000..896dc73
--- /dev/null
+++ b/src/LngLat.elm
@@ -0,0 +1,58 @@
+module LngLat exposing (LngLat, encodeAsPair, encodeAsObject, decodeFromPair, decodeFromObject, map)
+
+{-| @docs LngLat, encodeAsPair, encodeAsObject, decodeFromPair, decodeFromObject, map
+-}
+
+import Json.Encode as Encode exposing (Value)
+import Json.Decode as Decode exposing (Decoder)
+
+
+{-| A LngLat represents a geographic position.
+-}
+type alias LngLat =
+ { lng : Float
+ , lat : Float
+ }
+
+
+{-| Most implementations seem to encode these as a 2 member array.
+-}
+encodeAsPair : LngLat -> Value
+encodeAsPair { lng, lat } =
+ Encode.list [ Encode.float lng, Encode.float lat ]
+
+
+{-| Most implementations seem to encode these as a 2 member array.
+-}
+decodeFromPair : Decoder LngLat
+decodeFromPair =
+ Decode.list Decode.float
+ |> Decode.andThen
+ (\l ->
+ case l of
+ [ lng, lat ] ->
+ Decode.succeed (LngLat lng lat)
+
+ _ ->
+ Decode.fail "Doesn't apear to be a valid lng lat pair"
+ )
+
+
+{-| We can also encode as an `{lng: 32, lat: 435}` object.
+-}
+encodeAsObject : LngLat -> Value
+encodeAsObject { lng, lat } =
+ Encode.object [ ( "lng", Encode.float lng ), ( "lat", Encode.float lat ) ]
+
+
+{-| We can also encode from an `{lng: 32, lat: 435}` object.
+-}
+decodeFromObject : Decoder LngLat
+decodeFromObject =
+ Decode.map2 LngLat (Decode.field "lng" Decode.float) (Decode.field "lat" Decode.float)
+
+
+{-| -}
+map : (Float -> Float) -> LngLat -> LngLat
+map f { lng, lat } =
+ { lng = f lng, lat = f lat }
diff --git a/src/Mapbox/Cmd/Internal.elm b/src/Mapbox/Cmd/Internal.elm
new file mode 100644
index 0000000..1445e78
--- /dev/null
+++ b/src/Mapbox/Cmd/Internal.elm
@@ -0,0 +1,14 @@
+module Mapbox.Cmd.Internal exposing (..)
+
+import Json.Encode as Encode exposing (Value)
+
+
+{-| Options use phantom types to show which commands support them.
+-}
+type Option support
+ = Option String Value
+
+
+{-| -}
+type Supported
+ = Supported
diff --git a/src/Mapbox/Cmd/Option.elm b/src/Mapbox/Cmd/Option.elm
new file mode 100644
index 0000000..6157de4
--- /dev/null
+++ b/src/Mapbox/Cmd/Option.elm
@@ -0,0 +1,188 @@
+module Mapbox.Cmd.Option exposing (..)
+
+{-|
+
+
+### Animation options
+
+Options common to map movement commands that involve animation, such as panBy and easeTo, controlling the duration and easing function of the animation. All properties are optional.
+
+@docs duration, easing, offset, animate
+
+@docs curve, minZoom, speed, screenSpeed, maxDuration
+
+
+### Camera Options
+
+Options common to `jumpTo`, `easeTo`, and `flyTo`, controlling the desired location, zoom, bearing, and pitch of the camera. All properties are optional, and when a property is omitted, the current camera value for that property will remain unchanged.
+
+@docs center, zoom, bearing, pitch, around
+
+
+### Fiting bounds
+
+@docs padding, Padding, linear, maxZoom
+
+@docs layers, filter
+
+-}
+
+import Mapbox.Helpers exposing (encodePair)
+import Json.Encode as Encode exposing (Value)
+import Mapbox.Cmd.Internal as Internal exposing (Option(..), Supported)
+import Mapbox.Helpers exposing (encodePair)
+import LngLat exposing (LngLat)
+import Mapbox.Expression exposing (DataExpression, Expression)
+
+
+{-| The animation's duration, measured in milliseconds.
+-}
+duration : Int -> Option { a | duration : Supported }
+duration =
+ Encode.int >> Option "duration"
+
+
+{-| The name of an easing function. These must be passed to `elmMapbox`
+in the `easingFunctions` option.
+-}
+easing : String -> Option { a | easing : Supported }
+easing =
+ Encode.string >> Option "easing"
+
+
+{-| Offset of the target center relative to real map container center at the end of animation.
+-}
+offset : ( Int, Int ) -> Option { a | offset : Supported }
+offset =
+ encodePair Encode.int >> Option "offset"
+
+
+{-| If false, no animation will occur.
+-}
+animate : Bool -> Option { a | animate : Supported }
+animate =
+ Encode.bool >> Option "animate"
+
+
+{-| The desired center.
+-}
+center : LngLat -> Option { a | center : Supported }
+center =
+ LngLat.encodeAsPair >> Option "center"
+
+
+{-| The desired zoom level.
+-}
+zoom : Float -> Option { a | zoom : Supported }
+zoom =
+ Encode.float >> Option "zoom"
+
+
+{-| The desired bearing, in degrees. The bearing is the compass direction that is "up"; for example, a bearing of 90° orients the map so that east is up.
+-}
+bearing : Float -> Option { a | bearing : Supported }
+bearing =
+ Encode.float >> Option "bearing"
+
+
+{-| The desired pitch, in degrees.
+-}
+pitch : Float -> Option { a | pitch : Supported }
+pitch =
+ Encode.float >> Option "pitch"
+
+
+{-| If `zoom` is specified, `around` determines the point around which the zoom is centered.
+-}
+around : LngLat -> Option { a | around : Supported }
+around =
+ LngLat.encodeAsPair >> Option "around"
+
+
+{-| The amount of padding in pixels to add to the given bounds.
+-}
+padding : Padding -> Option { a | padding : Supported }
+padding =
+ encodePadding >> Option "padding"
+
+
+{-| -}
+type alias Padding =
+ { top : Int, right : Int, bottom : Int, left : Int }
+
+
+encodePadding { top, right, bottom, left } =
+ Encode.object
+ [ ( "top", Encode.int top )
+ , ( "right", Encode.int right )
+ , ( "bottom", Encode.int bottom )
+ , ( "left", Encode.int left )
+ ]
+
+
+{-| If true, the map transitions using `easeTo` . If false, the map transitions using `flyTo`.
+-}
+linear : Bool -> Option { a | linear : Supported }
+linear =
+ Encode.bool >> Option "linear"
+
+
+{-| The maximum zoom level to allow when the map view transitions to the specified bounds.
+-}
+maxZoom : Float -> Option { a | maxZoom : Supported }
+maxZoom =
+ Encode.float >> Option "maxZoom"
+
+
+{-| The zooming "curve" that will occur along the flight path.
+A high value maximizes zooming for an exaggerated animation, while a
+low value minimizes zooming for an effect closer to `easeTo`.
+1.42 is the average value selected by participants in the user study discussed in [van Wijk (2003)](https://www.win.tue.nl/~vanwijk/zoompan.pdf).
+A value of `6 ^ 0.25` would be equivalent to the root mean squared average velocity. A value of 1 would produce a circular motion.
+-}
+curve : Float -> Option { a | curve : Supported }
+curve =
+ Encode.float >> Option "curve"
+
+
+{-| The zero-based zoom level at the peak of the flight path.
+If `curve` is specified, this option is ignored.
+-}
+minZoom : Float -> Option { a | minZoom : Supported }
+minZoom =
+ Encode.float >> Option "minZoom"
+
+
+{-| The average speed of the animation defined in relation to `curve`. A speed of 1.2 means that the map appears to move along the flight path by 1.2 times `curve` screenfuls every second. A screenful is the map's visible span. It does not correspond to a fixed physical distance, but varies by zoom level.
+-}
+speed : Float -> Option { a | speed : Supported }
+speed =
+ Encode.float >> Option "speed"
+
+
+{-| The average speed of the animation measured in screenfuls per second, assuming a linear timing curve. If `speed` is specified, this option is ignored.
+-}
+screenSpeed : Float -> Option { a | screenSpeed : Supported }
+screenSpeed =
+ Encode.float >> Option "screenSpeed"
+
+
+{-| The animation's maximum duration, measured in milliseconds. If duration exceeds maximum duration, it resets to 0.
+-}
+maxDuration : Float -> Option { a | maxDuration : Supported }
+maxDuration =
+ Encode.float >> Option "maxDuration"
+
+
+{-| A list of style layer IDs for the query to inspect. Only features within these layers will be returned. If this parameter is not set, all layers will be checked.
+-}
+layers : List String -> Option { a | layers : Supported }
+layers =
+ List.map Encode.string >> Encode.list >> Option "layers"
+
+
+{-| A filter to limit query results.
+-}
+filter : Expression DataExpression Bool -> Option { a | filter : Supported }
+filter =
+ Mapbox.Expression.encode >> Option "filter"
diff --git a/src/Mapbox/Cmd.elm b/src/Mapbox/Cmd/Template.elm
index 17cea13..d0f306e 100644
--- a/src/Mapbox/Cmd.elm
+++ b/src/Mapbox/Cmd/Template.elm
@@ -1,36 +1,22 @@
-module Mapbox.Cmd exposing (Id, Outgoing, Option, Supported, duration, easing, offset, animate, panBy, panTo, zoomTo, zoomIn, zoomOut, rotateTo, jumpTo, easeTo, flyTo, curve, minZoom, speed, screenSpeed, maxDuration, stop, center, zoom, bearing, pitch, around, fitBounds, padding, Padding, linear, maxZoom, setRTLTextPlugin, Response, queryResults, getBounds, queryRenderedFeatures, Query, layers, filter, resize)
+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)
{-| This module has a bunch of essentially imperative commands for your map.
-@docs Id, Outgoing
+However, since a published library can't have ports in it, you will need to do some setup. The easiest way to do this is to copy [this file into your app](https://github.com/gampleman/elm-mapbox/blob/master/examples/MapCommands.elm). You can see the module docs for that [here](https://github.com/gampleman/elm-mapbox/blob/master/docs/MapCommands.md).
-However, since a published library can't have ports in it, you will need to do some setup. The easiest way to do this is to copy [this file into your app](https://github.com/gampleman/elm-mapbox/blob/master/examples/MapCommands.elm).
+@docs Id, Outgoing, Option, Supported
-@docs Option, Supported
-
-
-### Animation options
-
-Options common to map movement commands that involve animation, such as panBy and easeTo, controlling the duration and easing function of the animation. All properties are optional.
-
-@docs duration, easing, offset, animate
+You can of course customize the module you copy into your codebase to support things like having multiple maps on the page at once, etc.
### Moving the map around
-@docs panBy, panTo, zoomTo, zoomIn, zoomOut, rotateTo, jumpTo, easeTo, flyTo, curve, minZoom, speed, screenSpeed, maxDuration, stop
-
-
-### Camera Options
-
-Options common to `jumpTo`, `easeTo`, and `flyTo`, controlling the desired location, zoom, bearing, and pitch of the camera. All properties are optional, and when a property is omitted, the current camera value for that property will remain unchanged.
-
-@docs center, zoom, bearing, pitch, around
+@docs panBy, panTo, zoomTo, zoomIn, zoomOut, rotateTo, jumpTo, easeTo, flyTo, stop
### Fiting bounds
-@docs fitBounds, padding, Padding, linear, maxZoom
+@docs fitBounds
### Other