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 function getIcon(aPlace) {
17 // equivalent to PHP Nominatim::ClassTypes::getIcon
18 // covers 83 of 214 available icon filenames, e.g. transport_roundabout_anticlockwise
19 // transport_rental_bicycle or place_of_worship_christian would need more data from
22 'boundary:administrative': 'poi_boundary_administrative',
23 'place:city': 'poi_place_city',
24 'place:town': 'poi_place_town',
25 'place:village': 'poi_place_village',
26 'place:hamlet': 'poi_place_village',
27 'place:suburb': 'poi_place_village',
28 'place:locality': 'poi_place_village',
29 'place:airport': 'transport_airport2',
30 'aeroway:aerodrome': 'transport_airport2',
31 'railway:station': 'transport_train_station2',
32 'amenity:place_of_worship': 'place_of_worship_unknown3',
33 'amenity:pub': 'food_pub',
34 'amenity:bar': 'food_bar',
35 'amenity:university': 'education_university',
36 'tourism:museum': 'tourist_museum',
37 'amenity:arts_centre': 'tourist_art_gallery2',
38 'tourism:zoo': 'tourist_zoo',
39 'tourism:theme_park': 'poi_point_of_interest',
40 'tourism:attraction': 'poi_point_of_interest',
41 'leisure:golf_course': 'sport_golf',
42 'historic:castle': 'tourist_castle',
43 'amenity:hospital': 'health_hospital',
44 'amenity:school': 'education_school',
45 'amenity:theatre': 'tourist_theatre',
46 'amenity:library': 'amenity_library',
47 'amenity:fire_station': 'amenity_firestation3',
48 'amenity:police': 'amenity_police2',
49 'amenity:bank': 'money_bank2',
50 'amenity:post_office': 'amenity_post_office',
51 'tourism:hotel': 'accommodation_hotel2',
52 'amenity:cinema': 'tourist_cinema',
53 'tourism:artwork': 'tourist_art_gallery2',
54 'historic:archaeological_site': 'tourist_archaeological2',
55 'amenity:doctors': 'health_doctors',
56 'leisure:sports_centre': 'sport_leisure_centre',
57 'leisure:swimming_pool': 'sport_swimming_outdoor',
58 'shop:supermarket': 'shopping_supermarket',
59 'shop:convenience': 'shopping_convenience',
60 'amenity:restaurant': 'food_restaurant',
61 'amenity:fast_food': 'food_fastfood',
62 'amenity:cafe': 'food_cafe',
63 'tourism:guest_house': 'accommodation_bed_and_breakfast',
64 'amenity:pharmacy': 'health_pharmacy_dispensing',
65 'amenity:fuel': 'transport_fuel',
66 'natural:peak': 'poi_peak',
67 'natural:wood': 'landuse_coniferous_and_deciduous',
68 'shop:bicycle': 'shopping_bicycle',
69 'shop:clothes': 'shopping_clothes',
70 'shop:hairdresser': 'shopping_hairdresser',
71 'shop:doityourself': 'shopping_diy',
72 'shop:estate_agent': 'shopping_estateagent2',
73 'shop:car': 'shopping_car',
74 'shop:garden_centre': 'shopping_garden_centre',
75 'shop:car_repair': 'shopping_car_repair',
76 'shop:bakery': 'shopping_bakery',
77 'shop:butcher': 'shopping_butcher',
78 'shop:apparel': 'shopping_clothes',
79 'shop:laundry': 'shopping_laundrette',
80 'shop:beverages': 'shopping_alcohol',
81 'shop:alcohol': 'shopping_alcohol',
82 'shop:optician': 'health_opticians',
83 'shop:chemist': 'health_pharmacy',
84 'shop:gallery': 'tourist_art_gallery2',
85 'shop:jewelry': 'shopping_jewelry',
86 'tourism:information': 'amenity_information',
87 'historic:ruins': 'tourist_ruin',
88 'amenity:college': 'education_school',
89 'historic:monument': 'tourist_monument',
90 'historic:memorial': 'tourist_monument',
91 'historic:mine': 'poi_mine',
92 'tourism:caravan_site': 'accommodation_caravan_park',
93 'amenity:bus_station': 'transport_bus_station',
94 'amenity:atm': 'money_atm2',
95 'tourism:viewpoint': 'tourist_view_point',
96 'tourism:guesthouse': 'accommodation_bed_and_breakfast',
97 'railway:tram': 'transport_tram_stop',
98 'amenity:courthouse': 'amenity_court',
99 'amenity:recycling': 'amenity_recycling',
100 'amenity:dentist': 'health_dentist',
101 'natural:beach': 'tourist_beach',
102 'railway:tram_stop': 'transport_tram_stop',
103 'amenity:prison': 'amenity_prison',
104 'highway:bus_stop': 'transport_bus_stop2'
107 var sCategoryPlace = aPlace.category + ':' + aPlace.type;
109 return aIcons[sCategoryPlace];
113 Handlebars.registerHelper({
114 formatOSMType: function (sType, bExcludeExternal) {
115 return formatOSMType(sType, bExcludeExternal);
117 shortOSMType: function (sType) {
118 if (sType === 'node') return 'N';
119 if (sType === 'way') return 'W';
120 if (sType === 'relation') return 'R';
123 // { osm_type: 'R', osm_id: 12345 }
124 // <a href="https://www.openstreetmap.org/relation/12345">relation 12345</a
125 osmLink: function (aPlace) {
126 if (!aPlace.osm_type) return '';
127 var sOSMType = formatOSMType(aPlace.osm_type, false);
128 if (!sOSMType) return '';
130 return new Handlebars.SafeString(
131 '<a href="https://www.openstreetmap.org/' + sOSMType + '/' + aPlace.osm_id + '">' + sOSMType + ' ' + aPlace.osm_id + '</a>'
134 /* en:London_Borough_of_Redbridge => https://en.wikipedia.org/wiki/London_Borough_of_Redbridge */
135 wikipediaLink: function (aPlace) {
136 if (!aPlace.calculated_wikipedia) return '';
138 var parts = aPlace.calculated_wikipedia.split(':', 2);
140 var sTitle = Handlebars.escapeExpression(aPlace.calculated_wikipedia);
141 var sLanguage = Handlebars.escapeExpression(parts[0]);
142 var sArticle = Handlebars.escapeExpression(parts[1]);
144 return new Handlebars.SafeString(
145 '<a href="https://' + sLanguage + '.wikipedia.org/wiki/' + sArticle + '" target="_blank">' + sTitle + '</a>'
148 // { osm_type: 'R', osm_id: 12345 }
149 // <a href="details.html?place_id=12345">details</a>
150 detailsLink: function (aFeature, sTitle) {
151 if (!aFeature) return '';
152 if (!aFeature.place_id) return '';
154 var sTitleEscaped = Handlebars.escapeExpression(sTitle || 'details >');
156 return new Handlebars.SafeString(
157 '<a href="details.html?place_id=' + aFeature.place_id + '">' + sTitleEscaped + '</a>'
160 detailsPermaLink: function (aFeature, sTitle) {
161 if (!aFeature) return '';
163 var sOSMType = formatOSMType(aFeature.osm_type, false);
164 if (!sOSMType) return '';
166 var sTitleEscaped = Handlebars.escapeExpression(sTitle || sOSMType + ' ' + aFeature.osm_id);
168 var sURL = 'details.html?osmtype=' + aFeature.osm_type + '&osmid=' + aFeature.osm_id;
169 if (aFeature.category) {
170 sURL = sURL + '&class=' + aFeature.category;
173 return new Handlebars.SafeString(
174 '<a href="' + sURL + '">' + sTitleEscaped + '</a>'
177 formatPlaceType: function (aPlace) {
178 var sOut = aPlace.class + ':' + aPlace.type;
179 if (aPlace.type && aPlace.type === 'administrative' && aPlace.place_type) {
180 sOut = sOut + ' (' + aPlace.place_type + ')';
182 return new Handlebars.SafeString(sOut);
184 coverageType: function (aPlace) {
185 return (aPlace.isarea ? 'Polygon' : 'Point');
187 // fDistance is in meters
188 formatDistance: function (fDistanceMeters) {
189 if (fDistanceMeters < 1) return '0';
191 var formatted = (fDistanceMeters >= 1000)
192 ? Math.round(fDistanceMeters / 1000, 1) + ' km'
193 : Math.round(fDistanceMeters, 0) + ' m';
195 return new Handlebars.SafeString(
196 '<abbr class="distance" title="' + fDistanceMeters + '">~' + formatted + '</abbr>'
199 // mark partial tokens (those starting with a space) with a star for readability
200 formatKeywordToken: function (sToken) {
201 return (sToken[0] === ' ' ? '*' : '') + Handlebars.escapeExpression(sToken);
203 // Any over 15 are invalid data in OSM anyway
204 formatAdminLevel: function (iLevel) {
205 return (iLevel < 15 ? iLevel : '');
207 formatMapIcon: function (aPlace) {
208 var sIcon = getIcon(aPlace);
210 if (!sIcon) return '';
212 var title = 'icon for ' + aPlace.category + ' ' + aPlace.type;
213 var url = get_config_value('Images_Base_Url') + sIcon + '.p.20.png';
215 return new Handlebars.SafeString(
216 '<img class="mapicon" src="' + url + '" alt="' + title + '"/>'
219 formatLabel: function (aPlace) {
220 if (aPlace.label) return aPlace.label;
222 function capitalize(s) {
223 return s && s[0].toUpperCase() + s.slice(1);
226 if (aPlace.type && aPlace.type === 'yes' && aPlace.class) {
227 return capitalize(aPlace.class.replace(/_/g, ' '));
230 return capitalize(aPlace.type.replace(/_/g, ' '));
234 formatSearchRank: function (iRank) {
236 // https://github.com/osm-search/Nominatim/blob/master/sql/functions.sql
237 // get_searchrank_label()
239 if (iRank < 2) return 'continent';
240 if (iRank < 4) return 'sea';
241 if (iRank < 8) return 'country';
242 if (iRank < 12) return 'state';
243 if (iRank < 16) return 'county';
244 if (iRank === 16) return 'city';
245 if (iRank === 17) return 'town / island';
246 if (iRank === 18) return 'village / hamlet';
247 if (iRank === 20) return 'suburb';
248 if (iRank === 21) return 'postcode area';
249 if (iRank === 22) return 'croft / farm / locality / islet';
250 if (iRank === 23) return 'postcode area';
251 if (iRank === 25) return 'postcode point';
252 if (iRank === 26) return 'street / major landmark';
253 if (iRank === 27) return 'minory street / path';
254 if (iRank === 28) return 'house / building';
255 return 'other: ' + iRank;
257 tooManyHierarchyLinesWarning: function (aPlace) {
258 if (!aPlace.hierarchy) return '';
260 var c = Object.keys(aPlace.hierarchy);
261 if (c < 500) return '';
263 return new Handlebars.SafeString(
264 '<p>There are more child objects which are not shown.</p>'
267 zoomLevels: function (iSelectedZoom) {
269 /* 0 */ 'Continent / Sea',
281 /* 12 */ 'Town / Village',
293 var select = $('<select>');
294 var option = jQuery('<option>', { value: '', text: '--' });
295 if (typeof (iSelectedZoom) === 'undefined') {
296 option.attr('selected', 'selected');
298 option.appendTo(select);
300 jQuery.each(aZoomLevels, function (i, title) {
301 option = jQuery('<option>', { value: i, text: i + ' ' + title });
302 if (i === iSelectedZoom) option.attr('selected', 'selected');
303 option.appendTo(select);
305 return new Handlebars.SafeString(select.html());