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 shortOSMType: function (sType) {
18 if (sType === 'node') return 'N';
19 if (sType === 'way') return 'W';
20 if (sType === 'relation') return 'R';
23 // { osm_type: 'R', osm_id: 12345 }
24 // <a href="https://www.openstreetmap.org/relation/12345">relation 12345</a
25 osmLink: function (aPlace) {
26 if (!aPlace.osm_type) return '';
27 var sOSMType = formatOSMType(aPlace.osm_type, false);
28 if (!sOSMType) return '';
30 return new Handlebars.SafeString(
31 '<a href="https://www.openstreetmap.org/' + sOSMType + '/' + aPlace.osm_id + '">' + sOSMType + ' ' + aPlace.osm_id + '</a>'
34 /* en:London_Borough_of_Redbridge => https://en.wikipedia.org/wiki/London_Borough_of_Redbridge */
35 wikipediaLink: function (aPlace) {
36 if (!aPlace.calculated_wikipedia) return '';
38 var parts = aPlace.calculated_wikipedia.split(':', 2);
40 var sTitle = Handlebars.escapeExpression(aPlace.calculated_wikipedia);
41 var sLanguage = Handlebars.escapeExpression(parts[0]);
42 var sArticle = Handlebars.escapeExpression(parts[1]);
44 return new Handlebars.SafeString(
45 '<a href="https://' + sLanguage + '.wikipedia.org/wiki/' + sArticle + '" target="_blank">' + sTitle + '</a>'
48 // { osm_type: 'R', osm_id: 12345 }
49 // <a href="details.html?place_id=12345">details</a>
50 detailsLink: function (aFeature, sTitle) {
51 if (!aFeature) return '';
52 if (!aFeature.place_id) return '';
54 var sTitleEscaped = Handlebars.escapeExpression(sTitle || 'details >');
56 return new Handlebars.SafeString(
57 '<a href="details.html?place_id=' + aFeature.place_id + '">' + sTitleEscaped + '</a>'
60 detailsPermaLink: function (aFeature, sTitle) {
61 if (!aFeature) return '';
63 var sOSMType = formatOSMType(aFeature.osm_type, false);
64 if (!sOSMType) return '';
66 var sTitleEscaped = Handlebars.escapeExpression(sTitle || sOSMType + ' ' + aFeature.osm_id);
68 var sURL = 'details.html?osmtype=' + aFeature.osm_type + '&osmid=' + aFeature.osm_id;
69 if (aFeature.category) {
70 sURL = sURL + '&class=' + aFeature.category;
73 return new Handlebars.SafeString(
74 '<a href="' + sURL + '">' + sTitleEscaped + '</a>'
77 formatPlaceType: function (aPlace) {
78 var sOut = aPlace.class + ':' + aPlace.type;
79 if (aPlace.type && aPlace.type === 'administrative' && aPlace.place_type) {
80 sOut = sOut + ' (' + aPlace.place_type + ')';
82 return new Handlebars.SafeString(sOut);
84 coverageType: function (aPlace) {
85 return (aPlace.isarea ? 'Polygon' : 'Point');
87 // fDistance is in meters
88 formatDistance: function (fDistanceMeters) {
89 if (fDistanceMeters < 1) return '0';
91 var formatted = (fDistanceMeters >= 1000)
92 ? Math.round(fDistanceMeters / 1000, 1) + ' km'
93 : Math.round(fDistanceMeters, 0) + ' m';
95 return new Handlebars.SafeString(
96 '<abbr class="distance" title="' + fDistanceMeters + '">~' + formatted + '</abbr>'
99 // mark partial tokens (those starting with a space) with a star for readability
100 formatKeywordToken: function (sToken) {
101 return (sToken[0] === ' ' ? '*' : '') + Handlebars.escapeExpression(sToken);
103 // Any over 15 are invalid data in OSM anyway
104 formatAdminLevel: function (iLevel) {
105 return (iLevel < 15 ? iLevel : '');
107 formatMapIcon: function (sIcon) {
108 if (!sIcon) return '';
111 if (!url.match(/^http/)) url = get_config_value('Images_Base_Url') + url;
113 return new Handlebars.SafeString(
114 '<img class="mapicon" src="' + url + '" alt="' + sIcon + '"/>'
117 formatLabel: function (aPlace) {
118 if (aPlace.label) return aPlace.label;
120 function capitalize(s) {
121 return s && s[0].toUpperCase() + s.slice(1);
124 if (aPlace.type && aPlace.type === 'yes' && aPlace.class) {
125 return capitalize(aPlace.class.replace(/_/g, ' '));
128 return capitalize(aPlace.type.replace(/_/g, ' '));
132 formatSearchRank: function (iRank) {
134 // https://github.com/osm-search/Nominatim/blob/master/sql/functions.sql
135 // get_searchrank_label()
137 if (iRank < 2) return 'continent';
138 if (iRank < 4) return 'sea';
139 if (iRank < 8) return 'country';
140 if (iRank < 12) return 'state';
141 if (iRank < 16) return 'county';
142 if (iRank === 16) return 'city';
143 if (iRank === 17) return 'town / island';
144 if (iRank === 18) return 'village / hamlet';
145 if (iRank === 20) return 'suburb';
146 if (iRank === 21) return 'postcode area';
147 if (iRank === 22) return 'croft / farm / locality / islet';
148 if (iRank === 23) return 'postcode area';
149 if (iRank === 25) return 'postcode point';
150 if (iRank === 26) return 'street / major landmark';
151 if (iRank === 27) return 'minory street / path';
152 if (iRank === 28) return 'house / building';
153 return 'other: ' + iRank;
155 tooManyHierarchyLinesWarning: function (aPlace) {
156 if (!aPlace.hierarchy) return '';
158 var c = Object.keys(aPlace.hierarchy);
159 if (c < 500) return '';
161 return new Handlebars.SafeString(
162 '<p>There are more child objects which are not shown.</p>'
165 zoomLevels: function (iSelectedZoom) {
167 /* 0 */ 'Continent / Sea',
179 /* 12 */ 'Town / Village',
191 var select = $('<select>');
192 var option = jQuery('<option>', { value: '', text: '--' });
193 if (typeof (iSelectedZoom) === 'undefined') {
194 option.attr('selected', 'selected');
196 option.appendTo(select);
198 jQuery.each(aZoomLevels, function (i, title) {
199 option = jQuery('<option>', { value: i, text: i + ' ' + title });
200 if (i === iSelectedZoom) option.attr('selected', 'selected');
201 option.appendTo(select);
203 return new Handlebars.SafeString(select.html());