reduces repetition, adds callback

This commit is contained in:
Francisco Dans 2016-07-06 12:55:06 +02:00
parent 4cd282a6d4
commit bfc2489b5c
2 changed files with 20 additions and 18 deletions

View File

@ -392,25 +392,25 @@ L.TorqueLayer = L.CanvasLayer.extend({
setCartoCSS: function(cartocss) {
if (this.provider.options.named_map) throw new Error("CartoCSS style on named maps is read-only");
if (!this.renderer) throw new Error('renderer is not valid');
var shader = new carto.RendererJS().render(cartocss);
this.renderer.setShader(shader);
this.renderer.setCartoCSS(cartocss, function () {
// provider options
var options = torque.common.TorqueLayer.optionsFromLayer(this.renderer._shader.findLayer({ name: 'Map' }));
this.provider.setCartoCSS && this.provider.setCartoCSS(cartocss);
if(this.provider.setOptions(options)) {
this._reloadTiles();
}
// provider options
var options = torque.common.TorqueLayer.optionsFromLayer(shader.findLayer({ name: 'Map' }));
this.provider.setCartoCSS && this.provider.setCartoCSS(cartocss);
if(this.provider.setOptions(options)) {
this._reloadTiles();
}
torque.extend(this.options, options);
torque.extend(this.options, options);
// animator options
if (options.animationDuration) {
this.animator.duration(options.animationDuration);
}
this._clearCaches();
this.redraw();
return this;
}.bind(this));
// animator options
if (options.animationDuration) {
this.animator.duration(options.animationDuration);
}
this._clearCaches();
this.redraw();
return this;
},
/**

View File

@ -109,17 +109,19 @@ var CartoDatasource = require('./datasource');
//
// sets the cartocss style to render stuff
//
setCartoCSS: function(cartocss) {
setCartoCSS: function(cartocss, callback) {
var self = this;
if (PointRenderer.isTurboCarto(cartocss)) {
var datasource = new CartoDatasource(self.layer._tiles);
turbocarto(cartocss, datasource, function (err, parsedCartoCSS) {
self.setShader(new carto.RendererJS().render(parsedCartoCSS));
self.layer.redraw();
self.layer.animator.start()
self.layer.animator.start();
callback && callback();
});
} else {
self.setShader(new carto.RendererJS().render(cartocss));
callback && callback();
}
},