Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function queryOverpass(lon, lat, radius, callback) {
var query = fs.readFileSync(__dirname + '/query.ql').toString();
var x = lon;
var y = lat;
var point = turf.point([x, y]);
var buffer = turf.buffer(point, radius, 'kilometers');
// wsen
var bbox = turf.bbox(buffer);
// swne
var overpassBbox = [bbox[0], bbox[1], bbox[2], bbox[3]].toString();
var query = util.format(query, overpassBbox, overpassBbox);
overpass(query, function(error, data) {
if (error) {
return callback(error, null);
};
// ::id,::lon,::lat,"place","name","name:en","name:zh","wikipedia","wikidata"
var d = [];
data.features.forEach(function (f) {
var interestedProps = {
'id': f.properties.id,
'type': f.properties.type,
'lon': f.geometry.coordinates[0],
'lat': f.geometry.coordinates[1],
var bboxes = [];
var highways = {};
var output = {};
var motorwayJunction = {};
var majorRoads = {
'motorway': true,
'motorway_link': true
};
var preserveType = {};
preserveType = _.extend(preserveType, majorRoads);
var osmlint = 'getylane';
for (var z = 0; z < layer.features.length; z++) {
var val = layer.features[z];
if (val.geometry.type === 'LineString' && preserveType[val.properties.highway]) {
var bboxA = turf.bbox(val);
bboxA.push({
id: val.properties['@id']
});
bboxes.push(bboxA);
highways[val.properties['@id']] = val;
}
if (val.geometry.type === 'Point' && val.properties.highway && val.properties.highway === 'motorway_junction') {
var bboxP = turf.bbox(turf.buffer(val, 20, 'meters'));
bboxP.push({
id: val.properties['@id'] + 'P',
junction: true
});
bboxes.push(bboxP);
motorwayJunction[val.properties['@id'] + 'P'] = val;
}
}
function generate_points(polygon, number, coordinates_number, max_distance) {
let query_points = [];
while (query_points.length < number) {
let points = [];
while(points.length < coordinates_number) {
let chunk = turf
.random('points', coordinates_number, { bbox: turf.bbox(polygon)})
.features
.map(x => x.geometry.coordinates)
.filter(pt => turf.inside(pt, polygon));
if (max_distance > 0)
{
chunk.forEach(pt => {
if (points.length == 0)
{
points.push(pt);
}
else
{
let distance = turf.distance(pt, points[points.length-1], 'meters');
if (distance < max_distance)
{
_getBoundsBasedOnData() {
const featureCollection = this._getSourceFeatureCollection();
if (!featureCollection) {
return null;
}
const bbox = turf.bbox(featureCollection);
return {
min_lon: bbox[0],
min_lat: bbox[1],
max_lon: bbox[2],
max_lat: bbox[3]
};
}
'motorway': true,
'trunk': true,
'primary': true,
'secondary': true,
'tertiary': true,
'motorway_link': true,
'trunk_link': true,
'primary_link': true,
'secondary_link': true,
'tertiary_link': true
};
var osmlint = 'missinguturn';
for (var z = 0; z < layer.features.length; z++) {
var val = layer.features[z];
if (val.geometry.type === 'LineString' && preserveType[val.properties.highway]) {
var bboxA = turf.bbox(val);
bboxA.push({
id: val.properties['@id']
});
bboxes.push(bboxA);
highways[val.properties['@id']] = val;
}
}
var highwaysTree = rbush(bboxes.length);
highwaysTree.load(bboxes);
for (var i = 0; i < bboxes.length; i++) {
var valueBbox = bboxes[i];
var eHighway = highways[valueBbox[4].id];
if (eHighway.properties.oneway && eHighway.properties.oneway !== 'no') {
var overlaps = highwaysTree.search(valueBbox);
var nearRoads = {
_getBoundsBasedOnData() {
const featureCollection = this._getSourceFeatureCollection();
if (!featureCollection) {
return null;
}
const bbox = turf.bbox(featureCollection);
return {
min_lon: bbox[0],
min_lat: bbox[1],
max_lon: bbox[2],
max_lat: bbox[3]
};
}
_getBoundsBasedOnData() {
const featureCollection = this._getSourceFeatureCollection();
if (!featureCollection) {
return null;
}
const visibleFeatures = featureCollection.features.filter(feature => feature.properties[FEATURE_VISIBLE_PROPERTY_NAME]);
const bbox = turf.bbox({
type: 'FeatureCollection',
features: visibleFeatures
});
return {
min_lon: bbox[0],
min_lat: bbox[1],
max_lon: bbox[2],
max_lat: bbox[3]
};
}