-
Notifications
You must be signed in to change notification settings - Fork 2
/
poi.ts
94 lines (77 loc) · 2.94 KB
/
poi.ts
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { RestrictionPoiOSMTag } from "../types/lir-restrictions.type"
import { TreeNode } from "../xml/tree-node"
const mapPoiSubCategoryIcons = <Record<RestrictionPoiOSMTag, string[]>>{
service: ['atm', 'hairdresser'],
shopping: ['all', 'clothes', 'optician'],
catering: ['all'],
accommodation: ['all'],
}
export class PointOfInterest {
public code: string
public name: string
public category: RestrictionPoiOSMTag
public subCategory: string | null
public categoryTags: string[]
constructor(code: string, name: string, category: RestrictionPoiOSMTag, subCategory: string | null, categoryTags: string[]) {
this.code = code
this.name = name
this.category = category
this.subCategory = subCategory
this.categoryTags = categoryTags
}
public static initWithLocationTreeNode(locationTreeNode: TreeNode): PointOfInterest | null {
const treeNode = locationTreeNode.findChildNamed('PointOfInterest');
if (treeNode === null) {
return null;
}
const code = treeNode.findTextFromChildNamed('PointOfInterestCode');
const name = treeNode.findTextFromChildNamed('PointOfInterestName/Text');
if (!(code && name)) {
return null;
}
const categoryTags: string[] = [];
let category: RestrictionPoiOSMTag | null = null;
let subCategory: string | null = null;
const categoryTreeNodes = treeNode.findChildrenNamed('PointOfInterestCategory');
categoryTreeNodes.forEach(categoryTreeNode => {
const tagValue = categoryTreeNode.findTextFromChildNamed('OsmTag/Value');
if (tagValue) {
categoryTags.push(tagValue);
}
const tagKey = categoryTreeNode.findTextFromChildNamed('OsmTag/Tag');
if (tagKey === 'POI_0' || tagKey === 'amenity') {
category = tagValue as RestrictionPoiOSMTag;
}
if (tagKey === 'POI_1') {
subCategory = tagValue;
}
});
if (category === null) {
console.error('PointOfInterest.initWithLocationTreeNode error - no category');
console.log(locationTreeNode);
return null;
}
const poi = new PointOfInterest(code, name, category, subCategory, categoryTags);
return poi;
}
// The return is a 50px image in ./src/assets/map-style-icons
// i.e. ./src/assets/map-style-icons/poi-atm.png
// icons from https://www.shareicon.net/author/adiante-apps
public computePoiMapIcon(): string {
const fallbackIcon = 'poi-unknown';
if (!(this.category in mapPoiSubCategoryIcons)) {
return fallbackIcon;
}
const hasSubCategory = this.subCategory && (mapPoiSubCategoryIcons[this.category].indexOf(this.subCategory) > -1);
if (hasSubCategory) {
const mapIcon = 'poi-' + this.category + '-' + this.subCategory;
return mapIcon;
}
const hasAllSubCategory = mapPoiSubCategoryIcons[this.category].indexOf('all') > -1;
if (hasAllSubCategory) {
const mapIcon = 'poi-' + this.category + '-all';
return mapIcon;
}
return fallbackIcon;
}
}