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 return new Handlebars.SafeString(
70 '<a href="details.html?osmtype=' + aFeature.osm_type + '&osmid=' + aFeature.osm_id + '&class=' + aFeature.category + '">' + sTitleEscaped + '</a>'
73 coverageType: function (aPlace) {
74 return (aPlace.isarea ? 'Polygon' : 'Point');
76 // fDistance is in meters
77 formatDistance: function (fDistanceMeters) {
78 if (fDistanceMeters < 1) return '0';
80 var formatted = (fDistanceMeters >= 1000)
81 ? Math.round(fDistanceMeters / 1000, 1) + ' km'
82 : Math.round(fDistanceMeters, 0) + ' m';
84 return new Handlebars.SafeString(
85 '<abbr class="distance" title="' + fDistanceMeters + '">~' + formatted + '</abbr>'
88 // mark partial tokens (those starting with a space) with a star for readability
89 formatKeywordToken: function (sToken) {
90 return (sToken[0] === ' ' ? '*' : '') + Handlebars.escapeExpression(sToken);
92 // Any over 15 are invalid data in OSM anyway
93 formatAdminLevel: function (iLevel) {
94 return (iLevel < 15 ? iLevel : '');
96 formatMapIcon: function (sIcon) {
100 if (!url.match(/^http/)) url = get_config_value('Images_Base_Url') + url;
102 return new Handlebars.SafeString(
103 '<img class="mapicon" src="' + url + '" alt="' + sIcon + '"/>'
106 formatLabel: function (aPlace) {
107 if (aPlace.label) return aPlace.label;
109 function capitalize(s) {
110 return s && s[0].toUpperCase() + s.slice(1);
113 if (aPlace.type && aPlace.type === 'yes') {
114 return capitalize(aPlace.class.replace(/_/g, ' '));
116 return capitalize(aPlace.type.replace(/_/g, ' '));
118 formatSearchRank: function (iRank) {
120 // https://github.com/openstreetmap/Nominatim/blob/master/sql/functions.sql
121 // get_searchrank_label()
123 if (iRank < 2) return 'continent';
124 if (iRank < 4) return 'sea';
125 if (iRank < 8) return 'country';
126 if (iRank < 12) return 'state';
127 if (iRank < 16) return 'county';
128 if (iRank === 16) return 'city';
129 if (iRank === 17) return 'town / island';
130 if (iRank === 18) return 'village / hamlet';
131 if (iRank === 20) return 'suburb';
132 if (iRank === 21) return 'postcode area';
133 if (iRank === 22) return 'croft / farm / locality / islet';
134 if (iRank === 23) return 'postcode area';
135 if (iRank === 25) return 'postcode point';
136 if (iRank === 26) return 'street / major landmark';
137 if (iRank === 27) return 'minory street / path';
138 if (iRank === 28) return 'house / building';
139 return 'other: ' + iRank;
141 tooManyHierarchyLinesWarning: function (aPlace) {
142 if (!aPlace.hierarchy) return;
145 for (var type in aPlace.hierarchy) {
146 c = c + type.length + 1;
150 return new Handlebars.SafeString(
151 '<p>There are more child objects which are not shown.</p>'
154 zoomLevels: function (iSelectedZoom) {
156 /* 0 */ 'Continent / Sea',
168 /* 12 */ 'Town / Village',
180 var select = $('<select>');
181 var option = jQuery('<option>', { value: '', text: '--' });
182 if (typeof (iSelectedZoom) === 'undefined') option.attr('selected', 'selected');
183 option.appendTo(select);
185 jQuery.each(aZoomLevels, function (i, title) {
186 option = jQuery('<option>', { value: i, text: i + ' ' + title });
187 if (i === iSelectedZoom) option.attr('selected', 'selected');
188 option.appendTo(select);
190 return new Handlebars.SafeString(select.html());