diff --git a/parse/common.js b/parse/common.js index d92b09e6..20ea8fee 100644 --- a/parse/common.js +++ b/parse/common.js @@ -1,5 +1,6 @@ 'use strict' +const omit = require('lodash/omit') const findInTree = require('../lib/find-in-tree') const parseCommonData = (_ctx) => { @@ -9,6 +10,7 @@ const parseCommonData = (_ctx) => { '**.oprX', '**.icoX', '**.prodX', '**.pRefL', '**.locX', '**.ani.fLocX', '**.ani.tLocX', '**.fLocX', '**.tLocX', '**.remX', '**.himX', '**.polyG.polyXL', '**.rRefL', + '**.msgL', ]); const common = {} @@ -89,13 +91,29 @@ const parseCommonData = (_ctx) => { }) } common.warnings = [] - if (opt.remarks && Array.isArray(c.himL)) { + if (Array.isArray(c.himL)) { common.warnings = c.himL.map(w => profile.parseWarning(ctx, w)) matches['**.himX'].forEach(([idx, parents]) => { if ('number' === typeof idx) parents[0].warning = common.warnings[idx] }) } + // resolve .msgL[] references + const parseRemarkRef = (ref) => { + if (ref.type === 'REM' && ref.hint) { + return omit(ref, ['type', 'remX']) + } + if (ref.type === 'HIM' && ref.warning) { + return omit(ref, ['type', 'himX']) + } + return null + } + matches['**.msgL'].forEach(([refs, parents]) => { + parents[0].remarkRefs = refs + .map(parseRemarkRef) + .filter(ref => ref !== null) + }) + common.polylines = [] if (opt.polylines && Array.isArray(c.polyL)) { common.polylines = c.polyL.map(p => profile.parsePolyline(ctx, p)) diff --git a/parse/hint.js b/parse/hint.js index 6bd309d2..14cdbe46 100644 --- a/parse/hint.js +++ b/parse/hint.js @@ -5,10 +5,12 @@ const codesByIcon = Object.assign(Object.create(null), { }) const linkTypesByCode = Object.assign(Object.create(null), { + BB: 'stop-website', // IFOPT-based DHID // https://wiki.openstreetmap.org/wiki/DE:Key:ref:IFOPT // https://trid.trb.org/view/1435440 IF: 'stop-dhid', + OZ: 'transit-authority', // todo: `{type: 'I',code: 'TD',icoX: 1,txtN: '8010224'}` // todo: `{type: 'I',code: 'TE',icoX: 1,txtN: '8024001'}` }) @@ -28,6 +30,9 @@ const parseHint = (ctx, h) => { if (h.code in linkTypesByCode) { return {type: linkTypesByCode[h.code], text: h.txtN} } + if (h.code === 'TW' && h.txtN[0] === '$') { + return {type: 'local-fare-zone', text: h.txtN.slice(1)} + } if (h.code === 'TW' && h.txtN[0] === '#') { return {type: 'foreign-id', text: h.txtN.slice(1)} } diff --git a/parse/location.js b/parse/location.js index e533cc64..f61f2713 100644 --- a/parse/location.js +++ b/parse/location.js @@ -38,9 +38,22 @@ const parseLocation = (ctx, l) => { stop.lines = l.lines } - const hints = l.hints || [] + const locHints = (l.remarkRefs || []) + .filter(ref => !!ref.hint && Array.isArray(ref.tagL)) + .filter(({tagL}) => ( + tagL.includes('RES_LOC') || + tagL.find(t => t.slice(0, 8) === 'RES_LOC_') // e.g. `RES_LOC_H3` + )) + .map(ref => ref.hint) + const hints = [ + ...(l.hints || []), + ...locHints, + ] const byType = type => hints.find(h => h.type === type) + const transitAuthority = (byType('transit-authority') || {}).text + if (transitAuthority) stop.transitAuthority = transitAuthority + const dhid = (byType('stop-dhid') || {}).text if (dhid) { if (!stop.ids) stop.ids = {} diff --git a/test/fixtures/db-stop.js b/test/fixtures/db-stop.js index ca3698ef..979c4f78 100644 --- a/test/fixtures/db-stop.js +++ b/test/fixtures/db-stop.js @@ -3,6 +3,10 @@ module.exports = { type: 'stop', id: '8011155', + ids: { + dhid: 'de:11000:900100003', + VBB: '900100003' + }, name: 'Berlin Alexanderplatz', location: { type: 'location', @@ -21,5 +25,6 @@ module.exports = { subway: true, tram: true, taxi: false - } + }, + transitAuthority: 'VBB', }