From 6fad5676b4ac18846308d5a3f5f4c02a1078ac80 Mon Sep 17 00:00:00 2001 From: javi Date: Mon, 16 Jun 2014 12:45:17 +0200 Subject: [PATCH] removed renderer options, just return styles --- README.md | 8 ++-- lib/carto/renderer_js.js | 91 +-------------------------------------- test/rendering_js.test.js | 4 +- 3 files changed, 8 insertions(+), 95 deletions(-) diff --git a/README.md b/README.md index ae63e57..9e85151 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ for (var i = 0; i < layers.length; ++i) { console.log("- frames: ", layer.frames()) console.log("- attachment: ", layer.attachment()) - var layerShader = layer.getStyle('canvas-2d', { property: 1 }, { zoom: 10 }) + var layerShader = layer.getStyle({ property: 1 }, { zoom: 10 }) console.log(layerShader['marker-width']) // 1 console.log(layerShader['marker-fill']) // #FF0000 } @@ -60,10 +60,9 @@ shader.findLayer({ name: 'test' }) ## CartoCSS.Layer -### getStyle(target, props, context) +### getStyle(props, context) -return the evaluated style - - target: 'canvas-2d' +return the evaluated style: - props: object containing properties needed to render the style. If the cartocss style uses some variables they should be passed in this object - context: rendering context variables like ``zoom`` or animation ``frame`` @@ -76,6 +75,7 @@ return the evaluated style + ## Reference Documentation * [mapbox.com/carto](http://mapbox.com/carto/) diff --git a/lib/carto/renderer_js.js b/lib/carto/renderer_js.js index fdc2a38..570830c 100644 --- a/lib/carto/renderer_js.js +++ b/lib/carto/renderer_js.js @@ -88,90 +88,6 @@ CartoCSS.Layer = function(shader, options) { this.shader = shader; }; -CartoCSS.renderers = {}; - -CartoCSS.renderers['svg'] = { - - maps: {}, - - transform: function(src) { - var target = {}; - for(var i in src) { - var t = this.maps[i]; - if(t) { - target[t] = src[i]; - } else { - // copy it - target[i] = src[i]; - } - } - return target; - } - -}; - -CartoCSS.renderers['canvas-2d'] = { - - maps: { - // marker - 'marker-width': 'point-radius', - 'marker-line-color': 'strokeStyle', - 'marker-line-width': 'lineWidth', - 'marker-line-opacity': 'strokeOpacity', - 'marker-fill-opacity': 'fillOpacity', - 'marker-opacity': 'fillOpacity', - 'marker-fill': 'fillStyle', - 'marker-file': function(attr) { - var img = new Image(); - img.src = attr; - return img; - }, - // point - 'point-color': 'fillStyle', - 'point-file': function(attr) { - var img = new Image(); - img.src = attr; - return img; - }, - // line - 'line-color': 'strokeStyle', - 'line-width': 'lineWidth', - 'line-opacity': 'globalAlpha', - // polygon - 'polygon-fill': 'fillStyle', - 'polygon-opacity': 'globalAlpha', - 'comp-op': 'comp-op' - }, - - transform: function(src) { - var target = {}; - for(var i in src) { - var t = this.maps[i]; - if(t) { - if(typeof(t) === 'function') { - target[i] = t(src[i]); - } else { - target[t] = src[i]; - } - } else { - // copy it - target[i] = src[i]; - } - } - return target; - } -} - -var renderer = CartoCSS.renderers['svg']; -var ref = require('mapnik-reference').version.latest; -var to_load = ['polygon', 'line', 'point', 'markers']; -for(var ss in to_load) { - var s = to_load[ss]; - for(var i in ref.symbolizers[s]) { - renderer.maps[ref.symbolizers[s][i].css] = i; - } -} - CartoCSS.Layer.prototype = { @@ -203,14 +119,14 @@ CartoCSS.Layer.prototype = { * `props`: feature properties * `context`: rendering properties, i.e zoom */ - getStyle: function(target, props, context) { + getStyle: function(props, context) { var style = {}; for(var i in this.shader) { if(i !== 'attachment' && i !== 'zoom' && i !== 'frames') { style[i] = this.shader[i](props, context); } } - return CartoCSS.renderers[target].transform(style); + return style; }, /** @@ -309,7 +225,6 @@ CartoCSS.prototype = { try { ruleset = (new carto.Parser(parse_env)).parse(cartocss); } catch(e) { - console.log(e.stack); // add the style.mss string to match the response from the server parse_env.errors.push(e.message); return; @@ -341,8 +256,6 @@ CartoCSS.prototype = { if(!done[k]) { for(var prop in layer) { if (prop !== 'zoom' && prop !== 'frames') { - - console.log("****", prop); layer[prop] = this._createFn(layer[prop]); } } diff --git a/test/rendering_js.test.js b/test/rendering_js.test.js index 352acb3..519203d 100644 --- a/test/rendering_js.test.js +++ b/test/rendering_js.test.js @@ -39,7 +39,7 @@ describe('RenderingJS', function() { it ("shold render with frames var", function() { var layer = shader.getLayers()[1]; - var props = layer.getStyle('canvas-2d', {}, { 'zoom': 0, 'frame-offset': 10 }); - assert( props['lineWidth'] === 4); + var props = layer.getStyle({}, { 'zoom': 0, 'frame-offset': 10 }); + assert( props['line-width'] === 4); }); });