UNPKG

overpass-frontend

Version:

A JavaScript (NodeJS/Browser) library to easily access data from OpenStreetMap via Overpass API or from an OSM File. The objects can directly be used with LeafletJS or exported to GeoJSON. Data will be cached in the browser memory.

56 lines (44 loc) 1.24 kB
const Request = require('./Request') /** * A request consisting of several requests - duplicate results will be filtered * @extends Request */ class RequestMulti extends Request { constructor (overpass, options, requests) { super(overpass, options) this.type = 'RequestMulti' this.doneFeatures = {} this.requests = requests this.requests.forEach(req => { req.on('finish', () => { this.requests.splice(this.requests.indexOf(req), 1) }) req.on('subrequest-compile', (subRequest) => this.emit('subrequest-compile', subRequest)) req.on('subrequest-finish', (subRequest) => this.emit('subrequest-finish', subRequest)) req.featureCallback = (err, ob) => { if (!(ob.id in this.doneFeatures)) { this.doneFeatures[ob.id] = true this.featureCallback(err, ob) } } req.finalCallback = () => {} this.overpass.requests.push(req) }) } /** * abort this request and sub requests */ abort () { this.requests.forEach(req => req.abort()) super.abort() } willInclude () { return false } preprocess () { } mayFinish () { return !this.requests.length } } module.exports = RequestMulti