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.
29 lines (25 loc) • 742 B
JavaScript
const turf = require('../turf')
const EvaluatorFunction = require('../EvaluatorFunction')
const OverpassFrontend = require('../defines')
module.exports = class EvaluatorFunctionLength extends EvaluatorFunction {
constructor (fun, parameters) {
super(fun, parameters)
this.requestProperties = OverpassFrontend.GEOM
}
eval (context) {
if ('geomLength' in context.dbData) {
return context.dbData.geomLength
} else {
const g = context.GeoJSON()
if (g && g.geometry) {
const geomLength = turf.length(g, { units: 'kilometers' }) * 1000
context.dbSet({ geomLength })
return geomLength
}
}
return null
}
compileLokiJS (param) {
return { needMatch: true }
}
}