-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtranslate.js
55 lines (51 loc) · 1.65 KB
/
translate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const getLabel = properties => {
const { name, street, housenumber, postalcode, city } = properties;
const result = [];
if (name) {
result.push(name);
}
if (street) {
const num = housenumber || "";
result.push(`${street} ${num}`.trim());
}
if (city) {
const pc = postalcode || "";
result.push(`${pc} ${city}`);
}
return result.join(", ");
};
// if we already have a name, we keep it.
// exact addresses (with house numbers) don't have a name
// so we will use the label instead.
const getName = properties => {
const { name, label } = properties;
if (name) {
return name;
} else return label;
};
exports.translateResults = photonResult => {
let peliasResponse = {
features: []
};
photonResult.features.forEach(feature => {
if (feature.properties.state) {
feature.properties.region = feature.properties.state;
delete feature.properties.state;
}
if (feature.properties.postcode) {
feature.properties.postalcode = feature.properties.postcode;
delete feature.properties.postcode;
}
if (feature.properties.city) {
feature.properties.locality = feature.properties.city;
}
// in digitransit name is displayed in the first line and label in the second one
feature.properties.label = getLabel(feature.properties);
feature.properties.name = getName(feature.properties);
// `venue` is also applied to addresses but for the purpose of digitransit it does
// not matter: https://github.com/mfdz/digitransit-ui/blob/master/app/util/suggestionUtils.js#L54
feature.properties.layer = "venue";
peliasResponse.features.push(feature);
});
return peliasResponse;
};