aboutsummaryrefslogtreecommitdiffstats
path: root/src/Mapbox/Cmd.elm
diff options
context:
space:
mode:
authorJakub Hampl <kopomir@gmail.com>2018-06-20 15:56:35 +0100
committerJakub Hampl <kopomir@gmail.com>2018-06-20 15:56:35 +0100
commit7eb8f3ea42fb1399bc9960697e9f6439fe5ec6cb (patch)
tree183cbf84ab1383ba11f9502f30db1270ffdd25cd /src/Mapbox/Cmd.elm
parent42d12f835708b15f6730cf0f3fdf6072de1e3002 (diff)
Add basic Command module
Diffstat (limited to 'src/Mapbox/Cmd.elm')
-rw-r--r--src/Mapbox/Cmd.elm58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/Mapbox/Cmd.elm b/src/Mapbox/Cmd.elm
new file mode 100644
index 0000000..510c627
--- /dev/null
+++ b/src/Mapbox/Cmd.elm
@@ -0,0 +1,58 @@
+module Mapbox.Cmd exposing (..)
+
+{-| This module has a bunch of essentially imperative commands for your map.
+
+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 paste the following code into your app:
+
+ import Json.Decode exposing (Value)
+ import Mapbox.Cmd as Cmd
+
+ port elmMapboxOutgoing : Value -> Cmd msg
+
+ port elmMapboxIncoming : (Cmd.Response -> msg) -> Sub msg
+
+ mapId =
+ {- this is whatever the `id` attribute on your map is -}
+ "my-map"
+
+ flyTo =
+ Cmd.flyTo elmMapboxOutgoing mapId
+
+-}
+
+import Json.Encode as Encode exposing (Value)
+import Mapbox.Element exposing (LngLat, Viewport)
+
+
+type alias Outgoing msg =
+ Value -> Cmd msg
+
+
+type alias Id =
+ String
+
+
+encodePair encoder ( a, b ) =
+ Encode.list [ encoder a, encoder b ]
+
+
+fitBounds : Outgoing msg -> Id -> ( LngLat, LngLat ) -> Cmd msg
+fitBounds prt id bounds =
+ prt <|
+ Encode.object
+ [ ( "command", Encode.string "fitBounds" )
+ , ( "target", Encode.string id )
+ , ( "bounds", encodePair (encodePair Encode.float) bounds )
+ ]
+
+
+
+--
+--
+-- flyTo : Outgoing msg -> Id -> Viewport -> { curve : Float } -> Cmd msg
+-- flyTo prt id desiredViewport options =
+-- prt <|
+-- Encode.object
+-- [ ( "command", Encode.string "flyTo" )
+-- , ( "target", Encode.string id )
+-- ]