Sources

The source types FATOS GL JS can handle in addition to the ones described in th FATOS Style Specification

setSource

Adds a source to the map's style.

map.setSource(id, geoJson, cluster, maxZoom, radius)

Parameter

Required ParameterDescriptionType

id

The ID of the source to add. Must not conflict with existing sources.

String

geoJson

A source containing GeoJSON.

Object

Optional ParameterDescriptionType

cluster

Cluster enabled or disabled

Boolean

maxZoom

Max zoom to cluster points on (defaults to 14)

Numeric

radius

Radius of each cluster when clustering points

Int

Example

map.setSource('some id', {
    "type": "FeatureCollection",
    "features": [{
            "type": "Feature",
            "properties": {},
            "geometry": {
                "type": "Point",
                "coordinates": [ 126.896038, 37.482901]
            }
        }]
    },
    //If you want to use the cluster
    true, //cluster
    15,  // maxZoom to cluster
    50  // radius 
);

getSource

Returns the source with the specified ID in the map's style.

Parameter

Required ParameterDescriptionType

id

The ID of the source to get.

String

Returns

Object : The style source with the specified ID or undefined if the ID corresponds to no existing sources.

Example

const getSourceObj = map.getSource('some id');

setData

Sets the GeoJSON data and re-renders the map.

map.getSource('some id').setData(data);

Parameter

Required ParameterDescriptionType

data

A GeoJSON data object or a URL to one. The latter is preferable in the case of large GeoJSON files.

Object | string

Example

map.getSource('some id').setData({
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "properties": {},
        "geometry": {
            "type": "Point",
            "coordinates": [ 126.896038, 37.482901]
        }
    }]
});

isSourceLoaded

Returns a Boolean indicating whether the source is loaded. Returns true if the source with the given ID in the map's style has no outstanding network requests, otherwise false.

const sourceLoaded = map.isSourceLoaded('some id');

Parameter

Required ParameterDescriptionType

id

The ID of the source to be checked.

String

Returns

boolean : A Boolean indicating whether the source is loaded.

Example

const sourceloaded = map.isSourceLoaded('some id');

removeSource

Removes a source from the map's style.

Parameter

Required ParameterDescriptionType

id

The ID of the source to remove.

String

Returns

Map : Returns itself to allow for method chaining.

Example

map.removeSource('some id');

Last updated