1 function formatOSMType(sType, bExcludeExternal)
3 if (sType == 'N') return 'node';
4 if (sType == 'W') return 'way';
5 if (sType == 'R') return 'relation';
7 if (!bExcludeExternal) return '';
9 if (sType == 'T') return 'way';
10 if (sType == 'I') return 'way';
15 Handlebars.registerHelper({
16 isaddresses_unused: function(aAddressLine) {
17 return ((aAddressLine.isaddress && aAddressLine.isaddress == 'f') ? 'notused' : '');
19 // { osm_type: 'R', osm_id: 12345 }
20 // <a href="//www.openstreetmap.org/relation/12345">relation 12345</a
21 osmLink: function(aPlace) {
22 if (!aPlace.osm_type) return '';
23 var sOSMType = formatOSMType(aPlace.osm_type, false);
24 if (!sOSMType) return '';
26 return new Handlebars.SafeString(
27 '<a href="//www.openstreetmap.org/' + sOSMType + '/' + aPlace.osm_id + '">' + sOSMType + ' ' + aPlace.osm_id + '</a>'
30 /* en:London_Borough_of_Redbridge => https://en.wikipedia.org/wiki/London_Borough_of_Redbridge */
31 wikipediaLink: function(aPlace) {
32 if (! aPlace.wikipedia) return '';
34 var parts = aPlace.wikipedia.split(':', 2);
36 var sTitle = Handlebars.escapeExpression(aPlace.wikipedia),
37 sLanguage = Handlebars.escapeExpression(parts[0]),
38 sArticle = Handlebars.escapeExpression(parts[1]);
40 return new Handlebars.SafeString(
41 '<a href="https://' + sLanguage + '.wikipedia.org/wiki/' + sArticle + '" target="_blank">' + sTitle + '</a>'
44 // { osm_type: 'R', osm_id: 12345 }
45 // <a href="//www.openstreetmap.org/relation/12345">relation 12345</a
46 detailsLink: function(aFeature, sTitle) {
47 if (!aFeature) return '';
48 if (!aFeature.place_id) return '';
51 var sTitle = Handlebars.escapeExpression(sTitle);
53 return new Handlebars.SafeString(
54 '<a href="details.html?place_id=' + aFeature.place_id + '">' + (sTitle ? sTitle : aFeature.place_id ) + '</a>'
57 coverageType: function(aPlace) {
58 return (aPlace.isarea === 't' ? 'Polygon' : 'Point');
60 // fDistance is in meters
61 formatDistance: function(fDistanceMeters) {
62 if (fDistanceMeters < 1) return '0';
64 var formatted = (fDistanceMeters >= 1000) ?
65 Math.round(fDistanceMeters/1000, 1) + ' km' :
66 Math.round(fDistanceMeters, 0) + ' m';
68 return new Handlebars.SafeString(
69 '<abbr class="distance" title="' + fDistanceMeters + '">~' + formatted + '</abbr>'
72 // mark partial tokens (those starting with a space) with a star for readability
73 formatKeywordToken: function(sToken) {
74 return (sToken[0] == ' ' ? '*' : '') + Handlebars.escapeExpression(sToken);
76 // Any over 15 are invalid data in OSM anyway
77 formatAdminLevel: function(iLevel) {
78 return (iLevel < 15 ? iLevel : '');
80 formatMapIcon: function(sIcon) {
83 var url = sIcon.match(/png$/) ? Nominatim_Config.Images_Base_Url + '/' + sIcon : Nominatim_Config.Images_Base_Url + 'nominatim/images/mapicons/' + sIcon + '.n.32.png';
85 return new Handlebars.SafeString(
86 '<img class="mapicon" src="' + url + '" alt="' + sIcon + '"/>'
89 formatLabel: function(aPlace) {
90 if (aPlace.label) return aPlace.label;
92 function capitalize(s)
94 return s && s[0].toUpperCase() + s.slice(1);
97 if (aPlace.type && aPlace.type === 'yes') {
98 return capitalize(aPlace.class.replace(/_/g, ' '));
100 return capitalize(aPlace.type.replace(/_/g, ' '));
103 zoomLevels: function(iSelectedZoom) {
105 /* 0 */ 'Continent / Sea',
117 /* 12 */ 'Town / Village',
129 var select = $('<select>');
130 var option = jQuery('<option>', { value: '', text: '--'});
131 option.appendTo(select);
132 jQuery.each(aZoomLevels, function(i, title) {
133 var option = jQuery('<option>', { value: i, text: i + ' ' + title });
134 if (i == iSelectedZoom) option.attr('selected', 'selected');
135 option.appendTo(select);
137 return new Handlebars.SafeString(select.html());