From c7600b2cbcd53a1459283a6b420235cd9a756b74 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Thu, 14 Nov 2013 01:35:19 +0100 Subject: [PATCH] Add ol.style.Text --- src/ol/render/dragbox.js | 1 + src/ol/style.js | 50 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/ol/render/dragbox.js b/src/ol/render/dragbox.js index c8ad9dd572..f3a83efe61 100644 --- a/src/ol/render/dragbox.js +++ b/src/ol/render/dragbox.js @@ -54,6 +54,7 @@ ol.render.DragBox = function(opt_style) { color: '#ff0000', width: 1 }, + text: null, zIndex: 0 }; diff --git a/src/ol/style.js b/src/ol/style.js index 691b9ecf85..41ff550109 100644 --- a/src/ol/style.js +++ b/src/ol/style.js @@ -6,6 +6,7 @@ goog.provide('ol.style.Style'); goog.provide('ol.style.StyleFunction'); goog.provide('ol.style.fill'); goog.provide('ol.style.stroke'); +goog.provide('ol.style.text'); goog.require('goog.functions'); goog.require('ol.color'); @@ -82,10 +83,46 @@ ol.style.stroke.equals = function(strokeStyle1, strokeStyle2) { }; +/** + * @typedef {{font: (string|undefined), + * text: (string|undefined), + * textAlign: (string|undefined), + * textBaseline: (string|undefined)}|null|undefined} + */ +ol.style.Text; + + +/** + * @param {ol.style.Text} textStyle1 Text style 1. + * @param {ol.style.Text} textStyle2 Text style 2. + * @return {boolean} Equals. + */ +ol.style.text.equals = function(textStyle1, textStyle2) { + if (goog.isDefAndNotNull(textStyle1)) { + if (goog.isDefAndNotNull(textStyle2)) { + return textStyle1 === textStyle2 || ( + textStyle1.font == textStyle2.font && + textStyle1.text == textStyle2.text && + textStyle1.textAlign == textStyle2.textAlign && + textStyle1.textBaseline == textStyle2.textBaseline); + } else { + return false; + } + } else { + if (goog.isDefAndNotNull(textStyle2)) { + return false; + } else { + return true; + } + } +}; + + /** * @typedef {{fill: ol.style.Fill, * image: ol.style.Image, * stroke: ol.style.Stroke, + * text: ol.style.Text, * zIndex: (number|undefined)}} */ ol.style.Style; @@ -129,6 +166,18 @@ ol.style.DEFAULT_STROKE_STYLE = { }; +/** + * @const + * @type {ol.style.Text} + */ +ol.style.DEFAULT_TEXT_STYLE = { + font: '10px sans-serif', + text: undefined, + textAlign: 'start', + textBaseline: 'alphabetic' +}; + + /** * @const * @type {number} @@ -144,6 +193,7 @@ ol.style.DEFAULT_STYLE = { fill: ol.style.DEFAULT_FILL_STYLE, image: ol.style.DEFAULT_IMAGE_STYLE, stroke: ol.style.DEFAULT_STROKE_STYLE, + text: ol.style.DEFAULT_TEXT_STYLE, zIndex: ol.style.DEFAULT_Z_INDEX };