From 0d7f38f6c1117295fe985403efe321a6ff57f997 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 10 May 2013 20:40:00 -0700 Subject: [PATCH] Extract iD.util.localeName --- js/id/svg/labels.js | 18 +++++++----------- js/id/util.js | 5 +++++ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/js/id/svg/labels.js b/js/id/svg/labels.js index abb0a9251..754328c66 100644 --- a/js/id/svg/labels.js +++ b/js/id/svg/labels.js @@ -104,7 +104,7 @@ iD.svg.Labels = function(projection, context) { 'startOffset': '50%', 'xlink:href': function(d) { return '#labelpath-' + d.id; } }) - .text(function(d) { return name(d); }); + .text(iD.util.localeName); texts.exit().remove(); @@ -140,8 +140,8 @@ iD.svg.Labels = function(projection, context) { texts.attr('x', get(labels, 'x')) .attr('y', get(labels, 'y')) .style('text-anchor', get(labels, 'textAnchor')) - .text(function(d) { return name(d); }) - .each(function(d, i) { textWidth(name(d), labels[i].height, this); }); + .text(iD.util.localeName) + .each(function(d, i) { textWidth(iD.util.localeName(d), labels[i].height, this); }); texts.exit().remove(); return texts; @@ -241,13 +241,8 @@ iD.svg.Labels = function(projection, context) { .classed('proximate', true); } - function name(d) { - return d.tags[lang] || d.tags.name; - } - var rtree = new RTree(), - rectangles = {}, - lang = 'name:' + iD.detect().locale.toLowerCase().split('-')[0]; + rectangles = {}; function labels(surface, graph, entities, filter, dimensions, fullRedraw) { @@ -272,7 +267,7 @@ iD.svg.Labels = function(projection, context) { preset = geometry === 'area' && context.presets().match(entity, graph), icon = preset && !blacklisted(preset) && preset.icon; - if ((name(entity) || icon) && !(hidePoints && geometry === 'point')) { + if ((iD.util.localeName(entity) || icon) && !(hidePoints && geometry === 'point')) { for (k = 0; k < label_stack.length; k ++) { if (entity.geometry(graph) === label_stack[k][0] && @@ -301,7 +296,8 @@ iD.svg.Labels = function(projection, context) { var font_size = font_sizes[k]; for (i = 0; i < labelable[k].length; i ++) { entity = labelable[k][i]; - var width = name(entity) && textWidth(name(entity), font_size), + var name = iD.util.localeName(entity), + width = name && textWidth(name, font_size), p; if (entity.geometry(graph) === 'point') { p = getPointLabel(entity, width, font_size); diff --git a/js/id/util.js b/js/id/util.js index 5efdcfb7e..7e23d9117 100644 --- a/js/id/util.js +++ b/js/id/util.js @@ -10,6 +10,11 @@ iD.util.entitySelector = function(ids) { return ids.length ? '.' + ids.join(',.') : 'nothing'; }; +iD.util.localeName = function(entity) { + var localeName = 'name:' + iD.detect().locale.toLowerCase().split('-')[0]; + return entity.tags[localeName] || entity.tags.name; +}; + iD.util.stringQs = function(str) { return str.split('&').reduce(function(obj, pair){ var parts = pair.split('=');