]> git.openstreetmap.org Git - nominatim-ui.git/commitdiff
generate mapicon URLs from place category and type
authormarc tobias <mtmail@gmx.net>
Mon, 18 May 2020 22:54:38 +0000 (00:54 +0200)
committermarc tobias <mtmail@gmx.net>
Mon, 18 May 2020 22:54:38 +0000 (00:54 +0200)
dist/details.html
dist/detailspage.hbs
dist/handlebar_helpers.js
dist/reverse.html
dist/reversepage.hbs
dist/search.html
dist/searchpage.hbs
src/handlebar_helpers.js
src/templates/detailspage.hbs
src/templates/reversepage.hbs
src/templates/searchpage.hbs

index 1509fb4e02d781762c24c1faee95bda7f81395ce..3d0c57e043776ecaf1fd4fc74d34c3832c914f60 100644 (file)
       </h1>
     </div>
     <div class="col-sm-2 text-right">
-      {{formatMapIcon aPlace.icon}}
+      {{formatMapIcon aPlace}}
     </div>
   </div>
   <div class="row">
index 1b394324b91ddc82b7483ee3b4549f2d692966ed..48ecde95c3aabf3d3609bc0748809a4e363e3360 100644 (file)
@@ -44,7 +44,7 @@
       </h1>
     </div>
     <div class="col-sm-2 text-right">
-      {{formatMapIcon aPlace.icon}}
+      {{formatMapIcon aPlace}}
     </div>
   </div>
   <div class="row">
index 260525f8ebf3f7c01c3a3970014fbd310415791f..4d1889f324530b13371c7c3bca0930a8cf363c0e 100644 (file)
@@ -13,6 +13,103 @@ function formatOSMType(sType, bExcludeExternal) {
   return '';
 }
 
+function getIcon(aPlace) {
+  // equivalent to PHP Nominatim::ClassTypes::getIcon
+  // covers 83 of 214 available icon filenames, e.g. transport_roundabout_anticlockwise
+  // transport_rental_bicycle or place_of_worship_christian would need more data from
+  // the place.
+  var aIcons = {
+    'boundary:administrative': 'poi_boundary_administrative',
+    'place:city': 'poi_place_city',
+    'place:town': 'poi_place_town',
+    'place:village': 'poi_place_village',
+    'place:hamlet': 'poi_place_village',
+    'place:suburb': 'poi_place_village',
+    'place:locality': 'poi_place_village',
+    'place:airport': 'transport_airport2',
+    'aeroway:aerodrome': 'transport_airport2',
+    'railway:station': 'transport_train_station2',
+    'amenity:place_of_worship': 'place_of_worship_unknown3',
+    'amenity:pub': 'food_pub',
+    'amenity:bar': 'food_bar',
+    'amenity:university': 'education_university',
+    'tourism:museum': 'tourist_museum',
+    'amenity:arts_centre': 'tourist_art_gallery2',
+    'tourism:zoo': 'tourist_zoo',
+    'tourism:theme_park': 'poi_point_of_interest',
+    'tourism:attraction': 'poi_point_of_interest',
+    'leisure:golf_course': 'sport_golf',
+    'historic:castle': 'tourist_castle',
+    'amenity:hospital': 'health_hospital',
+    'amenity:school': 'education_school',
+    'amenity:theatre': 'tourist_theatre',
+    'amenity:library': 'amenity_library',
+    'amenity:fire_station': 'amenity_firestation3',
+    'amenity:police': 'amenity_police2',
+    'amenity:bank': 'money_bank2',
+    'amenity:post_office': 'amenity_post_office',
+    'tourism:hotel': 'accommodation_hotel2',
+    'amenity:cinema': 'tourist_cinema',
+    'tourism:artwork': 'tourist_art_gallery2',
+    'historic:archaeological_site': 'tourist_archaeological2',
+    'amenity:doctors': 'health_doctors',
+    'leisure:sports_centre': 'sport_leisure_centre',
+    'leisure:swimming_pool': 'sport_swimming_outdoor',
+    'shop:supermarket': 'shopping_supermarket',
+    'shop:convenience': 'shopping_convenience',
+    'amenity:restaurant': 'food_restaurant',
+    'amenity:fast_food': 'food_fastfood',
+    'amenity:cafe': 'food_cafe',
+    'tourism:guest_house': 'accommodation_bed_and_breakfast',
+    'amenity:pharmacy': 'health_pharmacy_dispensing',
+    'amenity:fuel': 'transport_fuel',
+    'natural:peak': 'poi_peak',
+    'natural:wood': 'landuse_coniferous_and_deciduous',
+    'shop:bicycle': 'shopping_bicycle',
+    'shop:clothes': 'shopping_clothes',
+    'shop:hairdresser': 'shopping_hairdresser',
+    'shop:doityourself': 'shopping_diy',
+    'shop:estate_agent': 'shopping_estateagent2',
+    'shop:car': 'shopping_car',
+    'shop:garden_centre': 'shopping_garden_centre',
+    'shop:car_repair': 'shopping_car_repair',
+    'shop:bakery': 'shopping_bakery',
+    'shop:butcher': 'shopping_butcher',
+    'shop:apparel': 'shopping_clothes',
+    'shop:laundry': 'shopping_laundrette',
+    'shop:beverages': 'shopping_alcohol',
+    'shop:alcohol': 'shopping_alcohol',
+    'shop:optician': 'health_opticians',
+    'shop:chemist': 'health_pharmacy',
+    'shop:gallery': 'tourist_art_gallery2',
+    'shop:jewelry': 'shopping_jewelry',
+    'tourism:information': 'amenity_information',
+    'historic:ruins': 'tourist_ruin',
+    'amenity:college': 'education_school',
+    'historic:monument': 'tourist_monument',
+    'historic:memorial': 'tourist_monument',
+    'historic:mine': 'poi_mine',
+    'tourism:caravan_site': 'accommodation_caravan_park',
+    'amenity:bus_station': 'transport_bus_station',
+    'amenity:atm': 'money_atm2',
+    'tourism:viewpoint': 'tourist_view_point',
+    'tourism:guesthouse': 'accommodation_bed_and_breakfast',
+    'railway:tram': 'transport_tram_stop',
+    'amenity:courthouse': 'amenity_court',
+    'amenity:recycling': 'amenity_recycling',
+    'amenity:dentist': 'health_dentist',
+    'natural:beach': 'tourist_beach',
+    'railway:tram_stop': 'transport_tram_stop',
+    'amenity:prison': 'amenity_prison',
+    'highway:bus_stop': 'transport_bus_stop2'
+  };
+
+  var sCategoryPlace = aPlace.category + ':' + aPlace.type;
+
+  return aIcons[sCategoryPlace];
+}
+
+
 Handlebars.registerHelper({
   formatOSMType: function (sType, bExcludeExternal) {
     return formatOSMType(sType, bExcludeExternal);
@@ -107,14 +204,13 @@ Handlebars.registerHelper({
   formatAdminLevel: function (iLevel) {
     return (iLevel < 15 ? iLevel : '');
   },
-  formatMapIcon: function (sIcon) {
+  formatMapIcon: function (aPlace) {
+    var sIcon = getIcon(aPlace);
+
     if (!sIcon) return '';
 
-    // https://nominatim.openstreetmap.org/images/mapicons/poi_boundary_administrative.p.20.png
-    // => poi boundary administrative
-    var title = sIcon.replace(/.+\//, '').replace(/\..+/, '').replace(/_/g, ' ');
-    // => http://localhost/mapicons/poi_boundary_administrative.p.20.png
-    var url = get_config_value('Images_Base_Url') + sIcon.replace(/.+\//, '');
+    var title = 'icon for ' + aPlace.category + ' ' + aPlace.type;
+    var url = get_config_value('Images_Base_Url') + sIcon + '.p.20.png';
 
     return new Handlebars.SafeString(
       '<img class="mapicon" src="' + url + '" alt="' + title + '"/>'
index 630c15898c2d171e137510531194d339256fd9c2..642b330700fbb75274ccd83fd17b670590535641 100644 (file)
 
 {{#*inline "partial_one_result"}}
   <div class="result" data-position="{{iResNum}}">
-    {{#if aResult.icon}}
-      <img src="{{env.Images_Base_Url}}{{aResult.icon}}" />
-      {{!-- {{formatMapIcon aResult.icon}} --}}
-    {{/if}}
+    {{formatMapIcon aResult}}
 
     <span class="name">{{aResult.display_name}}</span>
     <span class="type">{{formatLabel aResult}}</span>
index 280a28255cde566c2fc1615690f007ccd7f4f670..ba80e7445c7dcf104af05e6a9c812fd8a0a39a7a 100644 (file)
@@ -1,10 +1,7 @@
 
 {{#*inline "partial_one_result"}}
   <div class="result" data-position="{{iResNum}}">
-    {{#if aResult.icon}}
-      <img src="{{env.Images_Base_Url}}{{aResult.icon}}" />
-      {{!-- {{formatMapIcon aResult.icon}} --}}
-    {{/if}}
+    {{formatMapIcon aResult}}
 
     <span class="name">{{aResult.display_name}}</span>
     <span class="type">{{formatLabel aResult}}</span>
index a8a36d91c1dcc17f80464994b31a8a7d6f42ceac..b3e2b032ae5d05da845d05337700439c6a88be9d 100644 (file)
 <script id="searchpage-template" type="text/x-handlebars-template">
 {{#*inline "partial_one_result"}}
   <div class="result" data-position="{{iResNum}}">
-    {{#if aResult.icon}}
-      {{!-- <img src="{{env.Images_Base_Url}}{{aResult.icon}}" /> --}}
-      {{formatMapIcon aResult.icon}}
-    {{/if}}
+    {{formatMapIcon aResult}}
 
     <span class="name">{{aResult.display_name}}</span>
     <span class="type">({{formatLabel aResult}})</span>
index 1d3c92ca49a1fd654c48ea1b5429e94b04526953..ae13597009ce9f7353834d6b0aeeb6cdcf689af3 100644 (file)
@@ -1,9 +1,6 @@
 {{#*inline "partial_one_result"}}
   <div class="result" data-position="{{iResNum}}">
-    {{#if aResult.icon}}
-      {{!-- <img src="{{env.Images_Base_Url}}{{aResult.icon}}" /> --}}
-      {{formatMapIcon aResult.icon}}
-    {{/if}}
+    {{formatMapIcon aResult}}
 
     <span class="name">{{aResult.display_name}}</span>
     <span class="type">({{formatLabel aResult}})</span>
index 260525f8ebf3f7c01c3a3970014fbd310415791f..4d1889f324530b13371c7c3bca0930a8cf363c0e 100644 (file)
@@ -13,6 +13,103 @@ function formatOSMType(sType, bExcludeExternal) {
   return '';
 }
 
+function getIcon(aPlace) {
+  // equivalent to PHP Nominatim::ClassTypes::getIcon
+  // covers 83 of 214 available icon filenames, e.g. transport_roundabout_anticlockwise
+  // transport_rental_bicycle or place_of_worship_christian would need more data from
+  // the place.
+  var aIcons = {
+    'boundary:administrative': 'poi_boundary_administrative',
+    'place:city': 'poi_place_city',
+    'place:town': 'poi_place_town',
+    'place:village': 'poi_place_village',
+    'place:hamlet': 'poi_place_village',
+    'place:suburb': 'poi_place_village',
+    'place:locality': 'poi_place_village',
+    'place:airport': 'transport_airport2',
+    'aeroway:aerodrome': 'transport_airport2',
+    'railway:station': 'transport_train_station2',
+    'amenity:place_of_worship': 'place_of_worship_unknown3',
+    'amenity:pub': 'food_pub',
+    'amenity:bar': 'food_bar',
+    'amenity:university': 'education_university',
+    'tourism:museum': 'tourist_museum',
+    'amenity:arts_centre': 'tourist_art_gallery2',
+    'tourism:zoo': 'tourist_zoo',
+    'tourism:theme_park': 'poi_point_of_interest',
+    'tourism:attraction': 'poi_point_of_interest',
+    'leisure:golf_course': 'sport_golf',
+    'historic:castle': 'tourist_castle',
+    'amenity:hospital': 'health_hospital',
+    'amenity:school': 'education_school',
+    'amenity:theatre': 'tourist_theatre',
+    'amenity:library': 'amenity_library',
+    'amenity:fire_station': 'amenity_firestation3',
+    'amenity:police': 'amenity_police2',
+    'amenity:bank': 'money_bank2',
+    'amenity:post_office': 'amenity_post_office',
+    'tourism:hotel': 'accommodation_hotel2',
+    'amenity:cinema': 'tourist_cinema',
+    'tourism:artwork': 'tourist_art_gallery2',
+    'historic:archaeological_site': 'tourist_archaeological2',
+    'amenity:doctors': 'health_doctors',
+    'leisure:sports_centre': 'sport_leisure_centre',
+    'leisure:swimming_pool': 'sport_swimming_outdoor',
+    'shop:supermarket': 'shopping_supermarket',
+    'shop:convenience': 'shopping_convenience',
+    'amenity:restaurant': 'food_restaurant',
+    'amenity:fast_food': 'food_fastfood',
+    'amenity:cafe': 'food_cafe',
+    'tourism:guest_house': 'accommodation_bed_and_breakfast',
+    'amenity:pharmacy': 'health_pharmacy_dispensing',
+    'amenity:fuel': 'transport_fuel',
+    'natural:peak': 'poi_peak',
+    'natural:wood': 'landuse_coniferous_and_deciduous',
+    'shop:bicycle': 'shopping_bicycle',
+    'shop:clothes': 'shopping_clothes',
+    'shop:hairdresser': 'shopping_hairdresser',
+    'shop:doityourself': 'shopping_diy',
+    'shop:estate_agent': 'shopping_estateagent2',
+    'shop:car': 'shopping_car',
+    'shop:garden_centre': 'shopping_garden_centre',
+    'shop:car_repair': 'shopping_car_repair',
+    'shop:bakery': 'shopping_bakery',
+    'shop:butcher': 'shopping_butcher',
+    'shop:apparel': 'shopping_clothes',
+    'shop:laundry': 'shopping_laundrette',
+    'shop:beverages': 'shopping_alcohol',
+    'shop:alcohol': 'shopping_alcohol',
+    'shop:optician': 'health_opticians',
+    'shop:chemist': 'health_pharmacy',
+    'shop:gallery': 'tourist_art_gallery2',
+    'shop:jewelry': 'shopping_jewelry',
+    'tourism:information': 'amenity_information',
+    'historic:ruins': 'tourist_ruin',
+    'amenity:college': 'education_school',
+    'historic:monument': 'tourist_monument',
+    'historic:memorial': 'tourist_monument',
+    'historic:mine': 'poi_mine',
+    'tourism:caravan_site': 'accommodation_caravan_park',
+    'amenity:bus_station': 'transport_bus_station',
+    'amenity:atm': 'money_atm2',
+    'tourism:viewpoint': 'tourist_view_point',
+    'tourism:guesthouse': 'accommodation_bed_and_breakfast',
+    'railway:tram': 'transport_tram_stop',
+    'amenity:courthouse': 'amenity_court',
+    'amenity:recycling': 'amenity_recycling',
+    'amenity:dentist': 'health_dentist',
+    'natural:beach': 'tourist_beach',
+    'railway:tram_stop': 'transport_tram_stop',
+    'amenity:prison': 'amenity_prison',
+    'highway:bus_stop': 'transport_bus_stop2'
+  };
+
+  var sCategoryPlace = aPlace.category + ':' + aPlace.type;
+
+  return aIcons[sCategoryPlace];
+}
+
+
 Handlebars.registerHelper({
   formatOSMType: function (sType, bExcludeExternal) {
     return formatOSMType(sType, bExcludeExternal);
@@ -107,14 +204,13 @@ Handlebars.registerHelper({
   formatAdminLevel: function (iLevel) {
     return (iLevel < 15 ? iLevel : '');
   },
-  formatMapIcon: function (sIcon) {
+  formatMapIcon: function (aPlace) {
+    var sIcon = getIcon(aPlace);
+
     if (!sIcon) return '';
 
-    // https://nominatim.openstreetmap.org/images/mapicons/poi_boundary_administrative.p.20.png
-    // => poi boundary administrative
-    var title = sIcon.replace(/.+\//, '').replace(/\..+/, '').replace(/_/g, ' ');
-    // => http://localhost/mapicons/poi_boundary_administrative.p.20.png
-    var url = get_config_value('Images_Base_Url') + sIcon.replace(/.+\//, '');
+    var title = 'icon for ' + aPlace.category + ' ' + aPlace.type;
+    var url = get_config_value('Images_Base_Url') + sIcon + '.p.20.png';
 
     return new Handlebars.SafeString(
       '<img class="mapicon" src="' + url + '" alt="' + title + '"/>'
index 1b394324b91ddc82b7483ee3b4549f2d692966ed..48ecde95c3aabf3d3609bc0748809a4e363e3360 100644 (file)
@@ -44,7 +44,7 @@
       </h1>
     </div>
     <div class="col-sm-2 text-right">
-      {{formatMapIcon aPlace.icon}}
+      {{formatMapIcon aPlace}}
     </div>
   </div>
   <div class="row">
index 280a28255cde566c2fc1615690f007ccd7f4f670..ba80e7445c7dcf104af05e6a9c812fd8a0a39a7a 100644 (file)
@@ -1,10 +1,7 @@
 
 {{#*inline "partial_one_result"}}
   <div class="result" data-position="{{iResNum}}">
-    {{#if aResult.icon}}
-      <img src="{{env.Images_Base_Url}}{{aResult.icon}}" />
-      {{!-- {{formatMapIcon aResult.icon}} --}}
-    {{/if}}
+    {{formatMapIcon aResult}}
 
     <span class="name">{{aResult.display_name}}</span>
     <span class="type">{{formatLabel aResult}}</span>
index 1d3c92ca49a1fd654c48ea1b5429e94b04526953..ae13597009ce9f7353834d6b0aeeb6cdcf689af3 100644 (file)
@@ -1,9 +1,6 @@
 {{#*inline "partial_one_result"}}
   <div class="result" data-position="{{iResNum}}">
-    {{#if aResult.icon}}
-      {{!-- <img src="{{env.Images_Base_Url}}{{aResult.icon}}" /> --}}
-      {{formatMapIcon aResult.icon}}
-    {{/if}}
+    {{formatMapIcon aResult}}
 
     <span class="name">{{aResult.display_name}}</span>
     <span class="type">({{formatLabel aResult}})</span>