1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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 )
-- ]
|