Layers
Layers are responsible for rendering data associated with a data source based on a particular style configuration. There are two primary components to a layer: the source that provides the data to render and a layer style that determines how that data gets rendered on a map.
Currently, all layers within MapsGL are TileLayer
subclasses.
Layer Types
Layer type
values specify how data gets rendered on a map and aren't directly mapped to paint style properties as multiple style properties may be used for a single layer type. For example, a fill
layer type will only use the fill
style properties, but a circle
layer type will use the circle
, fill
, and stroke
style properties. However, all layer types will use the root-level opacity
style property to control the layer's overall transparency.
Review our advanced section on layers for more information and examples on setting up and using custom layers.
The following layer types and their respective paint style properties are supported:
raster
Basic raster tile images and textures. Uses raster
style properties.
fill
Filled and/or stroked vector polygons. Uses fill
and stroke
style properties.
line
Stroked vector lines. Uses stroke
style properties.
circle
Filled and/or stroked vector circles. Uses circle
, fill
, and stroke
style properties.
symbol
SDF (signed distance field) icons, image icons, or quads rendered with custom WebGL shaders. Uses symbol
style properties.
sample
Colorized encoded raster tile data. Uses sample
style properties.
grid
Symbols rendered on a grid. Uses grid
and sample
style properties.
heatmap
Heatmap rendering of point data. Uses heatmap
style properties.
contour
Contour lines from raster data. Uses contour
and sample
style properties.
particles
Flow field particles from raster vector data. Uses particle
and sample
style properties.
text
Text labels. Uses text
and symbol
style properties.
query
Queries features from another layer using a set of map coordinates and renders that data as text, symbol, or circle features. Uses style properties associated with text
, symbol
, or circle
layer types. Requires a valid value for queryLayer
to specify the layer to query features from. Also requires a vector
or geojson
data source of point features to use as the locations to query.
composite
Combines multiple layers into a single layer alias. Uses style properties associated with the layer types for each of the layers being combined. When adding composite layers via addWeatherLayer
, the return type will always be an array of individual layers associated with the composite layer that were added to the map.
Layer
The base class for all layers on a map.
Configuration
{
type: LayerType;
source: string | SourceSpecification | DataSource;
sourceLayer?: string;
sourceType?: SourceType;
queryLayer?: string | { id: string; hidden?: boolean; };
queryType?: 'text' | 'symbol' | 'circle';
mask?: string | { id: string; invert?: boolean; };
filter?: ExpressionSpecification;
timeSeries?: {
mode: 'none' | 'any' | 'interval';
clamp: 'none' | 'past' | 'future' | 'range';
range?: {
start: Date;
end: Date;
};
intervals: number;
interleaved: boolean;
};
paint: Partial<PaintStyleSpec>;
}
The following configuration options are supported when instantiating Layer
instances and subclasses:
Option | Description | Default |
---|---|---|
type | Type: raster | circle | symbol | fill | line | sample | grid | heatmap | contour | particles (required)The type of rendering method to use for the layer. See the list of available layer styles for examples of each type. |
|
source | Type: string (required)The identifier of the data source to be used for the layer. |
|
sourceLayer | Type: string ()Layer name to use from a vector tile data source that corresponds to the features to render for the layer. |
|
sourceType | Type: point | line | polygon | symbol ()The feature type to use from the sourceLayer when using a vector tile data source. |
|
queryLayer | Type: string | { id: string; hidden?: boolean; } ()The identifier of the layer to query features from when using a query layer type. If the queried layer should be hidden, then set the hidden property to true . |
|
queryType | Type: text | symbol | circle ()The type of feature to render when using a query layer type. |
|
mask | Type: string | { id: string; invert?: boolean; } ()The identifier of the layer to use as a mask for the layer. If the mask should be inverted, then set the invert property to true . |
|
filter | Type: ExpressionSpecification ()Filter expression to use for filtering features from the data source. This is only used for vector data sources in GeoJSON or Mapbox Vector Tile (MVT) format. See the documentation on filtering data for more information and examples. |
|
timeSeries.mode | Type: none | any | interval ()Controls how a time-based layer is rendered relative to the timeline associated with the parent MapController : - none : layer is not time-specific and should be displayed at any time- any : layer is time-specific but can be displayed at any time- interval : layer is time-specific and should be displayed at valid time intervals as defined by the data source |
|
timeSeries.clamp | Type: none | past | future | range ()Defines how to restrict the visibility of a time-specific layer: - none : layer can be displayed at any time- past : layer can only be displayed for past time intervals- future : layer can only be displayed for future time intervals- range : layer can only be displayed within a specific time range as defined by timeSeries.range |
|
timeSeries.range | Type: { start: Date; end: Date; } ()For time-based layers, defines the valid start and end date range for the layer. When provided, the layer will automatically be hidden outside of this date range. |
|
timeSeries.intervals | Type: number ()Maximum number of time intervals to use for the data set. | `` |
timeSeries.interleaved | Type: boolean ()Whether data requests for the layer's animation intervals should be interleaved. |
|
paint | Type: PaintStyleSpec (required)Style configuration for the layer. See the list of available layer styles and their properties. Also, review the mapping of layer type values to the supported paint style options for that type. |
|
Properties
The following properties are available on Layer
instances and subclasses:
Option | Description | Default |
---|---|---|
style | Type: PaintStyle ()Paint style configuration associated with the layer. |
|
visible | Type: boolean (read-only)Whether the layer is currently visible. To change the visibility of a layer, use the show() and hide() methods. |
|
enabled | Type: boolean ()Whether the layer is enabled. |
|
metadata | Type: Record<string, any> (read-only)Returns metadata information about the layer, such as its identifier, type, source, filters and paint style. |
|
renderer | Type: LayerRenderer (read-only)Layer style renderer associated with the layer as determined by the layer's configured type . |
|
animator | Type: TimeSeriesAnimator (optional)Manages time series data and requests associated with a time-based data source and layer. If the layer is not time-based, then undefined will be returned. |
|
isDirty | Type: boolean (read-only)Returns whether the layer has been flagged as dirty, indicating it will be updated during the next rendered frame. |
|
Methods
show()
hide()
refresh(clear: boolean)
setPaintProperty(property: string, value: any)
setNeedsUpdate()
queryFeatures(coord: { lat: number; lon: number; }, zoom: number): number | Record<string, any> | Array<any>
queryFeaturesPromise(coord: { lat: number; lon: number; }, zoom: number): Promise<FeatureQueryResult | void>
dispose()
Tile Layer
A layer that renders raster, encoded or vector tiles on a map. Extends Layer
.
Configuration
// Inherits all configuration options from `Layer`
{
quality: DataQuality;
}
The following configuration options are supported when instantiating TileLayer
instances:
Option | Description | Default |
---|---|---|
quality | Type: exact ()xxxxxx |
|
Properties
The following properties are available on TileLayer
instances and subclasses:
Option | Description | Default |
---|---|---|
quality | Type: DataQuality ()Data resolution to use, which controls which data zoom level is requested for a specific map zoom level.Using a lower data quality value will reduce the amount of data needed for the visible map region but also result is lower data resolution. Using a higher quality value will provide the most accurate result and highest data resolution but also increase the amount of data required. A lower quality value is useful in environments where resource limitations exist, such as mobile devices or less capable hardware. |
|
Methods
getDataZoom(zoom: number): number