@panoramax/web-viewer 4.0.2-develop-9d664bb8 → 4.0.2-develop-9b499e28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/utils/geocoder.js
CHANGED
|
@@ -3,6 +3,20 @@ import maplibregl from "!maplibre-gl";
|
|
|
3
3
|
|
|
4
4
|
import { NominatimBaseUrl, AdresseDataGouvBaseURL } from "./services";
|
|
5
5
|
|
|
6
|
+
const PLACETYPE_ZOOM = {
|
|
7
|
+
"house": 20,
|
|
8
|
+
"housenumber": 20,
|
|
9
|
+
"street": 18,
|
|
10
|
+
"locality": 15,
|
|
11
|
+
"district": 13,
|
|
12
|
+
"municipality": 12,
|
|
13
|
+
"city": 12,
|
|
14
|
+
"county": 8,
|
|
15
|
+
"region": 7,
|
|
16
|
+
"state": 7,
|
|
17
|
+
"country": 5
|
|
18
|
+
};
|
|
19
|
+
|
|
6
20
|
/**
|
|
7
21
|
* Transforms a set of parameters into an URL-ready string
|
|
8
22
|
* It also removes null/undefined values
|
|
@@ -20,42 +34,6 @@ function geocoderParamsToURLString(params) {
|
|
|
20
34
|
return new URLSearchParams(p).toString();
|
|
21
35
|
}
|
|
22
36
|
|
|
23
|
-
/**
|
|
24
|
-
* Transforms Nominatim search result into a nice-to-display address.
|
|
25
|
-
* @param {object} props The Nominatim API feature properties
|
|
26
|
-
* @returns {string} The clean-up string for display
|
|
27
|
-
* @private
|
|
28
|
-
*/
|
|
29
|
-
function nominatimAddressToPlaceName(props) {
|
|
30
|
-
// API format @ https://nominatim.org/release-docs/develop/api/Output/#addressdetails
|
|
31
|
-
|
|
32
|
-
const nameKind = [
|
|
33
|
-
"house_name", "emergency", "historic", "military", "natural", "landuse", "place", "railway", "man_made",
|
|
34
|
-
"aerialway", "boundary", "amenity", "aeroway", "club", "craft", "leisure", "office",
|
|
35
|
-
"mountain_pass", "shop", "tourism", "bridge", "tunnel", "waterway", "park"
|
|
36
|
-
].find(pn => props?.address?.[pn]);
|
|
37
|
-
|
|
38
|
-
const localityKind = [
|
|
39
|
-
"hamlet", "croft", "isolated_dwelling",
|
|
40
|
-
"farm", "farmyard", "industrial", "commercial", "retail", "city_block", "residential",
|
|
41
|
-
"neighbourhood", "allotments", "quarter",
|
|
42
|
-
].find(pn => props?.address?.[pn]);
|
|
43
|
-
|
|
44
|
-
const stprops = {
|
|
45
|
-
type: props?.addresstype || props?.type,
|
|
46
|
-
name: (props?.name?.length > 0 ? props.name : null) || (nameKind ? props.address[nameKind] : undefined),
|
|
47
|
-
housenumber: props?.address?.house_number,
|
|
48
|
-
street: props?.address?.road,
|
|
49
|
-
locality: localityKind ? props.address[localityKind] : undefined,
|
|
50
|
-
city: props?.address?.village || props?.address?.town || props?.address?.city || props?.address?.municipality,
|
|
51
|
-
county: props?.address?.county,
|
|
52
|
-
state: props?.address?.state,
|
|
53
|
-
country: props?.address?.country,
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
return geocodeJsonToPlaceName(stprops);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
37
|
/**
|
|
60
38
|
* Nominatim (OSM) geocoder, ready to use for our Map
|
|
61
39
|
* @private
|
|
@@ -69,18 +47,19 @@ export function forwardGeocodingNominatim(config) {
|
|
|
69
47
|
viewbox: config.bbox,
|
|
70
48
|
};
|
|
71
49
|
|
|
72
|
-
return fetch(`${NominatimBaseUrl()}/search?${geocoderParamsToURLString(params)}&format=
|
|
50
|
+
return fetch(`${NominatimBaseUrl()}/search?${geocoderParamsToURLString(params)}&format=geocodejson&addressdetails=1`)
|
|
73
51
|
.then(res => res.json())
|
|
74
52
|
.then(res => {
|
|
75
53
|
const finalRes = { features: [] };
|
|
76
54
|
const listedNames = [];
|
|
77
|
-
res.features.forEach(f => {
|
|
78
|
-
const plname =
|
|
55
|
+
(res.features || []).forEach(f => {
|
|
56
|
+
const plname = geocodeJsonToPlaceName(f.properties?.geocoding) || f.properties?.geocoding?.label;
|
|
79
57
|
if(!listedNames.includes(plname)) {
|
|
80
58
|
finalRes.features.push({
|
|
81
59
|
place_type: ["place"],
|
|
82
60
|
place_name: plname,
|
|
83
|
-
|
|
61
|
+
center: new maplibregl.LngLat(...f.geometry.coordinates),
|
|
62
|
+
zoom: PLACETYPE_ZOOM[f.properties?.geocoding?.type],
|
|
84
63
|
});
|
|
85
64
|
listedNames.push(plname);
|
|
86
65
|
}
|
|
@@ -90,9 +69,9 @@ export function forwardGeocodingNominatim(config) {
|
|
|
90
69
|
}
|
|
91
70
|
|
|
92
71
|
export function reverseGeocodingNominatim(lat, lon) {
|
|
93
|
-
return fetch(`${NominatimBaseUrl()}/reverse?lat=${lat}&lon=${lon}&zoom=18&format=
|
|
72
|
+
return fetch(`${NominatimBaseUrl()}/reverse?lat=${lat}&lon=${lon}&zoom=18&format=geocodejson`)
|
|
94
73
|
.then(res => res.json())
|
|
95
|
-
.then(res =>
|
|
74
|
+
.then(res => geocodeJsonToPlaceName(res?.features?.shift()?.properties?.geocoding));
|
|
96
75
|
}
|
|
97
76
|
|
|
98
77
|
/**
|
|
@@ -164,6 +143,7 @@ function geocodeJsonToPlaceName(props) {
|
|
|
164
143
|
p3.push(props.country);
|
|
165
144
|
break;
|
|
166
145
|
case "street":
|
|
146
|
+
case "road":
|
|
167
147
|
default:
|
|
168
148
|
p2.push(props.street);
|
|
169
149
|
p2.push(props.locality);
|
|
@@ -204,20 +184,6 @@ export function forwardGeocodingStandard(config, endpoint) {
|
|
|
204
184
|
params.lon = lon;
|
|
205
185
|
}
|
|
206
186
|
|
|
207
|
-
const placeTypeToZoom = {
|
|
208
|
-
"house": 20,
|
|
209
|
-
"housenumber": 20,
|
|
210
|
-
"street": 18,
|
|
211
|
-
"locality": 15,
|
|
212
|
-
"district": 13,
|
|
213
|
-
"municipality": 12,
|
|
214
|
-
"city": 12,
|
|
215
|
-
"county": 8,
|
|
216
|
-
"region": 7,
|
|
217
|
-
"state": 7,
|
|
218
|
-
"country": 5
|
|
219
|
-
};
|
|
220
|
-
|
|
221
187
|
return fetch(`${endpoint}/?${geocoderParamsToURLString(params)}`)
|
|
222
188
|
.then(res => res.json())
|
|
223
189
|
.then(res => {
|
|
@@ -230,7 +196,7 @@ export function forwardGeocodingStandard(config, endpoint) {
|
|
|
230
196
|
place_type: ["place"],
|
|
231
197
|
place_name: plname,
|
|
232
198
|
center: new maplibregl.LngLat(...f.geometry.coordinates),
|
|
233
|
-
zoom:
|
|
199
|
+
zoom: PLACETYPE_ZOOM[f.properties.type],
|
|
234
200
|
});
|
|
235
201
|
listedNames.push(plname);
|
|
236
202
|
}
|
|
@@ -1,56 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "FeatureCollection",
|
|
3
|
-
"
|
|
3
|
+
"geocoding": {
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"attribution": "Data © OpenStreetMap contributors, ODbL 1.0. http://osm.org/copyright",
|
|
6
|
+
"licence": "ODbL",
|
|
7
|
+
"query": "paris"
|
|
8
|
+
},
|
|
4
9
|
"features": [
|
|
5
10
|
{
|
|
6
11
|
"type": "Feature",
|
|
7
12
|
"properties": {
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"address": {
|
|
18
|
-
"suburb": "Paris",
|
|
19
|
-
"city_district": "Paris",
|
|
20
|
-
"city": "Paris",
|
|
21
|
-
"ISO3166-2-lvl6": "FR-75",
|
|
13
|
+
"geocoding": {
|
|
14
|
+
"place_id": 88066702,
|
|
15
|
+
"osm_type": "relation",
|
|
16
|
+
"osm_id": 71525,
|
|
17
|
+
"osm_key": "boundary",
|
|
18
|
+
"osm_value": "administrative",
|
|
19
|
+
"type": "city",
|
|
20
|
+
"label": "Paris, Île-de-France, France métropolitaine, France",
|
|
21
|
+
"name": "Paris",
|
|
22
22
|
"state": "Île-de-France",
|
|
23
|
-
"ISO3166-2-lvl4": "FR-IDF",
|
|
24
|
-
"region": "France métropolitaine",
|
|
25
23
|
"country": "France",
|
|
26
|
-
"country_code": "fr"
|
|
24
|
+
"country_code": "fr",
|
|
25
|
+
"admin": {
|
|
26
|
+
"level6": "Paris",
|
|
27
|
+
"level4": "Île-de-France",
|
|
28
|
+
"level3": "France métropolitaine"
|
|
29
|
+
}
|
|
27
30
|
}
|
|
28
31
|
},
|
|
29
|
-
"bbox": [
|
|
30
|
-
2.224122,
|
|
31
|
-
48.8155755,
|
|
32
|
-
2.4697602,
|
|
33
|
-
48.902156
|
|
34
|
-
],
|
|
35
32
|
"geometry": {
|
|
36
|
-
"type": "
|
|
33
|
+
"type": "Point",
|
|
37
34
|
"coordinates": [
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
2.224122,
|
|
41
|
-
48.854199
|
|
42
|
-
],
|
|
43
|
-
[
|
|
44
|
-
2.224125,
|
|
45
|
-
48.85402
|
|
46
|
-
],
|
|
47
|
-
[
|
|
48
|
-
2.224125,
|
|
49
|
-
48.853869
|
|
50
|
-
]
|
|
51
|
-
]
|
|
35
|
+
2.3483915,
|
|
36
|
+
48.8534951
|
|
52
37
|
]
|
|
53
38
|
}
|
|
54
39
|
}
|
|
55
40
|
]
|
|
56
|
-
}
|
|
41
|
+
}
|
|
@@ -22,20 +22,15 @@ exports[`forwardGeocodingNominatim works 1`] = `
|
|
|
22
22
|
Object {
|
|
23
23
|
"features": Array [
|
|
24
24
|
Object {
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
"lng": -1.7,
|
|
29
|
-
},
|
|
30
|
-
"sw": Object {
|
|
31
|
-
"lat": 47.8,
|
|
32
|
-
"lng": -1.7,
|
|
33
|
-
},
|
|
25
|
+
"center": Object {
|
|
26
|
+
"lat": 47.8,
|
|
27
|
+
"lng": -1.7,
|
|
34
28
|
},
|
|
35
|
-
"place_name": "Paris",
|
|
29
|
+
"place_name": "Paris, Île-de-France",
|
|
36
30
|
"place_type": Array [
|
|
37
31
|
"place",
|
|
38
32
|
],
|
|
33
|
+
"zoom": 12,
|
|
39
34
|
},
|
|
40
35
|
],
|
|
41
36
|
}
|
|
@@ -13,7 +13,7 @@ describe("forwardGeocodingNominatim", () => {
|
|
|
13
13
|
const cfg = { query: "bla", limit: 5, bbox: "17.7,-45.2,17.8,-45.1" };
|
|
14
14
|
|
|
15
15
|
return geocoder.forwardGeocodingNominatim(cfg).then(res => {
|
|
16
|
-
expect(global.fetch.mock.calls).toEqual([["https://nominatim.openstreetmap.org/search?q=bla&limit=5&viewbox=17.7%2C-45.2%2C17.8%2C-45.1&format=
|
|
16
|
+
expect(global.fetch.mock.calls).toEqual([["https://nominatim.openstreetmap.org/search?q=bla&limit=5&viewbox=17.7%2C-45.2%2C17.8%2C-45.1&format=geocodejson&addressdetails=1"]]);
|
|
17
17
|
expect(res).toMatchSnapshot();
|
|
18
18
|
});
|
|
19
19
|
});
|