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",
"doc": "The color of the area of the marker.",
"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": {

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) {
var img = st['point-file'] || st['marker-file'];
var ratio = img.height/img.width;
@ -50,7 +79,8 @@
exports.torque.cartocss = exports.torque.cartocss || {};
exports.torque.cartocss = {
renderPoint: renderPoint,
renderSprite: renderSprite
renderSprite: renderSprite,
renderRectangle: renderRectangle
};
})(typeof exports === "undefined" ? this : exports);

View File

@ -77,9 +77,14 @@
ctx.translate(canvasSize/2, canvasSize/2);
if(st['point-file'] || st['marker-file']) {
torque.cartocss.renderSprite(ctx, st);
} else {
var mt = st['marker-type'];
if (mt && mt === 'rectangle') {
torque.cartocss.renderRectangle(ctx, st);
} else {
torque.cartocss.renderPoint(ctx, st);
}
}
prof.end();
return canvas;
},