src/Layer.js
/**
     * Add this layer to a map. If the map's style is not loaded yet it will wait for it to add the layer as soon as possible.
     *
     * @param {mapboxgl.Map} map - The map on which to add the layer
     * @param {string?} beforeLayerID - The ID of an existing layer to insert the new layer before. If this values is not passed the layer will be added on the top of the existing layers.
     * @memberof carto.Layer
     * @instance
     * @api
     */
Add this layer to a map. If the map's style is not loaded yet it will wait for it to add the layer as soon as possible.
@param {mapboxgl.Map} map - The map on which to add the layer
@param {string?} beforeLayerID - The ID of an existing layer to insert the new layer before. If this values is not passed the layer will be added on the top of the existing layers.
Add this layer to a map . If the map ' s style is not loaded yet it will wait for it to add the layer as soon as possible . @param { mapboxgl . Map } map - The map on which to add the layer @param { string? } beforeLayerID - The ID of an existing layer to insert the new layer before . If this values is not passed the layer will be added on the top of the existing layers .
addTo (map, beforeLayerID) {
        const STYLE_ERROR_REGEX = /Style is not done loading/;
        try {
            map.addLayer(this, beforeLayerID);
        } catch (error) {
            if (!STYLE_ERROR_REGEX.test(error)) {
                throw new Error(error);
            }
            map.on('load', () => {
                map.addLayer(this, beforeLayerID);
            });
        }
    }
addTo ( map , beforeLayerID ) { const STYLE_ERROR_REGEX = / Style is not done loading / ; try { map . addLayer ( this , beforeLayerID ) ; } catch ( error ) { if ( ! STYLE_ERROR_REGEX . test ( error ) ) { throw new Error ( error ) ; } map . on ( 'load' , ( ) => { map . addLayer ( this , beforeLayerID ) ; } ) ; } }
Add this layer to a map.
Add this layer to a map .