gampleman / elm-mapbox / Mapbox.Source

Sources


type Source

Sources supply data to be shown on the map. Adding a source won't immediately make data appear on the map because sources don't contain styling details like color or width. Layers refer to a source and give it a visual representation. This makes it possible to style the same source in different ways, like differentiating between types of roads in a highways layer.


type SourceOption sourceType

Some sources can take options.


type alias Id =
String

Every layer is identified by an id.


type alias Url =
String

Represents a URL. For tiles hosted by Mapbox, the "url" value should be of the form mapbox://mapid.

Vector

vector : Id -> List Url -> List (SourceOption VectorSource) -> Source

A vector tile source. Tiles must be in Mapbox Vector Tile format. All geometric coordinates in vector tiles must be between -1 * extent and (extent * 2) - 1 inclusive. All layers that use a vector source must specify a sourceLayer value.

This takes an array of one or more tile source URLs, as in the TileJSON spec.

vectorFromUrl : Id -> Url -> Source

A vector tile source. Tiles must be in Mapbox Vector Tile format. All geometric coordinates in vector tiles must be between -1 * extent and (extent * 2) - 1 inclusive. All layers that use a vector source must specify a sourceLayer value.

The first argument is the layers id, the second is a url to a TileJSON specification that configures the source.


type VectorSource

Marks attributes that are only applicable to vector sources

Raster

raster : Id -> List Url -> List (SourceOption RasterSource) -> Source

A raster tile source. Takes a list of one or more tile source URLs, as in the TileJSON spec.

tileSize : Basics.Int -> SourceOption RasterSource

The minimum visual size to display tiles for this layer.

rasterFromUrl : Id -> Url -> Source

A raster tile source configured from a TileJSON spec.


type RasterSource

Marks attributes that are only applicable to raster sources

Raster DEM

rasterDEMMapbox : Id -> Source

The Mapbox Terrain RGB DEM source.

rasterDEMTerrarium : Id -> Url -> List (SourceOption RasterSource) -> Source

A raster DEM source in the Terarrium format.

GeoJSON

geoJSONFromUrl : Id -> Url -> List (SourceOption GeoJSONSource) -> Source

A remote GeoJSON source.

geoJSONFromValue : Id -> List (SourceOption GeoJSONSource) -> Json.Encode.Value -> Source

A GeoJSON source from some local data.


type GeoJSONSource

Marks attributes that are only applicable to GeoJSON sources

buffer : Basics.Int -> SourceOption GeoJSONSource

Size of the tile buffer on each side. A value of 0 produces no buffer. A value of 512 produces a buffer as wide as the tile itself. Larger values produce fewer rendering artifacts near tile edges and slower performance. Defaults to 128.

tolerance : Basics.Float -> SourceOption GeoJSONSource

Douglas-Peucker simplification tolerance (higher means simpler geometries and faster performance). Defaults to 0.375.

cluster : SourceOption GeoJSONSource

If the data is a collection of point features, setting this clusters the points by radius into groups.

Cluster groups become new Point features in the source with additional properties:

clusterRadius : Basics.Float -> SourceOption GeoJSONSource

Radius of each cluster if clustering is enabled. A value of 512 indicates a radius equal to the width of a tile.

clusterProperties : List ( String, Mapbox.Expression.Expression Mapbox.Expression.DataExpression a -> Mapbox.Expression.Expression Mapbox.Expression.DataExpression b -> Mapbox.Expression.Expression Mapbox.Expression.DataExpression b, Mapbox.Expression.Expression Mapbox.Expression.DataExpression a ) -> SourceOption GeoJSONSource

When clustering, you may want to aggregate values from the points included in the cluster. This function allows you to associate a name that will be the property name with a fold that computes the aggregation. For example:

clusterProperties
    [ ( "sum", E.plus, E.getProperty (str "scalerank") )
    , ( "max", \point aggregate -> E.max aggregate point, E.getProperty (str "scalerank") )
    ]

Would produce clusters with two additional properties: sum and max, which you could then further use in data driven styling.

lineMetrics : Basics.Bool -> SourceOption GeoJSONSource

Whether to calculate line distance metrics. This is required for line layers that specify lineGradient values.

generateIds : SourceOption GeoJSONSource

When set, the feature.id property will be auto assigned based on its index in the features array, over-writing any previous values.

Image, Video & Canvas


type alias Coords =
{ topLeft : LngLat
, topRight : LngLat
, bottomRight : LngLat
, bottomLeft : LngLat 
}

(longitude, latitude) pairs for the corners. You can use the type alias constructor in clockwise order: top left, top right, bottom right, bottom left.

image : Id -> Url -> Coords -> Source

An image source

video : Id -> List Url -> Coords -> Source

A video source. For each URL in the list, a video element source will be created, in order to support same media in multiple formats supported by different browsers.

staticCanvas : Id -> String -> Coords -> Source

A data source containing the contents of an HTML canvas. The second argument must be the DOM ID of the canvas element. This method is only appropriate with a static Canvas (i.e. one that doesn't change), as it will be cached to improve performance.

animatedCanvas : Id -> String -> Coords -> Source

A data source containing the contents of an HTML canvas. The second argument must be the DOM ID of the canvas element. This method is only appropriate with an animated Canvas (i.e. one that changes over time).

Tiled sources

Tiled sources can also take the following attributes:

bounds : LngLat -> LngLat -> SourceOption any

The longitude and latitude of the southwest and northeast corners of the source's bounding box. When this property is included in a source, no tiles outside of the given bounds are requested by Mapbox GL.

minzoom : Basics.Float -> SourceOption any

Minimum zoom level for which tiles are available, as in the TileJSON spec.

maxzoom : Basics.Float -> SourceOption any

Maximum zoom level for which tiles are available, as in the TileJSON spec. Data from tiles at the maxzoom are used when displaying the map at higher zoom levels.

attribution : String -> SourceOption any

Contains an attribution to be displayed when the map is shown to a user.

scheme : Scheme -> SourceOption any

Influences the y direction of the tile coordinates. The global-mercator (aka Spherical Mercator) profile is assumed.


type Scheme
    = XYZ
    | TMS

XYZ: Slippy map tilenames scheme.

TMS: OSGeo spec scheme.

Working with sources

encode : Source -> Json.Encode.Value

getId : Source -> String