From 44d310bb6d9760924eb9f3798502b9f7591eff39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Thu, 19 Dec 2013 13:34:07 +0100 Subject: [PATCH] Add getters to ol.style.Text --- src/ol/render/canvas/canvasimmediate.js | 15 +++-- src/ol/style/textstyle.js | 85 +++++++++++++++++++++---- 2 files changed, 83 insertions(+), 17 deletions(-) diff --git a/src/ol/render/canvas/canvasimmediate.js b/src/ol/render/canvas/canvasimmediate.js index c89230ad96..85b3260a82 100644 --- a/src/ol/render/canvas/canvasimmediate.js +++ b/src/ol/render/canvas/canvasimmediate.js @@ -487,12 +487,15 @@ ol.render.canvas.Immediate.prototype.setTextStyle = function(textStyle) { var state = this.state_; if (!ol.style.Text.equals(state.textStyle, textStyle)) { if (goog.isDefAndNotNull(textStyle)) { - context.font = goog.isDef(textStyle.font) ? - textStyle.font : ol.render.canvas.defaultFont; - context.textAlign = goog.isDef(textStyle.textAlign) ? - textStyle.textAlign : ol.render.canvas.defaultTextAlign; - context.textBaseline = goog.isDef(textStyle.textBaseline) ? - textStyle.textBaseline : ol.render.canvas.defaultTextBaseline; + var textStyleFont = textStyle.getFont(); + context.font = goog.isDef(textStyleFont) ? + textStyleFont : ol.render.canvas.defaultFont; + var textStyleTextAlign = textStyle.getTextAlign(); + context.textAlign = goog.isDef(textStyleTextAlign) ? + textStyleTextAlign : ol.render.canvas.defaultTextAlign; + var textStyleTextBaseline = textStyle.getTextBaseline(); + context.textBaseline = goog.isDef(textStyleTextBaseline) ? + textStyleTextBaseline : ol.render.canvas.defaultTextBaseline; } state.textStyle = textStyle; } diff --git a/src/ol/style/textstyle.js b/src/ol/style/textstyle.js index a2a7851897..8ad1c50469 100644 --- a/src/ol/style/textstyle.js +++ b/src/ol/style/textstyle.js @@ -11,39 +11,46 @@ ol.style.Text = function(opt_options) { var options = goog.isDef(opt_options) ? opt_options : {}; /** + * @private * @type {string|undefined} */ - this.font = options.font; + this.font_ = options.font; /** + * @private * @type {number|undefined} */ - this.rotation = options.rotation; + this.rotation_ = options.rotation; /** + * @private * @type {string|undefined} */ - this.text = options.text; + this.text_ = options.text; /** + * @private * @type {string|undefined} */ - this.textAlign = options.textAlign; + this.textAlign_ = options.textAlign; /** + * @private * @type {string|undefined} */ - this.textBaseline = options.textBaseline; + this.textBaseline_ = options.textBaseline; /** + * @private * @type {ol.style.Fill} */ - this.fill = goog.isDef(options.fill) ? options.fill : null; + this.fill_ = goog.isDef(options.fill) ? options.fill : null; /** + * @private * @type {ol.style.Stroke} */ - this.stroke = goog.isDef(options.stroke) ? options.stroke : null; + this.stroke_ = goog.isDef(options.stroke) ? options.stroke : null; }; @@ -56,10 +63,10 @@ ol.style.Text.equals = function(textStyle1, textStyle2) { if (!goog.isNull(textStyle1)) { if (!goog.isNull(textStyle2)) { return textStyle1 === textStyle2 || ( - textStyle1.font == textStyle2.font && - textStyle1.text == textStyle2.text && - textStyle1.textAlign == textStyle2.textAlign && - textStyle1.textBaseline == textStyle2.textBaseline); + textStyle1.getFont() == textStyle2.getFont() && + textStyle1.getText() == textStyle2.getText() && + textStyle1.getTextAlign() == textStyle2.getTextAlign() && + textStyle1.getTextBaseline() == textStyle2.getTextBaseline()); } else { return false; } @@ -71,3 +78,59 @@ ol.style.Text.equals = function(textStyle1, textStyle2) { } } }; + + +/** + * @return {string|undefined} Font. + */ +ol.style.Text.prototype.getFont = function() { + return this.font_; +}; + + +/** + * @return {ol.style.Fill} Fill style. + */ +ol.style.Text.prototype.getFill = function() { + return this.fill_; +}; + + +/** + * @return {number|undefined} Rotation. + */ +ol.style.Text.prototype.getRotation = function() { + return this.rotation_; +}; + + +/** + * @return {ol.style.Stroke} Stroke style. + */ +ol.style.Text.prototype.getStroke = function() { + return this.stroke_; +}; + + +/** + * @return {string|undefined} Text. + */ +ol.style.Text.prototype.getText = function() { + return this.text_; +}; + + +/** + * @return {string|undefined} Text align. + */ +ol.style.Text.prototype.getTextAlign = function() { + return this.textAlign_; +}; + + +/** + * @return {string|undefined} Text baseline. + */ +ol.style.Text.prototype.getTextBaseline = function() { + return this.textBaseline_; +};