How to use the hafas-client/stringify.coord function in hafas-client

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 / 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
			})
			: []
	})
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
			})
			: []