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.
45 lines (36 loc) • 961 B
JavaScript
const OverpassFrontend = require('../defines')
const qlFunction = require('./qlFunction')
module.exports = class uid extends qlFunction {
constructor (str) {
super()
this.fun = 'uid'
this.requestProperties = OverpassFrontend.META
this.value = str.split(/,/g).map(v => {
if (!v.match(/^\s*\d+\s*/)) {
throw new Error('Error parsing uid filter, expect a numeric value: "' + v + '"')
}
return parseInt(v)
})
}
test (ob) {
if (!ob.meta) {
return
}
return this.value.includes(ob.meta.uid)
}
toString () {
return '(uid:' + this.value.join(',') + ')'
}
compileLokiJS () {
if (this.value.length === 1) {
return { 'osmMeta.uid': { $eq: this.value[0] } }
} else {
return { 'osmMeta.uid': { $in: this.value } }
}
}
isSupersetOf (other) {
if (other instanceof uid) {
return !other.value.filter(id => !this.value.includes(id)).length
}
}
}