Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

fixed issue with running-data value display. close #89

Benjamin984fb0afe563
diff --git a/web/js/map/wv.map.runningdata.js b/web/js/map/wv.map.runningdata.js
index ca86a4d45..671ed3a1f 100644
--- a/web/js/map/wv.map.runningdata.js
+++ b/web/js/map/wv.map.runningdata.js
@@ -361,7 +361,7 @@ wv.map.runningdata = wv.map.runningdata || function(models) {
$paletteLabel.text(data.label);
- labelWidth = $paletteLabel.width();
+ labelWidth = wv.util.getTextWidth(data.label, 'Lucida Sans');
labelMargin = self.getLabelMarginLeft(labelWidth, $paletteWidth, location);
diff --git a/web/js/util/wv.util.js b/web/js/util/wv.util.js
index c64358c25..9b6c0c488 100644
--- a/web/js/util/wv.util.js
+++ b/web/js/util/wv.util.js
@@ -21,7 +21,7 @@ var wv = wv || {};
* @static
*/
wv.util = (function(self) {
-
+ var canvas = null;
// Needed anymore?
self.LAYER_GROUPS = {
baselayers: {
@@ -185,7 +185,22 @@ wv.util = (function(self) {
}
return date;
};
-
+ /**
+ * Uses canvas.measureText to compute and return the width of the given text of given font in pixels.
+ *
+ * @param {String} text The text to be rendered.
+ * @param {String} font The css font descriptor that text is to be rendered with (e.g. "bold 14px verdana").
+ *
+ * @see http://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393
+ */
+ self.getTextWidth = function(text, font) {
+ // re-use canvas object for better performance
+ canvas = canvas || document.createElement("canvas");
+ var context = canvas.getContext("2d");
+ context.font = font;
+ var metrics = context.measureText(text);
+ return metrics.width;
+ };
/**
* Converts a date into an ISO string with only the date portion.
*