Skip to content

Commit e92025d

Browse files
committed
nominatim: test htmTemplate
See #357.
1 parent d697fa0 commit e92025d

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

spec/__snapshots__/nominatim.spec.ts.snap

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,61 @@ exports[`L.Control.Geocoder.Nominatim > geocodes Innsbruck 1`] = `
5555
]
5656
`;
5757

58+
exports[`L.Control.Geocoder.Nominatim > geocodes Innsbruck using a custom htmlTemplate 1`] = `
59+
[
60+
[
61+
[
62+
{
63+
"bbox": {
64+
"_northEast": {
65+
"lat": 47.2808566,
66+
"lng": 11.418183,
67+
},
68+
"_southWest": {
69+
"lat": 47.2583715,
70+
"lng": 11.3811871,
71+
},
72+
},
73+
"center": {
74+
"lat": 47.26951525,
75+
"lng": 11.3971372042211,
76+
},
77+
"html": "Innsbruck, Tyrol, Austria <a href="https://www.openstreetmap.org/relation/8182617">relation/8182617</a>",
78+
"icon": "https://nominatim.openstreetmap.org/images/mapicons/poi_boundary_administrative.p.20.png",
79+
"name": "Innsbruck, Tyrol, Austria",
80+
"properties": {
81+
"address": {
82+
"city": "Innsbruck",
83+
"city_district": "Innsbruck",
84+
"country": "Austria",
85+
"country_code": "at",
86+
"county": "Innsbruck",
87+
"state": "Tyrol",
88+
},
89+
"boundingbox": [
90+
"47.2583715",
91+
"47.2808566",
92+
"11.3811871",
93+
"11.418183",
94+
],
95+
"class": "boundary",
96+
"display_name": "Innsbruck, Tyrol, Austria",
97+
"icon": "https://nominatim.openstreetmap.org/images/mapicons/poi_boundary_administrative.p.20.png",
98+
"importance": 0.763909048330467,
99+
"lat": "47.26951525",
100+
"licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
101+
"lon": "11.3971372042211",
102+
"osm_id": 8182617,
103+
"osm_type": "relation",
104+
"place_id": 199282228,
105+
"type": "administrative",
106+
},
107+
},
108+
],
109+
],
110+
]
111+
`;
112+
58113
exports[`L.Control.Geocoder.Nominatim > reverse geocodes 47.3/11.3 1`] = `
59114
[
60115
[

spec/nominatim.spec.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,48 @@ describe('L.Control.Geocoder.Nominatim', () => {
5252
expect([[result]]).toMatchSnapshot();
5353
});
5454

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+
5597
it('reverse geocodes 47.3/11.3', async () => {
5698
const result = await mockFetchRequest(
5799
'https://nominatim.openstreetmap.org/reverse?lat=47.3&lon=11.3&zoom=9&addressdetails=1&format=json',

0 commit comments

Comments
 (0)