From 3a782117f5f0e1b467acd52399c0cf7ac619d9a3 Mon Sep 17 00:00:00 2001 From: Rafa de la Torre Date: Fri, 14 Jun 2019 15:07:24 +0200 Subject: [PATCH] Strip comments out of cartocss --- lib/torque/renderer/point.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/torque/renderer/point.js b/lib/torque/renderer/point.js index 6f5f201..6abcf55 100644 --- a/lib/torque/renderer/point.js +++ b/lib/torque/renderer/point.js @@ -57,6 +57,12 @@ var CartoDatasource = require('./datasource'); return COMP_OP_TO_CANVAS[compop] || compop; } + // Take an input cartocss that may contain comments and remove them + var COMMENTS_RE = /\/\*.*?\*\/\n?/mg; + function stripComments(cartocss) { + return cartocss.replace(COMMENTS_RE, ''); + } + // // this renderer just render points depending of the value // @@ -73,8 +79,7 @@ var CartoDatasource = require('./datasource'); this._icons = {}; this._iconsToLoad = 0; this._filters = new Filters(this._canvas, {canvasClass: options.canvasClass}); - this.style = this.options.cartocss || DEFAULT_CARTOCSS; - this.setCartoCSS(this.style); + this.setCartoCSS(this.options.cartocss || DEFAULT_CARTOCSS); this.TILE_SIZE = 256; this._style = null; this._gradients = {}; @@ -116,11 +121,11 @@ var CartoDatasource = require('./datasource'); setCartoCSS: function(cartocss, callback) { var self = this; - this.style = cartocss; + this.style = stripComments(cartocss); - if (PointRenderer.isTurboCarto(cartocss)) { + if (PointRenderer.isTurboCarto(this.style)) { var datasource = new CartoDatasource(self.layer._tiles); - turbocarto(cartocss, datasource, function (err, parsedCartoCSS) { + turbocarto(this.style, datasource, function (err, parsedCartoCSS) { if (err) { return callback(err, null); } @@ -131,7 +136,7 @@ var CartoDatasource = require('./datasource'); callback && callback(); }); } else { - self.setShader(new carto.RendererJS().render(cartocss)); + self.setShader(new carto.RendererJS().render(this.style)); callback && callback(); } },