added marker-type = rectangle

This commit is contained in:
javi 2013-11-22 16:16:32 +01:00
parent 46aa9fa2f2
commit d2dcf7b2a1
3 changed files with 46 additions and 2 deletions

View File

@ -214,6 +214,15 @@ var _torque_reference_latest = {
"default-value": "blue", "default-value": "blue",
"doc": "The color of the area of the marker.", "doc": "The color of the area of the marker.",
"type": "color" "type": "color"
},
"marker-type": {
"css": "marker-type",
"type": [
"rectangle",
"ellipse"
],
"default-value": "ellipse",
"doc": "The default marker-type. If a SVG file is not given as the marker-file parameter, the renderer provides either an rectangle or an ellipse (a circle if height is equal to width)"
} }
}, },
"point": { "point": {

View File

@ -39,6 +39,35 @@
} }
} }
function renderRectangle(ctx, st) {
ctx.fillStyle = st.fillStyle;
ctx.strokStyle = st.strokStyle;
var pixel_size = st['point-radius'];
// fill
if (st.fillStyle && st.fillOpacity) {
ctx.globalAlpha = st.fillOpacity;
}
ctx.fillRect(0, 0, pixel_size, pixel_size)
// stroke
ctx.globalAlpha = 1.0;
if (st.strokeStyle && st.lineWidth) {
if (st.strokeOpacity) {
ctx.globalAlpha = st.strokeOpacity;
}
if (st.lineWidth) {
ctx.lineWidth = st.lineWidth;
}
ctx.strokeStyle = st.strokeStyle;
// do not render for alpha = 0
if (ctx.globalAlpha > 0) {
ctx.strokeRect(0, 0, pixel_size, pixel_size);
}
}
}
function renderSprite(ctx, st) { function renderSprite(ctx, st) {
var img = st['point-file'] || st['marker-file']; var img = st['point-file'] || st['marker-file'];
var ratio = img.height/img.width; var ratio = img.height/img.width;
@ -50,7 +79,8 @@
exports.torque.cartocss = exports.torque.cartocss || {}; exports.torque.cartocss = exports.torque.cartocss || {};
exports.torque.cartocss = { exports.torque.cartocss = {
renderPoint: renderPoint, renderPoint: renderPoint,
renderSprite: renderSprite renderSprite: renderSprite,
renderRectangle: renderRectangle
}; };
})(typeof exports === "undefined" ? this : exports); })(typeof exports === "undefined" ? this : exports);

View File

@ -78,7 +78,12 @@
if(st['point-file'] || st['marker-file']) { if(st['point-file'] || st['marker-file']) {
torque.cartocss.renderSprite(ctx, st); torque.cartocss.renderSprite(ctx, st);
} else { } else {
torque.cartocss.renderPoint(ctx, st); var mt = st['marker-type'];
if (mt && mt === 'rectangle') {
torque.cartocss.renderRectangle(ctx, st);
} else {
torque.cartocss.renderPoint(ctx, st);
}
} }
prof.end(); prof.end();
return canvas; return canvas;