3 function formatOSMType(sType, bExcludeExternal) {
4 if (sType === 'N') return 'node';
5 if (sType === 'W') return 'way';
6 if (sType === 'R') return 'relation';
8 if (!bExcludeExternal) return '';
10 if (sType === 'T') return 'way';
11 if (sType === 'I') return 'way';
16 Handlebars.registerHelper({
17 formatOSMType: function (sType, bExcludeExternal) {
18 return formatOSMType(sType, bExcludeExternal);
20 shortOSMType: function (sType) {
21 if (sType === 'node') return 'N';
22 if (sType === 'way') return 'W';
23 if (sType === 'relation') return 'R';
26 // { osm_type: 'R', osm_id: 12345 }
27 // <a href="https://www.openstreetmap.org/relation/12345">relation 12345</a
28 osmLink: function (aPlace) {
29 if (!aPlace.osm_type) return '';
30 var sOSMType = formatOSMType(aPlace.osm_type, false);
31 if (!sOSMType) return '';
33 return new Handlebars.SafeString(
34 '<a href="https://www.openstreetmap.org/' + sOSMType + '/' + aPlace.osm_id + '">' + sOSMType + ' ' + aPlace.osm_id + '</a>'
37 /* en:London_Borough_of_Redbridge => https://en.wikipedia.org/wiki/London_Borough_of_Redbridge */
38 wikipediaLink: function (aPlace) {
39 if (!aPlace.calculated_wikipedia) return '';
41 var parts = aPlace.calculated_wikipedia.split(':', 2);
43 var sTitle = Handlebars.escapeExpression(aPlace.calculated_wikipedia);
44 var sLanguage = Handlebars.escapeExpression(parts[0]);
45 var sArticle = Handlebars.escapeExpression(parts[1]);
47 return new Handlebars.SafeString(
48 '<a href="https://' + sLanguage + '.wikipedia.org/wiki/' + sArticle + '" target="_blank">' + sTitle + '</a>'
51 // { osm_type: 'R', osm_id: 12345 }
52 // <a href="details.html?place_id=12345">details</a>
53 detailsLink: function (aFeature, sTitle) {
54 if (!aFeature) return '';
55 if (!aFeature.place_id) return '';
57 var sTitleEscaped = Handlebars.escapeExpression(sTitle || 'details >');
59 return new Handlebars.SafeString(
60 '<a href="details.html?place_id=' + aFeature.place_id + '">' + sTitleEscaped + '</a>'
63 detailsPermaLink: function (aFeature, sTitle) {
64 if (!aFeature) return '';
66 var sOSMType = formatOSMType(aFeature.osm_type, false);
67 if (!sOSMType) return '';
69 var sTitleEscaped = Handlebars.escapeExpression(sTitle || sOSMType + ' ' + aFeature.osm_id);
71 var sURL = 'details.html?osmtype=' + aFeature.osm_type + '&osmid=' + aFeature.osm_id;
72 if (aFeature.category) {
73 sURL = sURL + '&class=' + aFeature.category;
76 return new Handlebars.SafeString(
77 '<a href="' + sURL + '">' + sTitleEscaped + '</a>'
80 formatPlaceType: function (aPlace) {
81 var sOut = aPlace.class + ':' + aPlace.type;
82 if (aPlace.type && aPlace.type === 'administrative' && aPlace.place_type) {
83 sOut = sOut + ' (' + aPlace.place_type + ')';
85 return new Handlebars.SafeString(sOut);
87 coverageType: function (aPlace) {
88 return (aPlace.isarea ? 'Polygon' : 'Point');
90 // fDistance is in meters
91 formatDistance: function (fDistanceMeters) {
92 if (fDistanceMeters < 1) return '0';
94 var formatted = (fDistanceMeters >= 1000)
95 ? Math.round(fDistanceMeters / 1000, 1) + ' km'
96 : Math.round(fDistanceMeters, 0) + ' m';
98 return new Handlebars.SafeString(
99 '<abbr class="distance" title="' + fDistanceMeters + '">~' + formatted + '</abbr>'
102 // mark partial tokens (those starting with a space) with a star for readability
103 formatKeywordToken: function (sToken) {
104 return (sToken[0] === ' ' ? '*' : '') + Handlebars.escapeExpression(sToken);
106 // Any over 15 are invalid data in OSM anyway
107 formatAdminLevel: function (iLevel) {
108 return (iLevel < 15 ? iLevel : '');
110 formatMapIcon: function (sIcon) {
111 if (!sIcon) return '';
114 if (!url.match(/^http/)) url = get_config_value('Images_Base_Url') + url;
116 return new Handlebars.SafeString(
117 '<img class="mapicon" src="' + url + '" alt="' + sIcon + '"/>'
120 formatLabel: function (aPlace) {
121 if (aPlace.label) return aPlace.label;
123 function capitalize(s) {
124 return s && s[0].toUpperCase() + s.slice(1);
127 if (aPlace.type && aPlace.type === 'yes' && aPlace.class) {
128 return capitalize(aPlace.class.replace(/_/g, ' '));
131 return capitalize(aPlace.type.replace(/_/g, ' '));
135 formatSearchRank: function (iRank) {
137 // https://github.com/osm-search/Nominatim/blob/master/sql/functions.sql
138 // get_searchrank_label()
140 if (iRank < 2) return 'continent';
141 if (iRank < 4) return 'sea';
142 if (iRank < 8) return 'country';
143 if (iRank < 12) return 'state';
144 if (iRank < 16) return 'county';
145 if (iRank === 16) return 'city';
146 if (iRank === 17) return 'town / island';
147 if (iRank === 18) return 'village / hamlet';
148 if (iRank === 20) return 'suburb';
149 if (iRank === 21) return 'postcode area';
150 if (iRank === 22) return 'croft / farm / locality / islet';
151 if (iRank === 23) return 'postcode area';
152 if (iRank === 25) return 'postcode point';
153 if (iRank === 26) return 'street / major landmark';
154 if (iRank === 27) return 'minory street / path';
155 if (iRank === 28) return 'house / building';
156 return 'other: ' + iRank;
158 tooManyHierarchyLinesWarning: function (aPlace) {
159 if (!aPlace.hierarchy) return '';
161 var c = Object.keys(aPlace.hierarchy);
162 if (c < 500) return '';
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') {
197 option.attr('selected', 'selected');
199 option.appendTo(select);
201 jQuery.each(aZoomLevels, function (i, title) {
202 option = jQuery('<option>', { value: i, text: i + ' ' + title });
203 if (i === iSelectedZoom) option.attr('selected', 'selected');
204 option.appendTo(select);
206 return new Handlebars.SafeString(select.html());