diff --git a/lib/torque/cartocss_reference.js b/lib/torque/cartocss_reference.js index 93f812c..1775582 100644 --- a/lib/torque/cartocss_reference.js +++ b/lib/torque/cartocss_reference.js @@ -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": { diff --git a/lib/torque/renderer/cartocss_render.js b/lib/torque/renderer/cartocss_render.js index 49dd44b..9c8db0b 100644 --- a/lib/torque/renderer/cartocss_render.js +++ b/lib/torque/renderer/cartocss_render.js @@ -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); diff --git a/lib/torque/renderer/point.js b/lib/torque/renderer/point.js index e38ab1a..6c6c6e0 100644 --- a/lib/torque/renderer/point.js +++ b/lib/torque/renderer/point.js @@ -78,7 +78,12 @@ if(st['point-file'] || st['marker-file']) { torque.cartocss.renderSprite(ctx, st); } 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(); return canvas;