Skip to content

Commit

Permalink
Merge pull request #126 from CartoDB/refactor-27f
Browse files Browse the repository at this point in the history
Extract methods on layer.setSource
  • Loading branch information
IagoLast authored Mar 5, 2018
2 parents 7573d78 + 609636a commit 9d373db
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions src/api/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,40 @@ export default class Layer {
*/
setSource(source) {
this._checkSource(source);
source.bindLayer(
dataframe => {
this._dataframes.push(dataframe);
this._integrator.renderer.addDataframe(dataframe);
this._integrator.invalidateWebGLState();
},
dataframe => {
this._dataframes = this._dataframes.filter(d => d !== dataframe);
this._integrator.renderer.removeDataframe(dataframe);
this._integrator.invalidateWebGLState();
},
() => {
this.state = 'dataLoaded';
}
);
source.bindLayer(this._onDataframeAdded.bind(this), this._onDataFrameRemoved.bind(this), this._onDataLoaded.bind(this));
if (this._source && this._source !== source) {
this._source.free();
}
this._source = source;
}

/**
* Callback executed when the client adds a new dataframe
* @param {Dataframe} dataframe
*/
_onDataframeAdded(dataframe) {
this._dataframes.push(dataframe);
this._integrator.renderer.addDataframe(dataframe);
this._integrator.invalidateWebGLState();
}

/**
* Callback executed when the client removes dataframe
* @param {Dataframe} dataframe
*/
_onDataFrameRemoved(dataframe) {
this._dataframes = this._dataframes.filter(d => d !== dataframe);
this._integrator.renderer.removeDataframe(dataframe);
this._integrator.invalidateWebGLState();
}

/**
* Callback executed when the client finishes loading data
*/
_onDataLoaded() {
this.state = 'dataLoaded';
}

/**
* Set a new style for this layer.
*
Expand Down Expand Up @@ -224,6 +237,7 @@ export default class Layer {
this._styleChanged(this._style);
this.requestData();
}

_addToMGLMap(map, beforeLayerID) {
if (map.isStyleLoaded()) {
this._onMapLoaded(map, beforeLayerID);
Expand Down

0 comments on commit 9d373db

Please sign in to comment.