removed renderer options, just return styles

This commit is contained in:
javi 2014-06-16 12:45:17 +02:00
parent 6dc65cc991
commit 6fad5676b4
3 changed files with 8 additions and 95 deletions

View File

@ -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/)

View File

@ -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]);
}
}

View File

@ -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);
});
});