This repository has been archived by the owner on Oct 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
60 lines (50 loc) · 1.65 KB
/
index.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
56
57
58
59
60
import iconStyles from './icons.yml';
const nameToClass = iconName => iconName.match(/^(.*?)-[0-9]{1,2}$/)[1];
function getIconFromMapping({ className, subClassName }) {
const icons = iconStyles.mappings;
const icon =
// Matching class and subclass
icons.find(iconProperty =>
iconProperty.subclass === subClassName && iconProperty.class === className)
||
// Or: no class and matching subclass
icons.find(iconProperty =>
iconProperty.subclass === subClassName && !iconProperty.class)
||
// Or: matching class and no subclass
icons.find(iconProperty =>
iconProperty.class === className && !iconProperty.subclass);
return icon;
}
function getPoiIcon({ className, subClassName, type }) {
let iconName, color;
// Get the icon of a location / area that is not a PoI:
switch (type) {
case 'poi':
case 'category':
const icon = getIconFromMapping({ className, subClassName });
iconName = icon ? icon.iconName : iconStyles.defaultIcon;
color = icon ? icon.color : iconStyles.defaultColor;
break;
// Exact address
case 'house':
case 'address':
iconName = iconStyles.defaultAddressIcon;
color = iconStyles.defaultAddressColor;
break;
// Road / street without house number
case 'street':
iconName = iconStyles.defaultStreetIcon;
color = iconStyles.defaultStreetColor;
break;
// Administrative zones (city, area, country)
default:
iconName = iconStyles.defaultAdministrativeIcon;
color = iconStyles.defaultAdministrativeColor;
}
return {
iconClass: nameToClass(iconName),
color,
}
}
export { getPoiIcon };