How to use hafas-client - 10 common examples

To help you get started, we’ve selected a few hafas-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github derhuerst / vbb-hafas / lib / radar.js View on Github external
if ('number' !== typeof north) throw new Error('north must be a number.')
	if ('number' !== typeof west) throw new Error('west must be a number.')
	if ('number' !== typeof south) throw new Error('south must be a number.')
	if ('number' !== typeof east) throw new Error('east must be a number.')
	opt = Object.assign({}, defaults, opt || {})
	opt.when = opt.when || new Date()

	return request({
		  meth: 'JourneyGeoPos'
		, req: {
			  maxJny: opt.results
			, onlyRT: false // todo: only realtime?
			, date: _stringify.date(opt.when)
			, time: _stringify.time(opt.when)
			, rect: {
				llCrd: {x: stringify.coord(west), y: stringify.coord(south)},
				urCrd: {x: stringify.coord(east), y: stringify.coord(north)}
			}
			, perSize: opt.duration * 1000
			, perStep: Math.round(opt.duration / Math.max(opt.frames, 1) * 1000)
			, ageOfReport: true // todo
			, jnyFltrL: [{type: 'PROD', mode: 'INC', value: '127'}] // todo
			, trainPosMode: 'CALC' // todo
		}
	})
	.then((d) => {
		if (!Array.isArray(d.jnyL)) return []
		for (let l of d.locations) {
			if (l.type === 'station') l.name = shorten(l.name)
		}

		const movements = d.jnyL.map(parse.movement(tz, d.locations, d.lines, d.remarks))
github derhuerst / vbb-hafas / lib / radar.js View on Github external
if ('number' !== typeof west) throw new Error('west must be a number.')
	if ('number' !== typeof south) throw new Error('south must be a number.')
	if ('number' !== typeof east) throw new Error('east must be a number.')
	opt = Object.assign({}, defaults, opt || {})
	opt.when = opt.when || new Date()

	return request({
		  meth: 'JourneyGeoPos'
		, req: {
			  maxJny: opt.results
			, onlyRT: false // todo: only realtime?
			, date: _stringify.date(opt.when)
			, time: _stringify.time(opt.when)
			, rect: {
				llCrd: {x: stringify.coord(west), y: stringify.coord(south)},
				urCrd: {x: stringify.coord(east), y: stringify.coord(north)}
			}
			, perSize: opt.duration * 1000
			, perStep: Math.round(opt.duration / Math.max(opt.frames, 1) * 1000)
			, ageOfReport: true // todo
			, jnyFltrL: [{type: 'PROD', mode: 'INC', value: '127'}] // todo
			, trainPosMode: 'CALC' // todo
		}
	})
	.then((d) => {
		if (!Array.isArray(d.jnyL)) return []
		for (let l of d.locations) {
			if (l.type === 'station') l.name = shorten(l.name)
		}

		const movements = d.jnyL.map(parse.movement(tz, d.locations, d.lines, d.remarks))
		for (let movement of movements) {
github derhuerst / vbb-hafas / lib / parse.js View on Github external
const journeyPart = (tz, s, ln, r) => (d) => {
	const result = {
		id: d.jid,
		line: ln[parseInt(d.prodX)],
		direction: d.dirTxt, // todo: parse this
		// todo: isPartCncl, isRchbl, poly
	}

	if (d.stopL) result.passed = d.stopL.map(parse.stopover(tz, s, ln, r, d))
	if (Array.isArray(d.remL)) d.remL.forEach(parse.applyRemark(s, ln, r))

	return result
}
github derhuerst / vbb-hafas / lib / parse.js View on Github external
const journeyPart = (tz, s, ln, r) => (d) => {
	const result = {
		id: d.jid,
		line: ln[parseInt(d.prodX)],
		direction: d.dirTxt, // todo: parse this
		// todo: isPartCncl, isRchbl, poly
	}

	if (d.stopL) result.passed = d.stopL.map(parse.stopover(tz, s, ln, r, d))
	if (Array.isArray(d.remL)) d.remL.forEach(parse.applyRemark(s, ln, r))

	return result
}
github derhuerst / vbb-hafas / lib / journeys.js View on Github external
const journeys = (from, to, opt) => {
	from = location(from)
	to = location(to)

	opt = opt || {}
	opt.products = Object.assign({}, defaults.products, opt.products)
	opt = Object.assign({}, defaults, opt)
	opt.when = opt.when || new Date()

	const filters = [
		  _stringify.products(opt.products)
		, stringify.accessibility[opt.accessibility]
	]
	if (opt.bike) filters.push(stringify.bike)
	// todo: add req.gisFltrL

	return request({
		  cfg: {polyEnc: 'GPA'}
		, meth: 'TripSearch'
		, req: {
			  outDate: _stringify.date(opt.when)
			, outTime: _stringify.time(opt.when)
			, numF: opt.results
			, getPasslist: opt.passedStations
			, maxChg: opt.transfers
			, minChgTime: opt.transferTime
			, depLocL: [from]
			, viaLocL: opt.via ? [{loc: {type: 'S', lid: 'L=' + opt.via}}] : null
github derhuerst / vbb-hafas / lib / journeys.js View on Github external
const journeys = (from, to, opt) => {
	from = location(from)
	to = location(to)

	opt = opt || {}
	opt.products = Object.assign({}, defaults.products, opt.products)
	opt = Object.assign({}, defaults, opt)
	opt.when = opt.when || new Date()

	const filters = [
		  _stringify.products(opt.products)
		, stringify.accessibility[opt.accessibility]
	]
	if (opt.bike) filters.push(stringify.bike)
	// todo: add req.gisFltrL

	return request({
		  cfg: {polyEnc: 'GPA'}
		, meth: 'TripSearch'
		, req: {
			  outDate: _stringify.date(opt.when)
			, outTime: _stringify.time(opt.when)
			, numF: opt.results
			, getPasslist: opt.passedStations
			, maxChg: opt.transfers
			, minChgTime: opt.transferTime
			, depLocL: [from]
			, viaLocL: opt.via ? [{loc: {type: 'S', lid: 'L=' + opt.via}}] : null
			, arrLocL: [to]
			, jnyFltrL: [filters]
github derhuerst / vbb-hafas / lib / parse.js View on Github external
const location = (l) => {
	const r = parse.location(l)

	if (r.id) r.id = to12Digit(r.id.replace(leadingZeros, ''))
	if ('products' in r) r.products = util.products.parseBitmask(r.products)
	if (r.type === 'station' && !r.coordinates) {
		const [s] = stations(r.id)
		if (s) {
			r.coordinates = {
				latitude: s.coordinates.latitude,
				longitude: s.coordinates.longitude
			}
		}
	}
	return r
}
github derhuerst / vbb-hafas / lib / parse.js View on Github external
const nearby = (l) => {
	const r = parse.nearby(l)
	if (r.id) r.id = to12Digit(r.id.replace(leadingZeros, ''))
	if ('products' in r) r.products = util.products.parseBitmask(r.products)
	return r
}
github derhuerst / vbb-hafas / lib / stringify.js View on Github external
const station = (id) => {
	if ('string' === typeof id && id.length !== 7) id = to9Digit(id)
	return stringify.station(id)
}
github derhuerst / vbb-hafas / lib / nearby.js View on Github external
const nearby = (latitude, longitude, opt) => {
	if ('number' !== typeof latitude) throw new Error('latitude must be a number.')
	if ('number' !== typeof longitude) throw new Error('longitude must be a number.')
	opt = Object.assign({}, defaults, opt || {})

	return request({
		  cfg: {polyEnc: 'GPA'}
		, meth: 'LocGeoPos'
		, req: {
			  ring: {
				  cCrd: {
				  	  x: stringify.coord(longitude)
				  	, y: stringify.coord(latitude)
				}
				, maxDist: opt.distance ? -1 : opt.distance
				, minDist: 0
			}
			, getPOIs: opt.poi
			, getStops: opt.stations
		}
	})
	.then((d) => {
		return Array.isArray(d.locL)
			? d.locL.map(parse.nearby).map((n) => {
				n.name = shorten(n.name)
				return n
			})
			: []
	})