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