UNPKG

ojp-sdk-legacy

Version:

OJP (Open Journey Planner) Javascript SDK (legacy version)

71 lines (70 loc) 3.2 kB
export class PointOfInterest { constructor(code, name, category, subCategory, categoryTags, mapAdditionalInformation) { this.code = code; this.name = name; this.category = category; this.subCategory = subCategory; this.categoryTags = categoryTags; this.mapAdditionalInformation = mapAdditionalInformation; } static initWithLocationTreeNode(locationTreeNode, xmlConfig) { const treeNode = locationTreeNode.findChildNamed('PointOfInterest'); if (treeNode === null) { return null; } const isOJPv2 = xmlConfig.ojpVersion === '2.0'; const codeTagName = isOJPv2 ? 'PublicCode' : 'PointOfInterestCode'; const nameTagName = isOJPv2 ? 'Name/Text' : 'PointOfInterestName/Text'; const code = treeNode.findTextFromChildNamed(codeTagName); const name = treeNode.findTextFromChildNamed(nameTagName); if (!(code && name)) { return null; } const categoryTags = []; let category = null; let subCategory = null; const categoryTreeNodes = treeNode.findChildrenNamed('PointOfInterestCategory'); categoryTreeNodes.forEach(categoryTreeNode => { if (isOJPv2) { const categoryText = categoryTreeNode.findTextFromChildNamed('PointOfInterestClassification'); if (categoryText !== null) { category = categoryText; } } else { 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; } if (tagKey === 'POI_1') { subCategory = tagValue; } } }); if (category === null) { console.error('PointOfInterest.initWithLocationTreeNode error - no category'); category = 'none'; } // POIAdditionalInformation is OJP v2 only const mapAdditionalInformation = {}; if (isOJPv2) { const poiAdditonalInformationWrapperNode = treeNode.findChildNamed('POIAdditionalInformation'); if (poiAdditonalInformationWrapperNode) { const additonalInfoNodes = poiAdditonalInformationWrapperNode.findChildrenNamed('POIAdditionalInformation'); additonalInfoNodes.forEach(additonalInfoNode => { const keyText = additonalInfoNode.findTextFromChildNamed('Key'); const valueText = additonalInfoNode.findTextFromChildNamed('Value'); if ((keyText !== null) && (valueText !== null)) { mapAdditionalInformation[keyText] = valueText; } }); } } const poi = new PointOfInterest(code, name, category, subCategory, categoryTags, mapAdditionalInformation); return poi; } }