src/Layer.js
/**
     * Update the layer with a new Source and a new Viz object, replacing the current ones. The update is done atomically, i.e.: the viz will be changed with the source, not before it.
     * This method will return a promise that will be resolved once the source and the visualization are validated.
     * The promise will be rejected if the validation fails, for example because the visualization expects a property name that is not present in the source.
     * The promise will be rejected also if this method is invoked again before the first promise is resolved.
     * If the promise is rejected the layer's source and viz won't be changed.
     * @param {carto.source.Base} source - The new Source object
     * @param {carto.Viz?} viz - Optional. The new Viz object
     * @memberof carto.Layer
     * @instance
     * @async
     * @api
     */
Update the layer with a new Source and a new Viz object, replacing the current ones. The update is done atomically, i.e.: the viz will be changed with the source, not before it.
This method will return a promise that will be resolved once the source and the visualization are validated.
The promise will be rejected if the validation fails, for example because the visualization expects a property name that is not present in the source.
The promise will be rejected also if this method is invoked again before the first promise is resolved.
If the promise is rejected the layer's source and viz won't be changed.
@param {carto.source.Base} source - The new Source object
@param {carto.Viz?} viz - Optional. The new Viz object
@memberof carto.Layer
@instance
@async
@api
Update the layer with a new Source and a new Viz object replacing the current ones . The update is done atomically i . e . : the viz will be changed with the source not before it . This method will return a promise that will be resolved once the source and the visualization are validated . The promise will be rejected if the validation fails for example because the visualization expects a property name that is not present in the source . The promise will be rejected also if this method is invoked again before the first promise is resolved . If the promise is rejected the layer ' s source and viz won ' t be changed . @param { carto . source . Base } source - The new Source object @param { carto . Viz? } viz - Optional . The new Viz object @memberof carto . Layer @instance @async @api
async update (source, viz) {
        if (viz === undefined) {
            viz = this._viz;
        }
        this._checkSource(source);
        this._checkViz(viz);
        source = source._clone();
        this._atomicChangeUID++;
        const uid = this._atomicChangeUID;
        const loadImagesPromise = viz.loadImages();
        const metadata = await source.requestMetadata(viz);
        await loadImagesPromise;
        await this._context;
        if (this._atomicChangeUID > uid) {
            throw new Error('Another atomic change was done before this one committed');
        }
        this.metadata = metadata;
        source.bindLayer(this._onDataframeAdded.bind(this), this._onDataLoaded.bind(this));
        if (this._source !== source) {
            this._freeSource();
        }
        this._source = source;
        this.requestData();
        viz.setDefaultsIfRequired(this.metadata.geomType);
        await this._context;
        if (this._atomicChangeUID > uid) {
            throw new Error('Another atomic change was done before this one committed');
        }
        if (this._viz) {
            this._viz.onChange(null);
        }
        viz.setDefaultsIfRequired(this._renderLayer.type);
        this._viz = viz;
        viz.onChange(this._vizChanged.bind(this));
        this._compileShaders(viz, metadata);
        this._needRefresh();
    }
async update ( source , viz ) { if ( viz === undefined ) { viz = this . _viz ; } this . _checkSource ( source ) ; this . _checkViz ( viz ) ; source = source . _clone ( ) ; this . _atomicChangeUID ++ ; const uid = this . _atomicChangeUID ; const loadImagesPromise = viz . loadImages ( ) ; const metadata = await source . requestMetadata ( viz ) ; await loadImagesPromise ; await this . _context ; if ( this . _atomicChangeUID > uid ) { throw new Error ( 'Another atomic change was done before this one committed' ) ; } this . metadata = metadata ; source . bindLayer ( this . _onDataframeAdded . bind ( this ) , this . _onDataLoaded . bind ( this ) ) ; if ( this . _source !== source ) { this . _freeSource ( ) ; } this . _source = source ; this . requestData ( ) ; viz . setDefaultsIfRequired ( this . metadata . geomType ) ; await this . _context ; if ( this . _atomicChangeUID > uid ) { throw new Error ( 'Another atomic change was done before this one committed' ) ; } if ( this . _viz ) { this . _viz . onChange ( null ) ; } viz . setDefaultsIfRequired ( this . _renderLayer . type ) ; this . _viz = viz ; viz . onChange ( this . _vizChanged . bind ( this ) ) ; this . _compileShaders ( viz , metadata ) ; this . _needRefresh ( ) ; }
Update the layer with a new Source and a new Viz object, replacing the current ones.
Update the layer with a new Source and a new Viz object replacing the current ones .
// Use current viz // Everything was ok => commit changes