Commit 2ed7834e authored by Adrien Pavie's avatar Adrien Pavie
Browse files

Feature name in browser locale if available (closes #58)

parent 52729e6a
......@@ -129,8 +129,9 @@ MapLayersManager.prototype.setOSMFeatures = function(f, ruleset, options) {
var feature, fid, fLayer, fStyle, fLayerEdited, fClickHandler;
var fLevel, fIconUrl, fIconCoords, fIconAngle, coord1, coord2;
var midSegment, fIconRgxTagName, fIconRgxTagValue, fTextOffset;
var fHasIcon;
var fHasIcon, textVal;
var fIconRgx = /\$\[(\w+)\]/;
var locale = (window.navigator.userLanguage || window.navigator.language || "en").split("-")[0].toLowerCase();
fClickHandler = options.clickHandler;
......@@ -273,9 +274,12 @@ MapLayersManager.prototype.setOSMFeatures = function(f, ruleset, options) {
fTextOffset -= ((!isNaN(fStyle.icon_height)) ? fStyle.icon_height : options.size) / 2 + 5;
}
//Text value
textVal = (fStyle.text == "name" && feature.hasTag("name:"+locale)) ? feature.getTag("name:"+locale) : feature.getTag(fStyle.text);
fLayer.addLayer(this._createLabel(
fIconCoords,
feature.getTag(fStyle.text),
textVal,
fStyle,
fTextOffset,
fIconAngle
......
......@@ -54,7 +54,7 @@ Feature.prototype.get = function() {
if(this._feature != null) {
var title = $(
"<div class=\"side-content-feature-title\"><h2>"+((this._feature.name) ? this._feature.name : ((this._feature.category) ? this._feature.category : this._feature.id))+"</h2>"+
"<div class=\"side-content-feature-title\"><h2>"+this._displayName()+"</h2>"+
((this._feature.category != this._feature.name && this._feature.category != null) ? "<span>"+this._feature.category+"</span>" : "<span>"+this.t("feature.name")+"</span>")+
"</div>"
);
......@@ -301,5 +301,18 @@ Feature.prototype._mapillaryKeys = function() {
return result;
};
/**
* @return The readable name of a feature
*/
Feature.prototype._displayName = function() {
if(this._feature.name) {
//Check for name in browser locale
var locale = (window.navigator.userLanguage || window.navigator.language || "en").split("-")[0].toLowerCase();
return (this._feature.tags["name:"+locale]) ? this._feature.tags["name:"+locale] : this._feature.name;
}
else {
return (this._feature.category) ? this._feature.category : this._feature.id;
}
};
module.exports = Feature;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment