From 481a9b407898324d22b190ea110df40030539b89 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sun, 10 Nov 2013 01:41:06 +0100 Subject: [PATCH] Add symbol renderer --- src/ol/symbols.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/ol/symbols.js diff --git a/src/ol/symbols.js b/src/ol/symbols.js new file mode 100644 index 0000000000..7f7efd8007 --- /dev/null +++ b/src/ol/symbols.js @@ -0,0 +1,46 @@ +goog.provide('ol.symbol'); + +goog.require('goog.dom'); +goog.require('goog.dom.TagName'); +goog.require('ol.style'); + + +/** + * @param {number} radius Radius. + * @param {?ol.style.Fill} fillStyle Fill style. + * @param {?ol.style.Stroke} strokeStyle Stroke style. + * @return {ol.style.Image} Image. + */ +ol.symbol.renderCircle = function(radius, fillStyle, strokeStyle) { + + var canvas = /** @type {HTMLCanvasElement} */ + (goog.dom.createElement(goog.dom.TagName.CANVAS)); + var size = 2 * radius + 1; + if (!goog.isNull(strokeStyle) && goog.isDef(strokeStyle.width)) { + size += strokeStyle.width; + } + canvas.height = size; + canvas.width = size; + + var context = /** @type {CanvasRenderingContext2D} */ + (canvas.getContext('2d')); + context.arc(size / 2, size / 2, radius, 0, 2 * Math.PI, true); + + if (goog.isDefAndNotNull(fillStyle)) { + context.fillStyle = fillStyle.color; + context.fill(); + } + if (goog.isDefAndNotNull(strokeStyle)) { + context.strokeStyle = strokeStyle.color; + context.lineWidth = strokeStyle.width; + context.stroke(); + } + + return { + anchor: [size / 2, size / 2], + image: canvas, + rotation: 0, + subtractViewRotation: false + }; + +};