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 isaddresses_unused: function (aAddressLine) {
16 return ((aAddressLine.isaddress && aAddressLine.isaddress === 'f') ? 'notused' : '');
18 // { osm_type: 'R', osm_id: 12345 }
19 // <a href="https://www.openstreetmap.org/relation/12345">relation 12345</a
20 osmLink: function (aPlace) {
21 if (!aPlace.osm_type) return '';
22 var sOSMType = formatOSMType(aPlace.osm_type, false);
23 if (!sOSMType) return '';
25 return new Handlebars.SafeString(
26 '<a href="https://www.openstreetmap.org/' + sOSMType + '/' + aPlace.osm_id + '">' + sOSMType + ' ' + aPlace.osm_id + '</a>'
29 /* en:London_Borough_of_Redbridge => https://en.wikipedia.org/wiki/London_Borough_of_Redbridge */
30 wikipediaLink: function (aPlace) {
31 if (!aPlace.calculated_wikipedia) return '';
33 var parts = aPlace.calculated_wikipedia.split(':', 2);
35 var sTitle = Handlebars.escapeExpression(aPlace.calculated_wikipedia);
36 var sLanguage = Handlebars.escapeExpression(parts[0]);
37 var sArticle = Handlebars.escapeExpression(parts[1]);
39 return new Handlebars.SafeString(
40 '<a href="https://' + sLanguage + '.wikipedia.org/wiki/' + sArticle + '" target="_blank">' + sTitle + '</a>'
43 // { osm_type: 'R', osm_id: 12345 }
44 // <a href="details.html?place_id=12345">details</a>
45 detailsLink: function (aFeature, sTitle) {
46 if (!aFeature) return '';
47 if (!aFeature.place_id) return '';
49 var sTitleEscaped = Handlebars.escapeExpression(sTitle || 'details >');
51 return new Handlebars.SafeString(
52 '<a href="details.html?place_id=' + aFeature.place_id + '">' + sTitleEscaped + '</a>'
55 detailsPermaLink: function (aFeature, sTitle) {
56 if (!aFeature) return '';
58 var sOSMType = formatOSMType(aFeature.osm_type, false);
59 if (!sOSMType) return '';
61 var sTitleEscaped = Handlebars.escapeExpression(sTitle || sOSMType + ' ' + aFeature.osm_id);
63 return new Handlebars.SafeString(
64 '<a href="details.html?osmtype=' + aFeature.osm_type + '&osmid=' + aFeature.osm_id + '&class=' + aFeature.category + '">' + sTitleEscaped + '</a>'
67 coverageType: function (aPlace) {
68 return (aPlace.isarea ? 'Polygon' : 'Point');
70 // fDistance is in meters
71 formatDistance: function (fDistanceMeters) {
72 if (fDistanceMeters < 1) return '0';
74 var formatted = (fDistanceMeters >= 1000)
75 ? Math.round(fDistanceMeters / 1000, 1) + ' km'
76 : Math.round(fDistanceMeters, 0) + ' m';
78 return new Handlebars.SafeString(
79 '<abbr class="distance" title="' + fDistanceMeters + '">~' + formatted + '</abbr>'
82 // mark partial tokens (those starting with a space) with a star for readability
83 formatKeywordToken: function (sToken) {
84 return (sToken[0] === ' ' ? '*' : '') + Handlebars.escapeExpression(sToken);
86 // Any over 15 are invalid data in OSM anyway
87 formatAdminLevel: function (iLevel) {
88 return (iLevel < 15 ? iLevel : '');
90 formatMapIcon: function (sIcon) {
94 if (!url.match(/^http/)) url = get_config_value('Images_Base_Url') + url;
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) {
104 return s && s[0].toUpperCase() + s.slice(1);
107 if (aPlace.type && aPlace.type === 'yes') {
108 return capitalize(aPlace.class.replace(/_/g, ' '));
110 return capitalize(aPlace.type.replace(/_/g, ' '));
112 formatSearchRank: function (iRank) {
114 // https://github.com/openstreetmap/Nominatim/blob/master/sql/functions.sql
115 // get_searchrank_label()
117 if (iRank < 2) return 'continent';
118 if (iRank < 4) return 'sea';
119 if (iRank < 8) return 'country';
120 if (iRank < 12) return 'state';
121 if (iRank < 16) return 'county';
122 if (iRank === 16) return 'city';
123 if (iRank === 17) return 'town / island';
124 if (iRank === 18) return 'village / hamlet';
125 if (iRank === 20) return 'suburb';
126 if (iRank === 21) return 'postcode area';
127 if (iRank === 22) return 'croft / farm / locality / islet';
128 if (iRank === 23) return 'postcode area';
129 if (iRank === 25) return 'postcode point';
130 if (iRank === 26) return 'street / major landmark';
131 if (iRank === 27) return 'minory street / path';
132 if (iRank === 28) return 'house / building';
133 return 'other: ' + iRank;
135 tooManyHierarchyLinesWarning: function (aPlace) {
136 if (!aPlace.hierarchy) return;
139 for (var type in aPlace.hierarchy) {
140 c = c + type.length + 1;
144 return new Handlebars.SafeString(
145 '<p>There are more child objects which are not shown.</p>'
148 zoomLevels: function (iSelectedZoom) {
150 /* 0 */ 'Continent / Sea',
162 /* 12 */ 'Town / Village',
174 var select = $('<select>');
175 var option = jQuery('<option>', { value: '', text: '--' });
176 if (typeof (iSelectedZoom) === 'undefined') option.attr('selected', 'selected');
177 option.appendTo(select);
179 jQuery.each(aZoomLevels, function (i, title) {
180 option = jQuery('<option>', { value: i, text: i + ' ' + title });
181 if (i === iSelectedZoom) option.attr('selected', 'selected');
182 option.appendTo(select);
184 return new Handlebars.SafeString(select.html());