src/api/v4/layer/layer.js
function Layer (source, style, options = {}) {
  Base.apply(this, arguments);

  _checkSource(source);
  _checkStyle(style);

  this._client = undefined;
  this._engine = undefined;
  this._internalModel = undefined;

  this._source = source;
  this._style = style;
  this._visible = _.isBoolean(options.visible) ? options.visible : true;
  this._featureClickColumns = options.featureClickColumns || [];
  this._featureOverColumns = options.featureOverColumns || [];
  this._minzoom = options.minzoom || 0;
  this._maxzoom = options.maxzoom || undefined;
  this._aggregation = options.aggregation || {};

  _validateAggregationColumnsAndInteractivity(this._aggregation.columns, this._featureClickColumns, this._featureOverColumns);
}
function Layer (source, style, options = {}) {
  Base.apply(this, arguments);

  _checkSource(source);
  _checkStyle(style);

  this._client = undefined;
  this._engine = undefined;
  this._internalModel = undefined;

  this._source = source;
  this._style = style;
  this._visible = _.isBoolean(options.visible) ? options.visible : true;
  this._featureClickColumns = options.featureClickColumns || [];
  this._featureOverColumns = options.featureOverColumns || [];
  this._minzoom = options.minzoom || 0;
  this._maxzoom = options.maxzoom || undefined;
  this._aggregation = options.aggregation || {};

  _validateAggregationColumnsAndInteractivity(this._aggregation.columns, this._featureClickColumns, this._featureOverColumns);
}
function Layer ( source , style , options = { } ) { Base . apply ( this , arguments ) ; _checkSource ( source ) ; _checkStyle ( style ) ; this . _client = undefined ; this . _engine = undefined ; this . _internalModel = undefined ; this . _source = source ; this . _style = style ; this . _visible = _ . isBoolean ( options . visible ) ? options . visible : true ; this . _featureClickColumns = options . featureClickColumns || [ ] ; this . _featureOverColumns = options . featureOverColumns || [ ] ; this . _minzoom = options . minzoom || 0 ; this . _maxzoom = options . maxzoom || undefined ; this . _aggregation = options . aggregation || { } ; _validateAggregationColumnsAndInteractivity ( this . _aggregation . columns , this . _featureClickColumns , this . _featureOverColumns ) ; }
Represents a layer Object.

A layer is the primary way to visualize geospatial data.

To create a layer a {@link carto.source.Base|source} and {@link carto.style.Base|styles}
are required:

- The {@link carto.source.Base|source} is used to know **what** data will be displayed in the Layer.
- The {@link carto.style.Base|style} is used to know **how** to draw the data in the Layer.

A layer alone won't do too much. In order to get data from the CARTO server you must add the Layer to a {@link carto.Client|client}.

```
// Create a layer. Remember this won't do anything unless the layer is added to a client.
const layer = new carto.layer.Layer(source, style);
```

@param {carto.source.Base} source - The source where the layer will fetch the data
@param {carto.style.CartoCSS} style - A CartoCSS object with the layer styling
@param {object} [options]
@param {Array<string>} [options.featureClickColumns=[]] - Columns that will be available for `featureClick` events
@param {boolean} [options.visible=true] - A boolean value indicating the layer's visibility
@param {Array<string>} [options.featureOverColumns=[]] - Columns that will be available for `featureOver` events
@param {carto.layer.Aggregation} [options.aggregation={}] - Specify {@link carto.layer.Aggregation|aggregation } options
@param {string} [options.id] - An unique identifier for the layer
@fires metadataChanged
@fires featureClicked
@fires featureOut
@fires featureOver
@fires error
@example
const citiesSource = new carto.source.SQL('SELECT * FROM cities');
const citiesStyle = new carto.style.CartoCSS(`
#layer {
marker-fill: #FABADA;
marker-width: 10;
}
`);
// Create a layer with no options
new carto.layer.Layer(citiesSource, citiesStyle);
@example
const citiesSource = new carto.source.SQL('SELECT * FROM cities');
const citiesStyle = new carto.style.CartoCSS(`
#layer {
marker-fill: #FABADA;
marker-width: 10;
}
`);
// Create a layer indicating what columns will be included in the featureOver event.
new carto.layer.Layer(citiesSource, citiesStyle, {
featureOverColumns: [ 'name' ]
});
@example
const citiesSource = new carto.source.SQL('SELECT * FROM cities');
const citiesStyle = new carto.style.CartoCSS(`
#layer {
marker-fill: #FABADA;
marker-width: 10;
}
`);
// Create a hidden layer
new carto.layer.Layer(citiesSource, citiesStyle, { visible: false });
@example
// Listen to the event thrown when the mouse is over a feature
layer.on('featureOver', featureEvent => {
console.log(`Mouse over city with name: ${featureEvent.data.name}`);
});
@constructor
@extends carto.layer.Base
@memberof carto.layer
@api
Represents a layer Object .