1 function formatOSMType(sType, bExcludeExternal) {
2 if (sType === 'N') return 'node';
3 if (sType === 'W') return 'way';
4 if (sType === 'R') return 'relation';
6 if (!bExcludeExternal) return '';
8 if (sType === 'T') return 'way';
9 if (sType === 'I') return 'way';
14 Handlebars.registerHelper({
15 shortOSMType: function(sType) {
16 if (sType === 'node') return 'N';
17 if (sType === 'way') return 'W';
18 if (sType === 'relation') return 'R';
21 isaddresses_unused: function (aAddressLine) {
22 return ((aAddressLine.isaddress && aAddressLine.isaddress === 'f') ? 'notused' : '');
24 // { osm_type: 'R', osm_id: 12345 }
25 // <a href="https://www.openstreetmap.org/relation/12345">relation 12345</a
26 osmLink: function (aPlace) {
27 if (!aPlace.osm_type) return '';
28 var sOSMType = formatOSMType(aPlace.osm_type, false);
29 if (!sOSMType) return '';
31 return new Handlebars.SafeString(
32 '<a href="https://www.openstreetmap.org/' + sOSMType + '/' + aPlace.osm_id + '">' + sOSMType + ' ' + aPlace.osm_id + '</a>'
35 /* en:London_Borough_of_Redbridge => https://en.wikipedia.org/wiki/London_Borough_of_Redbridge */
36 wikipediaLink: function (aPlace) {
37 if (!aPlace.calculated_wikipedia) return '';
39 var parts = aPlace.calculated_wikipedia.split(':', 2);
41 var sTitle = Handlebars.escapeExpression(aPlace.calculated_wikipedia);
42 var sLanguage = Handlebars.escapeExpression(parts[0]);
43 var sArticle = Handlebars.escapeExpression(parts[1]);
45 return new Handlebars.SafeString(
46 '<a href="https://' + sLanguage + '.wikipedia.org/wiki/' + sArticle + '" target="_blank">' + sTitle + '</a>'
49 // { osm_type: 'R', osm_id: 12345 }
50 // <a href="details.html?place_id=12345">details</a>
51 detailsLink: function (aFeature, sTitle) {
52 if (!aFeature) return '';
53 if (!aFeature.place_id) return '';
55 var sTitleEscaped = Handlebars.escapeExpression(sTitle || 'details >');
57 return new Handlebars.SafeString(
58 '<a href="details.html?place_id=' + aFeature.place_id + '">' + sTitleEscaped + '</a>'
61 detailsPermaLink: function (aFeature, sTitle) {
62 if (!aFeature) return '';
64 var sOSMType = formatOSMType(aFeature.osm_type, false);
65 if (!sOSMType) return '';
67 var sTitleEscaped = Handlebars.escapeExpression(sTitle || sOSMType + ' ' + aFeature.osm_id);
69 var sURL = 'details.html?osmtype=' + aFeature.osm_type + '&osmid=' + aFeature.osm_id;
70 if (aFeature.category) {
71 sURL = sURL + '&class=' + aFeature.category;
74 return new Handlebars.SafeString(
75 '<a href="' + sURL + '">' + sTitleEscaped + '</a>'
78 coverageType: function (aPlace) {
79 return (aPlace.isarea ? 'Polygon' : 'Point');
81 // fDistance is in meters
82 formatDistance: function (fDistanceMeters) {
83 if (fDistanceMeters < 1) return '0';
85 var formatted = (fDistanceMeters >= 1000)
86 ? Math.round(fDistanceMeters / 1000, 1) + ' km'
87 : Math.round(fDistanceMeters, 0) + ' m';
89 return new Handlebars.SafeString(
90 '<abbr class="distance" title="' + fDistanceMeters + '">~' + formatted + '</abbr>'
93 // mark partial tokens (those starting with a space) with a star for readability
94 formatKeywordToken: function (sToken) {
95 return (sToken[0] === ' ' ? '*' : '') + Handlebars.escapeExpression(sToken);
97 // Any over 15 are invalid data in OSM anyway
98 formatAdminLevel: function (iLevel) {
99 return (iLevel < 15 ? iLevel : '');
101 formatMapIcon: function (sIcon) {
105 if (!url.match(/^http/)) url = get_config_value('Images_Base_Url') + url;
107 return new Handlebars.SafeString(
108 '<img class="mapicon" src="' + url + '" alt="' + sIcon + '"/>'
111 formatLabel: function (aPlace) {
112 if (aPlace.label) return aPlace.label;
114 function capitalize(s) {
115 return s && s[0].toUpperCase() + s.slice(1);
118 if (aPlace.type && aPlace.type === 'yes' && aPlace.class) {
119 return capitalize(aPlace.class.replace(/_/g, ' '));
120 } else if (aPlace.type) {
121 return capitalize(aPlace.type.replace(/_/g, ' '));
125 formatSearchRank: function (iRank) {
127 // https://github.com/openstreetmap/Nominatim/blob/master/sql/functions.sql
128 // get_searchrank_label()
130 if (iRank < 2) return 'continent';
131 if (iRank < 4) return 'sea';
132 if (iRank < 8) return 'country';
133 if (iRank < 12) return 'state';
134 if (iRank < 16) return 'county';
135 if (iRank === 16) return 'city';
136 if (iRank === 17) return 'town / island';
137 if (iRank === 18) return 'village / hamlet';
138 if (iRank === 20) return 'suburb';
139 if (iRank === 21) return 'postcode area';
140 if (iRank === 22) return 'croft / farm / locality / islet';
141 if (iRank === 23) return 'postcode area';
142 if (iRank === 25) return 'postcode point';
143 if (iRank === 26) return 'street / major landmark';
144 if (iRank === 27) return 'minory street / path';
145 if (iRank === 28) return 'house / building';
146 return 'other: ' + iRank;
148 tooManyHierarchyLinesWarning: function (aPlace) {
149 if (!aPlace.hierarchy) return;
152 for (var type in aPlace.hierarchy) {
153 c = c + type.length + 1;
157 return new Handlebars.SafeString(
158 '<p>There are more child objects which are not shown.</p>'
161 zoomLevels: function (iSelectedZoom) {
163 /* 0 */ 'Continent / Sea',
175 /* 12 */ 'Town / Village',
187 var select = $('<select>');
188 var option = jQuery('<option>', { value: '', text: '--' });
189 if (typeof (iSelectedZoom) === 'undefined') option.attr('selected', 'selected');
190 option.appendTo(select);
192 jQuery.each(aZoomLevels, function (i, title) {
193 option = jQuery('<option>', { value: i, text: i + ' ' + title });
194 if (i === iSelectedZoom) option.attr('selected', 'selected');
195 option.appendTo(select);
197 return new Handlebars.SafeString(select.html());