DataSource class

A data source class that makes it easy to manage shapes data that will be displayed on the map. A data source must be added to a layer before it is visible on the map. The DataSource class may be used with the SymbolLayer, LineLayer, PolygonLayer, BubbleLayer, and HeatMapLayer.

Extends

Constructors

DataSource(string, DataSourceOptions)

A data source class that makes it easy to manage shapes data that will be displayed on the map. A data source must be added to a layer before it is visible on the map. The DataSource class may be used with the SymbolLayer, LineLayer, PolygonLayer, BubbleLayer, and HeatMapLayer.

Methods

add(FeatureCollection | Feature<atlas.data.Geometry, any> | atlas.data.Geometry | GeometryCollection | Shape | Array<Feature<atlas.data.Geometry, any> | atlas.data.Geometry | Shape>, number)

Adds shapes to the data source. GeoJSON objects will be wrapped within a Shape class to make them easier to manage. Optionally specify an index to insert the feature between other shapes/features in the layers.

clear()

Removes all data in the data source.

dispose()

Cleans up any resources this object is consuming.

getClusterChildren(number)

Retrieves the children of the given cluster on the next zoom level. This may be a combination of shapes and sub-clusters. The sub-clusters will be features with properties matching ClusteredProperties.

getClusterExpansionZoom(number)

Calculates a zoom level at which the cluster will start expanding or break apart.

getClusterLeaves(number, number, number)

Retrieves shapes that are within the cluster.

getOptions()

Gets the options used by the data source.

getShapeById(string | number)

Retrieves a shape with the specified id. If no shape with the specified id is contained in the data source, null will be return.

getShapes()

Returns all shapes that are in the DataSource.

importDataFromUrl(string)

Downloads a GeoJSON document and imports its data into the data source. The GeoJSON document must be on the same domain or accessible using CORS.

remove(number | string | Shape | Feature<atlas.data.Geometry, any> | Array<number | string | Shape | Feature<atlas.data.Geometry, any>>)

Removes one or more shapes from the data source. If a string is passed in, it is assumed to be an id. If a number is passed in, removes the shape at that index.

removeById(number | string | Array<number | string>)

Removes one or more shapes from the datasource based on its id.

setOptions(DataSourceOptions)

Sets the data source options. The data source will retain its current values for any option not specified in the supplied options.

setShapes(FeatureCollection | Array<Feature<atlas.data.Geometry, any> | atlas.data.Geometry | Shape>)

Overwrites all shapes in the data source with the new array of shapes.

toJson()

Returns a GeoJSON FeatureCollection which contains all the shape data that is in the data source.

Inherited Methods

getId()

Gets the id of the data source

Constructor Details

DataSource(string, DataSourceOptions)

A data source class that makes it easy to manage shapes data that will be displayed on the map. A data source must be added to a layer before it is visible on the map. The DataSource class may be used with the SymbolLayer, LineLayer, PolygonLayer, BubbleLayer, and HeatMapLayer.

new DataSource(id?: string, options?: DataSourceOptions)

Parameters

id

string

a unique id that the user assigns to the data source. If this is not specified, then the data source will automatically be assigned an id.

options
DataSourceOptions

the options for the data source.

Method Details

add(FeatureCollection | Feature<atlas.data.Geometry, any> | atlas.data.Geometry | GeometryCollection | Shape | Array<Feature<atlas.data.Geometry, any> | atlas.data.Geometry | Shape>, number)

Adds shapes to the data source. GeoJSON objects will be wrapped within a Shape class to make them easier to manage. Optionally specify an index to insert the feature between other shapes/features in the layers.

function add(data: FeatureCollection | Feature<atlas.data.Geometry, any> | atlas.data.Geometry | GeometryCollection | Shape | Array<Feature<atlas.data.Geometry, any> | atlas.data.Geometry | Shape>, index?: number)

Parameters

index

number

clear()

Removes all data in the data source.

function clear()

dispose()

Cleans up any resources this object is consuming.

function dispose()

getClusterChildren(number)

Retrieves the children of the given cluster on the next zoom level. This may be a combination of shapes and sub-clusters. The sub-clusters will be features with properties matching ClusteredProperties.

function getClusterChildren(clusterId: number): Promise<Array<Feature<atlas.data.Geometry, ClusteredProperties | any> | Shape>>

Parameters

clusterId

number

Returns

Promise<Array<Feature<Geometry, ClusteredProperties | any> | Shape>>

getClusterExpansionZoom(number)

Calculates a zoom level at which the cluster will start expanding or break apart.

function getClusterExpansionZoom(clusterId: number): Promise<number>

Parameters

clusterId

number

Returns

Promise<number>

getClusterLeaves(number, number, number)

Retrieves shapes that are within the cluster.

function getClusterLeaves(clusterId: number, limit: number, offset: number): Promise<Array<Feature<atlas.data.Geometry, any> | Shape>>

Parameters

clusterId

number

limit

number

The maximum number of features to return. Set to Infinity to return all shapes.

offset

number

The number of shapes to skip. Allows you to page through the shapes in the cluster.

Returns

Promise<Array<Feature<Geometry, any> | Shape>>

getOptions()

Gets the options used by the data source.

function getOptions(): DataSourceOptions

Returns

getShapeById(string | number)

Retrieves a shape with the specified id. If no shape with the specified id is contained in the data source, null will be return.

function getShapeById(id: string | number): Shape

Parameters

id

string | number

The id of the shape to return.

Returns

getShapes()

Returns all shapes that are in the DataSource.

function getShapes(): Shape[]

Returns

Shape[]

importDataFromUrl(string)

Downloads a GeoJSON document and imports its data into the data source. The GeoJSON document must be on the same domain or accessible using CORS.

function importDataFromUrl(url: string): Promise<void>

Parameters

url

string

Returns

Promise<void>

remove(number | string | Shape | Feature<atlas.data.Geometry, any> | Array<number | string | Shape | Feature<atlas.data.Geometry, any>>)

Removes one or more shapes from the data source. If a string is passed in, it is assumed to be an id. If a number is passed in, removes the shape at that index.

function remove(shape: number | string | Shape | Feature<atlas.data.Geometry, any> | Array<number | string | Shape | Feature<atlas.data.Geometry, any>>)

Parameters

shape

number | string | Shape | Feature<Geometry, any> | Array<number | string | Shape | Feature<Geometry, any>>

The shape(s), shape id(s), or feature(s) to be removed

removeById(number | string | Array<number | string>)

Removes one or more shapes from the datasource based on its id.

function removeById(id: number | string | Array<number | string>)

Parameters

id

number | string | Array<number | string>

setOptions(DataSourceOptions)

Sets the data source options. The data source will retain its current values for any option not specified in the supplied options.

function setOptions(options: DataSourceOptions)

Parameters

options
DataSourceOptions

the DataSourceOptions to be set

setShapes(FeatureCollection | Array<Feature<atlas.data.Geometry, any> | atlas.data.Geometry | Shape>)

Overwrites all shapes in the data source with the new array of shapes.

function setShapes(shape: FeatureCollection | Array<Feature<atlas.data.Geometry, any> | atlas.data.Geometry | Shape>)

Parameters

shape

FeatureCollection | Array<Feature<Geometry, any> | Geometry | Shape>

the new shapes to update

toJson()

Returns a GeoJSON FeatureCollection which contains all the shape data that is in the data source.

function toJson(): FeatureCollection

Returns

Inherited Method Details

getId()

Gets the id of the data source

function getId(): string

Returns

string

Inherited From Source.getId