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="https://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="https://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.calculated_wikipedia) return '';
34 var parts = aPlace.calculated_wikipedia.split(':', 2);
36 var sTitle = Handlebars.escapeExpression(aPlace.calculated_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="details.html?place_id=12345">details</a>
46 detailsLink: function(aFeature, sTitle) {
47 if (!aFeature) return '';
48 if (!aFeature.place_id) return '';
50 sTitle = Handlebars.escapeExpression(sTitle || 'details >');
52 return new Handlebars.SafeString(
53 '<a href="details.html?place_id=' + aFeature.place_id + '">' + sTitle + '</a>'
56 detailsPermaLink: function(aFeature, sTitle) {
57 if (!aFeature) return '';
59 var sOSMType = formatOSMType(aFeature.osm_type, false);
60 if (!sOSMType) return '';
62 sTitle = Handlebars.escapeExpression(sTitle || sOSMType + ' ' + aFeature.osm_id);
64 return new Handlebars.SafeString(
65 '<a href="details.html?osmtype=' + aFeature.osm_type + '&osmid=' + aFeature.osm_id + '&class=' + aFeature.class + '">' + sTitle + '</a>'
68 coverageType: function(aPlace) {
69 return (aPlace.isarea ? 'Polygon' : 'Point');
71 // fDistance is in meters
72 formatDistance: function(fDistanceMeters) {
73 if (fDistanceMeters < 1) return '0';
75 var formatted = (fDistanceMeters >= 1000) ?
76 Math.round(fDistanceMeters/1000, 1) + ' km' :
77 Math.round(fDistanceMeters, 0) + ' m';
79 return new Handlebars.SafeString(
80 '<abbr class="distance" title="' + fDistanceMeters + '">~' + formatted + '</abbr>'
83 // mark partial tokens (those starting with a space) with a star for readability
84 formatKeywordToken: function(sToken) {
85 return (sToken[0] == ' ' ? '*' : '') + Handlebars.escapeExpression(sToken);
87 // Any over 15 are invalid data in OSM anyway
88 formatAdminLevel: function(iLevel) {
89 return (iLevel < 15 ? iLevel : '');
91 formatMapIcon: function(sIcon) {
94 var url = Nominatim_Config.Images_Base_Url + sIcon;
96 return new Handlebars.SafeString(
97 '<img class="mapicon" src="' + url + '" alt="' + sIcon + '"/>'
100 formatLabel: function(aPlace) {
101 if (aPlace.label) return aPlace.label;
103 function capitalize(s)
105 return s && s[0].toUpperCase() + s.slice(1);
108 if (aPlace.type && aPlace.type === 'yes') {
109 return capitalize(aPlace.class.replace(/_/g, ' '));
111 return capitalize(aPlace.type.replace(/_/g, ' '));
114 formatSearchRank: function(iRank) {
116 // https://github.com/openstreetmap/Nominatim/blob/master/sql/functions.sql
117 // get_searchrank_label()
121 } else if (iRank < 4) {
123 } else if (iRank < 8) {
125 } else if (iRank < 12) {
127 } else if (iRank < 16) {
129 } else if (iRank == 16) {
131 } else if (iRank == 17) {
132 return 'town / island';
133 } else if (iRank == 18) {
134 return 'village / hamlet';
135 } else if (iRank == 20) {
137 } else if (iRank == 21) {
138 return 'postcode area';
139 } else if (iRank == 22) {
140 return 'croft / farm / locality / islet';
141 } else if (iRank == 23) {
142 return 'postcode area';
143 } else if (iRank == 25) {
144 return 'postcode point';
145 } else if (iRank == 26) {
146 return 'street / major landmark';
147 } else if (iRank == 27) {
148 return 'minory street / path';
149 } else if (iRank == 28) {
150 return 'house / building';
152 return 'other: ' + iRank;
155 tooManyHierarchyLinesWarning: function(aPlace) {
156 if (!aPlace.hierarchy) return;
159 for (var type in aPlace.hierarchy) {
160 c = c + type.length+1;
164 return new Handlebars.SafeString(
165 '<p>There are more child objects which are not shown.</p>'
168 zoomLevels: function(iSelectedZoom) {
170 /* 0 */ 'Continent / Sea',
182 /* 12 */ 'Town / Village',
194 var select = $('<select>');
195 var option = jQuery('<option>', { value: '', text: '--'});
196 if (typeof(iSelectedZoom) === 'undefined') option.attr('selected', 'selected');
197 option.appendTo(select);
199 jQuery.each(aZoomLevels, function(i, title) {
200 var option = jQuery('<option>', { value: i, text: i + ' ' + title });
201 if (i == iSelectedZoom) option.attr('selected', 'selected');
202 option.appendTo(select);
204 return new Handlebars.SafeString(select.html());