cartodb-4.42/lib/assets/javascripts/builder/node-geometry-tracker.js

28 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-04-06 13:25:13 +08:00
/*
* Track geometry changes that happens in any Node definition model
*/
module.exports = {
track: function (params) {
if (!params) throw new Error('several parameters required');
if (!params.layerDefinitionsCollection) throw new Error('layerDefinitionsCollection is required');
if (!params.analysisDefinitionNodesCollection) throw new Error('analysisDefinitionNodesCollection is required');
if (!params.analysisDefinitionsCollection) throw new Error('analysisDefinitionsCollection is required');
this._layerDefinitionsCollection = params.layerDefinitionsCollection;
this._analysisDefinitionsCollection = params.analysisDefinitionsCollection;
params.analysisDefinitionNodesCollection.bind('change:simple_geom', this._onNodeGeometryChange, this);
},
_onNodeGeometryChange: function (nodeDefModel) {
if (nodeDefModel.get('table_name')) { // If it is a source node, no save
return;
}
var layerDefModel = this._layerDefinitionsCollection.findWhere({ source: nodeDefModel.get('id') });
if (layerDefModel) {
this._analysisDefinitionsCollection.saveAnalysisForLayer(layerDefModel);
}
}
};