diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/Example01.elm | 21 | ||||
-rw-r--r-- | examples/MapCommands.elm | 179 |
2 files changed, 17 insertions, 183 deletions
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 = |