@@ -52,6 +52,48 @@ describe('L.Control.Geocoder.Nominatim', () => {
52
52
expect ( [ [ result ] ] ) . toMatchSnapshot ( ) ;
53
53
} ) ;
54
54
55
+ it ( 'geocodes Innsbruck using a custom htmlTemplate' , async ( ) => {
56
+ const geocoder2 = new Nominatim ( {
57
+ htmlTemplate ( result ) {
58
+ const osm = [ result . osm_type , result . osm_id ] . join ( '/' ) ;
59
+ return `${ result . display_name } <a href="https://www.openstreetmap.org/${ osm } ">${ osm } </a>` ;
60
+ }
61
+ } ) ;
62
+ const result = await mockFetchRequest (
63
+ 'https://nominatim.openstreetmap.org/search?q=innsbruck&limit=5&format=json&addressdetails=1' ,
64
+ [
65
+ {
66
+ place_id : 199282228 ,
67
+ licence : 'Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright' ,
68
+ osm_type : 'relation' ,
69
+ osm_id : 8182617 ,
70
+ boundingbox : [ '47.2583715' , '47.2808566' , '11.3811871' , '11.418183' ] ,
71
+ lat : '47.26951525' ,
72
+ lon : '11.3971372042211' ,
73
+ display_name : 'Innsbruck, Tyrol, Austria' ,
74
+ class : 'boundary' ,
75
+ type : 'administrative' ,
76
+ importance : 0.763909048330467 ,
77
+ icon : 'https://nominatim.openstreetmap.org/images/mapicons/poi_boundary_administrative.p.20.png' ,
78
+ address : {
79
+ city_district : 'Innsbruck' ,
80
+ city : 'Innsbruck' ,
81
+ county : 'Innsbruck' ,
82
+ state : 'Tyrol' ,
83
+ country : 'Austria' ,
84
+ country_code : 'at'
85
+ }
86
+ }
87
+ ] satisfies NominatimResponse ,
88
+ ( ) => geocoder2 . geocode ( 'innsbruck' )
89
+ ) ;
90
+ const feature = result [ 0 ] ;
91
+ expect ( feature . html ) . toBe (
92
+ 'Innsbruck, Tyrol, Austria <a href="https://www.openstreetmap.org/relation/8182617">relation/8182617</a>'
93
+ ) ;
94
+ expect ( [ [ result ] ] ) . toMatchSnapshot ( ) ;
95
+ } ) ;
96
+
55
97
it ( 'reverse geocodes 47.3/11.3' , async ( ) => {
56
98
const result = await mockFetchRequest (
57
99
'https://nominatim.openstreetmap.org/reverse?lat=47.3&lon=11.3&zoom=9&addressdetails=1&format=json' ,
0 commit comments