]> git.openstreetmap.org Git - nominatim.git/blob - lib/ClassTypes.php
encapsulate icon URL in a function
[nominatim.git] / lib / ClassTypes.php
1 <?php
2
3 namespace Nominatim\ClassTypes;
4
5 /**
6  * Create a label tag for the given place that can be used as an XML name.
7  *
8  * @param array[] $aPlace  Information about the place to label.
9  *
10  * A label tag groups various object types together under a common
11  * label. The returned value is lower case and has no spaces
12  */
13 function getLabelTag($aPlace, $sCountry = null)
14 {
15     $iRank = (int) ($aPlace['rank_address'] ?? 30);
16     $sLabel;
17     if (isset($aPlace['place_type'])) {
18         $sLabel = $aPlace['place_type'];
19     } elseif ($aPlace['class'] == 'boundary' && $aPlace['type'] == 'administrative') {
20         $sLabel = getBoundaryLabel($iRank/2, $sCountry);
21     } elseif ($iRank < 26) {
22         $sLabel = $aPlace['type'];
23     } elseif ($iRank < 28) {
24         $sLabel = 'road';
25     } elseif ($aPlace['class'] == 'place'
26             && ($aPlace['type'] == 'house_number' ||
27                 $aPlace['type'] == 'house_name' ||
28                 $aPlace['type'] == 'country_code')
29     ) {
30         $sLabel = $aPlace['type'];
31     } else {
32         $sLabel = $aPlace['class'];
33     }
34
35     return strtolower(str_replace(' ', '_', $sLabel));
36 }
37
38 /**
39  * Create a label for the given place.
40  *
41  * @param array[] $aPlace  Information about the place to label.
42  */
43 function getLabel($aPlace, $sCountry = null)
44 {
45     if (isset($aPlace['place_type'])) {
46         return ucwords(str_replace('_', ' ', $aPlace['place_type']));
47     }
48
49     if ($aPlace['class'] == 'boundary' && $aPlace['type'] == 'administrative') {
50         return getBoundaryLabel(($aPlace['rank_address'] ?? 30)/2, $sCountry ?? null);
51     }
52
53     // Return a label only for 'important' class/type combinations
54     if (getImportance($aPlace) !== null) {
55         return ucwords(str_replace('_', ' ', $aPlace['type']));
56     }
57
58     return null;
59 }
60
61
62 /**
63  * Return a simple label for an administrative boundary for the given country.
64  *
65  * @param int $iAdminLevel   Content of admin_level tag.
66  * @param string $sCountry   Country code of the country where the object is
67  *                           in. May be null, in which case a world-wide
68  *                           fallback is used.
69  * @param string $sFallback  String to return if no explicit string is listed.
70  *
71  * @return string
72  */
73 function getBoundaryLabel($iAdminLevel, $sCountry, $sFallback = 'Administrative')
74 {
75     static $aBoundaryList = array (
76                              'default' => array (
77                                            1 => 'Continent',
78                                            2 => 'Country',
79                                            3 => 'Region',
80                                            4 => 'State',
81                                            5 => 'State District',
82                                            6 => 'County',
83                                            7 => 'Municipality',
84                                            8 => 'City',
85                                            9 => 'City District',
86                                            10 => 'Suburb',
87                                            11 => 'Neighbourhood'
88                                            )
89             );
90
91     if (isset($aBoundaryList[$sCountry])
92         && isset($aBoundaryList[$sCountry][$iAdminLevel])
93     ) {
94         return $aBoundaryList[$sCountry][$iAdminLevel];
95     }
96
97     return $aBoundaryList['default'][$iAdminLevel] ?? $sFallback;
98 }
99
100 /**
101  * Return an estimated radius of how far the object node extends.
102  *
103  * @param array[] $aPlace  Information about the place. This must be a node
104  *                         feature.
105  *
106  * @return float  The radius around the feature in degrees.
107  */
108 function getDefRadius($aPlace)
109 {
110     $aSpecialRadius = array(
111                        'place:continent' => 25,
112                        'place:country' => 7,
113                        'place:state' => 2.6,
114                        'place:province' => 2.6,
115                        'place:region' => 1.0,
116                        'place:county' => 0.7,
117                        'place:city' => 0.16,
118                        'place:municipality' => 0.16,
119                        'place:island' => 0.32,
120                        'place:postcode' => 0.16,
121                        'place:town' => 0.04,
122                        'place:village' => 0.02,
123                        'place:hamlet' => 0.02,
124                        'place:district' => 0.02,
125                        'place:borough' => 0.02,
126                        'place:suburb' => 0.02,
127                        'place:locality' => 0.01,
128                        'place:neighbourhood'=> 0.01,
129                        'place:quarter' => 0.01,
130                        'place:city_block' => 0.01,
131                        'landuse:farm' => 0.01,
132                        'place:farm' => 0.01,
133                        'place:airport' => 0.015,
134                        'aeroway:aerodrome' => 0.015,
135                        'railway:station' => 0.005
136            );
137
138     $sClassPlace = $aPlace['class'].':'.$aPlace['type'];
139
140     return $aSpecialRadius[$sClassPlace] ?? 0.00005;
141 }
142
143 /**
144  * Get the icon to use with the given object.
145  */
146 function getIcon($aPlace)
147 {
148     $aIcons = array(
149                'boundary:administrative' => 'poi_boundary_administrative',
150                'place:city' => 'poi_place_city',
151                'place:town' => 'poi_place_town',
152                'place:village' => 'poi_place_village',
153                'place:hamlet' => 'poi_place_village',
154                'place:suburb' => 'poi_place_village',
155                'place:locality' => 'poi_place_village',
156                'place:airport' => 'transport_airport2',
157                'aeroway:aerodrome' => 'transport_airport2',
158                'railway:station' => 'transport_train_station2',
159                'amenity:place_of_worship' => 'place_of_worship_unknown3',
160                'amenity:pub' => 'food_pub',
161                'amenity:bar' => 'food_bar',
162                'amenity:university' => 'education_university',
163                'tourism:museum' => 'tourist_museum',
164                'amenity:arts_centre' => 'tourist_art_gallery2',
165                'tourism:zoo' => 'tourist_zoo',
166                'tourism:theme_park' => 'poi_point_of_interest',
167                'tourism:attraction' => 'poi_point_of_interest',
168                'leisure:golf_course' => 'sport_golf',
169                'historic:castle' => 'tourist_castle',
170                'amenity:hospital' => 'health_hospital',
171                'amenity:school' => 'education_school',
172                'amenity:theatre' => 'tourist_theatre',
173                'amenity:library' => 'amenity_library',
174                'amenity:fire_station' => 'amenity_firestation3',
175                'amenity:police' => 'amenity_police2',
176                'amenity:bank' => 'money_bank2',
177                'amenity:post_office' => 'amenity_post_office',
178                'tourism:hotel' => 'accommodation_hotel2',
179                'amenity:cinema' => 'tourist_cinema',
180                'tourism:artwork' => 'tourist_art_gallery2',
181                'historic:archaeological_site' => 'tourist_archaeological2',
182                'amenity:doctors' => 'health_doctors',
183                'leisure:sports_centre' => 'sport_leisure_centre',
184                'leisure:swimming_pool' => 'sport_swimming_outdoor',
185                'shop:supermarket' => 'shopping_supermarket',
186                'shop:convenience' => 'shopping_convenience',
187                'amenity:restaurant' => 'food_restaurant',
188                'amenity:fast_food' => 'food_fastfood',
189                'amenity:cafe' => 'food_cafe',
190                'tourism:guest_house' => 'accommodation_bed_and_breakfast',
191                'amenity:pharmacy' => 'health_pharmacy_dispensing',
192                'amenity:fuel' => 'transport_fuel',
193                'natural:peak' => 'poi_peak',
194                'natural:wood' => 'landuse_coniferous_and_deciduous',
195                'shop:bicycle' => 'shopping_bicycle',
196                'shop:clothes' => 'shopping_clothes',
197                'shop:hairdresser' => 'shopping_hairdresser',
198                'shop:doityourself' => 'shopping_diy',
199                'shop:estate_agent' => 'shopping_estateagent2',
200                'shop:car' => 'shopping_car',
201                'shop:garden_centre' => 'shopping_garden_centre',
202                'shop:car_repair' => 'shopping_car_repair',
203                'shop:bakery' => 'shopping_bakery',
204                'shop:butcher' => 'shopping_butcher',
205                'shop:apparel' => 'shopping_clothes',
206                'shop:laundry' => 'shopping_laundrette',
207                'shop:beverages' => 'shopping_alcohol',
208                'shop:alcohol' => 'shopping_alcohol',
209                'shop:optician' => 'health_opticians',
210                'shop:chemist' => 'health_pharmacy',
211                'shop:gallery' => 'tourist_art_gallery2',
212                'shop:jewelry' => 'shopping_jewelry',
213                'tourism:information' => 'amenity_information',
214                'historic:ruins' => 'tourist_ruin',
215                'amenity:college' => 'education_school',
216                'historic:monument' => 'tourist_monument',
217                'historic:memorial' => 'tourist_monument',
218                'historic:mine' => 'poi_mine',
219                'tourism:caravan_site' => 'accommodation_caravan_park',
220                'amenity:bus_station' => 'transport_bus_station',
221                'amenity:atm' => 'money_atm2',
222                'tourism:viewpoint' => 'tourist_view_point',
223                'tourism:guesthouse' => 'accommodation_bed_and_breakfast',
224                'railway:tram' => 'transport_tram_stop',
225                'amenity:courthouse' => 'amenity_court',
226                'amenity:recycling' => 'amenity_recycling',
227                'amenity:dentist' => 'health_dentist',
228                'natural:beach' => 'tourist_beach',
229                'railway:tram_stop' => 'transport_tram_stop',
230                'amenity:prison' => 'amenity_prison',
231                'highway:bus_stop' => 'transport_bus_stop2'
232     );
233
234     $sClassPlace = $aPlace['class'].':'.$aPlace['type'];
235
236     return $aIcons[$sClassPlace] ?? null;
237 }
238
239 /**
240  * Get an icon for the given object with its full URL.
241  */
242 function getIconFile($aPlace)
243 {
244     $sIcon = getIcon($aPlace);
245
246     if (!isset($sIcon)) {
247         return null;
248     }
249
250     return CONST_Website_BaseURL.'images/mapicons/'.$sIcon.'.p.20.png';
251 }
252
253 /**
254  * Return a class importance value for the given place.
255  *
256  * @param array[] $aPlace  Information about the place.
257  *
258  * @return int  An importance value. The lower the value, the more
259  *              important the class.
260  */
261 function getImportance($aPlace)
262 {
263     static $aWithImportance = null;
264
265     if ($aWithImportance === null) {
266         $aWithImportance = array_flip(array(
267                                            'place:country',
268                                            'place:state',
269                                            'place:province',
270                                            'place:county',
271                                            'place:city',
272                                            'place:region',
273                                            'place:island',
274                                            'place:town',
275                                            'place:village',
276                                            'place:hamlet',
277                                            'place:suburb',
278                                            'place:locality',
279                                            'landuse:farm',
280                                            'place:farm',
281                                            'highway:motorway_junction',
282                                            'highway:motorway',
283                                            'highway:trunk',
284                                            'highway:primary',
285                                            'highway:secondary',
286                                            'highway:tertiary',
287                                            'highway:residential',
288                                            'highway:unclassified',
289                                            'highway:living_street',
290                                            'highway:service',
291                                            'highway:track',
292                                            'highway:road',
293                                            'highway:byway',
294                                            'highway:bridleway',
295                                            'highway:cycleway',
296                                            'highway:pedestrian',
297                                            'highway:footway',
298                                            'highway:steps',
299                                            'highway:motorway_link',
300                                            'highway:trunk_link',
301                                            'highway:primary_link',
302                                            'landuse:industrial',
303                                            'landuse:residential',
304                                            'landuse:retail',
305                                            'landuse:commercial',
306                                            'place:airport',
307                                            'aeroway:aerodrome',
308                                            'railway:station',
309                                            'amenity:place_of_worship',
310                                            'amenity:pub',
311                                            'amenity:bar',
312                                            'amenity:university',
313                                            'tourism:museum',
314                                            'amenity:arts_centre',
315                                            'tourism:zoo',
316                                            'tourism:theme_park',
317                                            'tourism:attraction',
318                                            'leisure:golf_course',
319                                            'historic:castle',
320                                            'amenity:hospital',
321                                            'amenity:school',
322                                            'amenity:theatre',
323                                            'amenity:public_building',
324                                            'amenity:library',
325                                            'amenity:townhall',
326                                            'amenity:community_centre',
327                                            'amenity:fire_station',
328                                            'amenity:police',
329                                            'amenity:bank',
330                                            'amenity:post_office',
331                                            'leisure:park',
332                                            'amenity:park',
333                                            'landuse:park',
334                                            'landuse:recreation_ground',
335                                            'tourism:hotel',
336                                            'tourism:motel',
337                                            'amenity:cinema',
338                                            'tourism:artwork',
339                                            'historic:archaeological_site',
340                                            'amenity:doctors',
341                                            'leisure:sports_centre',
342                                            'leisure:swimming_pool',
343                                            'shop:supermarket',
344                                            'shop:convenience',
345                                            'amenity:restaurant',
346                                            'amenity:fast_food',
347                                            'amenity:cafe',
348                                            'tourism:guest_house',
349                                            'amenity:pharmacy',
350                                            'amenity:fuel',
351                                            'natural:peak',
352                                            'waterway:waterfall',
353                                            'natural:wood',
354                                            'natural:water',
355                                            'landuse:forest',
356                                            'landuse:cemetery',
357                                            'landuse:allotments',
358                                            'landuse:farmyard',
359                                            'railway:rail',
360                                            'waterway:canal',
361                                            'waterway:river',
362                                            'waterway:stream',
363                                            'shop:bicycle',
364                                            'shop:clothes',
365                                            'shop:hairdresser',
366                                            'shop:doityourself',
367                                            'shop:estate_agent',
368                                            'shop:car',
369                                            'shop:garden_centre',
370                                            'shop:car_repair',
371                                            'shop:newsagent',
372                                            'shop:bakery',
373                                            'shop:furniture',
374                                            'shop:butcher',
375                                            'shop:apparel',
376                                            'shop:electronics',
377                                            'shop:department_store',
378                                            'shop:books',
379                                            'shop:yes',
380                                            'shop:outdoor',
381                                            'shop:mall',
382                                            'shop:florist',
383                                            'shop:charity',
384                                            'shop:hardware',
385                                            'shop:laundry',
386                                            'shop:shoes',
387                                            'shop:beverages',
388                                            'shop:dry_cleaning',
389                                            'shop:carpet',
390                                            'shop:computer',
391                                            'shop:alcohol',
392                                            'shop:optician',
393                                            'shop:chemist',
394                                            'shop:gallery',
395                                            'shop:mobile_phone',
396                                            'shop:sports',
397                                            'shop:jewelry',
398                                            'shop:pet',
399                                            'shop:beauty',
400                                            'shop:stationery',
401                                            'shop:shopping_centre',
402                                            'shop:general',
403                                            'shop:electrical',
404                                            'shop:toys',
405                                            'shop:jeweller',
406                                            'shop:betting',
407                                            'shop:household',
408                                            'shop:travel_agency',
409                                            'shop:hifi',
410                                            'amenity:shop',
411                                            'tourism:information',
412                                            'place:house',
413                                            'place:house_name',
414                                            'place:house_number',
415                                            'place:country_code',
416                                            'leisure:pitch',
417                                            'highway:unsurfaced',
418                                            'historic:ruins',
419                                            'amenity:college',
420                                            'historic:monument',
421                                            'railway:subway',
422                                            'historic:memorial',
423                                            'leisure:nature_reserve',
424                                            'leisure:common',
425                                            'waterway:lock_gate',
426                                            'natural:fell',
427                                            'amenity:nightclub',
428                                            'highway:path',
429                                            'leisure:garden',
430                                            'landuse:reservoir',
431                                            'leisure:playground',
432                                            'leisure:stadium',
433                                            'historic:mine',
434                                            'natural:cliff',
435                                            'tourism:caravan_site',
436                                            'amenity:bus_station',
437                                            'amenity:kindergarten',
438                                            'highway:construction',
439                                            'amenity:atm',
440                                            'amenity:emergency_phone',
441                                            'waterway:lock',
442                                            'waterway:riverbank',
443                                            'natural:coastline',
444                                            'tourism:viewpoint',
445                                            'tourism:hostel',
446                                            'tourism:bed_and_breakfast',
447                                            'railway:halt',
448                                            'railway:platform',
449                                            'railway:tram',
450                                            'amenity:courthouse',
451                                            'amenity:recycling',
452                                            'amenity:dentist',
453                                            'natural:beach',
454                                            'place:moor',
455                                            'amenity:grave_yard',
456                                            'waterway:drain',
457                                            'landuse:grass',
458                                            'landuse:village_green',
459                                            'natural:bay',
460                                            'railway:tram_stop',
461                                            'leisure:marina',
462                                            'highway:stile',
463                                            'natural:moor',
464                                            'railway:light_rail',
465                                            'railway:narrow_gauge',
466                                            'natural:land',
467                                            'amenity:village_hall',
468                                            'waterway:dock',
469                                            'amenity:veterinary',
470                                            'landuse:brownfield',
471                                            'leisure:track',
472                                            'railway:historic_station',
473                                            'landuse:construction',
474                                            'amenity:prison',
475                                            'landuse:quarry',
476                                            'amenity:telephone',
477                                            'highway:traffic_signals',
478                                            'natural:heath',
479                                            'historic:house',
480                                            'amenity:social_club',
481                                            'landuse:military',
482                                            'amenity:health_centre',
483                                            'historic:building',
484                                            'amenity:clinic',
485                                            'highway:services',
486                                            'amenity:ferry_terminal',
487                                            'natural:marsh',
488                                            'natural:hill',
489                                            'highway:raceway',
490                                            'amenity:taxi',
491                                            'amenity:take_away',
492                                            'amenity:car_rental',
493                                            'place:islet',
494                                            'amenity:nursery',
495                                            'amenity:nursing_home',
496                                            'amenity:toilets',
497                                            'amenity:hall',
498                                            'waterway:boatyard',
499                                            'highway:mini_roundabout',
500                                            'historic:manor',
501                                            'tourism:chalet',
502                                            'amenity:bicycle_parking',
503                                            'amenity:hotel',
504                                            'waterway:weir',
505                                            'natural:wetland',
506                                            'natural:cave_entrance',
507                                            'amenity:crematorium',
508                                            'tourism:picnic_site',
509                                            'landuse:wood',
510                                            'landuse:basin',
511                                            'natural:tree',
512                                            'leisure:slipway',
513                                            'landuse:meadow',
514                                            'landuse:piste',
515                                            'amenity:care_home',
516                                            'amenity:club',
517                                            'amenity:medical_centre',
518                                            'historic:roman_road',
519                                            'historic:fort',
520                                            'railway:subway_entrance',
521                                            'historic:yes',
522                                            'highway:gate',
523                                            'leisure:fishing',
524                                            'historic:museum',
525                                            'amenity:car_wash',
526                                            'railway:level_crossing',
527                                            'leisure:bird_hide',
528                                            'natural:headland',
529                                            'tourism:apartments',
530                                            'amenity:shopping',
531                                            'natural:scrub',
532                                            'natural:fen',
533                                            'building:yes',
534                                            'mountain_pass:yes',
535                                            'amenity:parking',
536                                            'highway:bus_stop',
537                                            'place:postcode',
538                                            'amenity:post_box',
539                                            'place:houses',
540                                            'railway:preserved',
541                                            'waterway:derelict_canal',
542                                            'amenity:dead_pub',
543                                            'railway:disused_station',
544                                            'railway:abandoned',
545                                            'railway:disused'
546                 ));
547     }
548
549     $sClassPlace = $aPlace['class'].':'.$aPlace['type'];
550
551     return $aWithImportance[$sClassPlace] ?? null;
552 }