This library wraps a Custom Element that actually renders a map.
map : List (MapboxAttr msg) -> Mapbox.Style.Style -> Html msg
A Map html element renders a map based on a Style.
css : Html msg
This is literally:
<link
href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.53.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.
This is the type that all attributes have.
token : String -> MapboxAttr msg
Your Mapbox API Token.
id : String -> MapboxAttr msg
The element's Id. This should be unique. You will need this if you want to use the Mapbox.Cmd module.
maxZoom : Basics.Float -> MapboxAttr msg
The maximum zoom level of the map (0-24). Default 22.
minZoom : Basics.Float -> MapboxAttr msg
The minimum zoom level of the map (0-24).
maxBounds : ( LngLat, LngLat ) -> MapboxAttr msg
If set, the map will be constrained to the given bounds. The bounds are the (south-west corner, north-east corner)
.
renderWorldCopies : Basics.Bool -> MapboxAttr msg
If true, multiple copies of the world will be rendered, when zoomed out.
featureState : List ( Json.Decode.Value, List ( String, Json.Decode.Value ) ) -> MapboxAttr msg
Sometimes you need to give certain geographic features some state.
The most common is user interaction states like hover, selected, etc.
The feature here is accepted as a Value
. This is partially due to its flexibility, but in order for this to work, this must be an object with the following top-level propreties:
source
sourceLayer
(only for vector sources)id
the feature's unique id (this must be a positive, non-zero integer).You can get these Value
s from event listeners and pass them straight through. The state is a list of (key, value)
pairs.
You can use this state infromation through the Mapbox.Expression.featureState
expression.
Layer.fillOpacity <|
E.ifElse
(E.toBool (E.featureState (str "hover")))
(float 0.9)
(float 0.1)
Note that this attribute is quite awkward to use directly. I recommend defining some helpers that suite your situation. For example:
hoveredFeature : Value -> MapboxAttr msg
hoveredFeature feat =
Element.featureState [ ( feat, [ ( "hover", Json.Encode.bool True ) ] ) ]
or
dataJoins : List (Int, Float) -> MapboxAttr msg
dataJoins =
List.map (\(id, population) ->
(Json.Encode.object
[( "source", Json.Encode.string "postcodes")
, ("id", Json.Encode.int id)
]
, [ ("population", Json.Encode.float population)]
)
>> Element.featureState
This will make your view code much neater, by not mixing in JSON encoding directly.
{ point : ( Basics.Int
, Basics.Int )
, lngLat : LngLat
, renderedFeatures : List Json.Decode.Value
}
point
is the coordinates in pixels in screen space.
lngLat
is the coordinates as a longitude, latitude in geographic space.
renderedFeatures
is a geojson that intersect the lngLat
:
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.
{ touches : List EventData
, center : EventData
}
touches
will list stuff for every finger involved in a gesture.
center
refers to the point in the geometric center of touches
.
eventFeaturesFilter : Mapbox.Expression.Expression Mapbox.Expression.DataExpression Basics.Bool -> MapboxAttr msg
By default the renderedFeatures
property in events will return
a lot of data. If you don't need it, you can provide a filter to filter that data. This will make things more performant.
eventFeaturesLayers : List String -> MapboxAttr msg
By default the renderedFeatures
property in events will return
a lot of data. Here you can specify which layers you want to search for intersections. If you don't care about intersecting data at all, you can optimize performance by passing an empty list to this attribute.
onMouseDown : (EventData -> msg) -> MapboxAttr msg
Fired when a pointing device (usually a mouse) is pressed within the map.
onMouseUp : (EventData -> msg) -> MapboxAttr msg
Fired when a pointing device (usually a mouse) is released within the map.
onMouseOver : (EventData -> msg) -> MapboxAttr msg
Fired when a pointing device (usually a mouse) is moved within the map.
onMouseMove : (EventData -> msg) -> MapboxAttr msg
Fired when a pointing device (usually a mouse) is moved within the map.
onClick : (EventData -> msg) -> MapboxAttr msg
Fired when a pointing device (usually a mouse) is pressed and released at the same point on the map.
onDblClick : (EventData -> msg) -> MapboxAttr msg
Fired when a pointing device (usually a mouse) is clicked twice at the same point on the map.
onMouseOut : (EventData -> msg) -> MapboxAttr msg
Fired when a point device (usually a mouse) leaves the map's canvas.
onContextMenu : (EventData -> msg) -> MapboxAttr msg
Fired when the right button of the mouse is clicked or the context menu key is pressed within the map.
onZoom : (EventData -> msg) -> MapboxAttr msg
Fired repeatedly during an animated transition from one zoom level to another.
onZoomStart : (EventData -> msg) -> MapboxAttr msg
Fired just before the map begins a transition from one zoom level to another.
onZoomEnd : (EventData -> msg) -> MapboxAttr msg
Fired just after the map completes a transition from one zoom level to another.
onRotate : (EventData -> msg) -> MapboxAttr msg
Fired repeatedly during a "drag to rotate" interaction.
onRotateStart : (EventData -> msg) -> MapboxAttr msg
Fired when a "drag to rotate" interaction starts.
onRotateEnd : (EventData -> msg) -> MapboxAttr msg
Fired when a "drag to rotate" interaction ends.
onTouchEnd : (TouchEvent -> msg) -> MapboxAttr msg
Fired when a touchend event occurs within the map.
onTouchMove : (TouchEvent -> msg) -> MapboxAttr msg
Fired when a touchmove event occurs within the map.
onTouchCancel : (TouchEvent -> msg) -> MapboxAttr msg
Fired when a touchcancel event occurs within the map.
on : String -> Json.Decode.Decoder msg -> MapboxAttr msg
This allows you to use other events not provided by this libary, or decode more or different data.
See https://www.mapbox.com/mapbox-gl-js/api/#map.event for all supported events.