Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then(results => {
if (!results.hits.hits.length) {
return results.hits.hits;
}
const points = results.hits.hits.map(doc =>
turf.point(doc._source.coordinates)
);
if (lat && lng && !bounds) {
points.push(turf.point([lng, lat]));
}
// create a bounding box for the results
const envelope = turf.bbox(
turf.buffer(turf.envelope(turf.featureCollection(points)), 0.5, {
units: "miles"
})
);
bounds = {
southwest: {
lat: envelope[1],
lng: envelope[0]
},
northeast: {
lat: envelope[3],
lng: envelope[2]
}
};
return results.hits.hits.map(doc => {
Agent.prototype.route = async function(range) {
try {
// buffer location to range
const buffer = turf.buffer(turf.point(this.location), range).geometry;
// compute quadkeys to query
const quadkeys = cover.indexes(buffer, this.simulation.Z);
// select random quadkey by rank
const scores = quadkeys.map(q => {
var score = this.simulation.quadtree.get(q);
return this.simulation.quadtree.get(q) || 0;
});
const quadkey = this.simulation.chance.weighted(quadkeys, scores);
const bbox = tilebelt.tileToBBOX(tilebelt.quadkeyToTile(quadkey));
// select random destination within bbox
var destination = [
this.simulation.chance.longitude({ min: bbox[0], max: bbox[2] }),
this.simulation.chance.latitude({ min: bbox[1], max: bbox[3] })
];
// snap destination to graph
drawBorderedPolygon(rectangle) {
if (!rectangle) {
// handles case where model changes to empty vars and we don't want to draw anymore
return
}
const lineWidth =
DistanceUtils.getDistanceInMeters(
this.model.get('lineWidth'),
this.model.get('lineUnits')
) || 1
const turfLine = Turf.lineString(
translateFromOpenlayersCoordinates(rectangle.getCoordinates())
)
const bufferedLine = Turf.buffer(turfLine, lineWidth, 'meters')
const geometryRepresentation = new ol.geom.MultiLineString(
translateToOpenlayersCoordinates(bufferedLine.geometry.coordinates)
)
if (this.vectorLayer) {
this.map.removeLayer(this.vectorLayer)
}
this.billboard = new ol.Feature({
geometry: geometryRepresentation,
})
this.billboard.setId(this.model.cid)
const color = this.model.get('color')
module.exports = function(tileLayers, tile, writeData, done) {
var layer = tileLayers.osm.osm;
var bboxes = [];
var bboxLayer = turf.bboxPolygon(turf.bbox(layer));
bboxLayer.geometry.type = 'LineString';
bboxLayer.geometry.coordinates = bboxLayer.geometry.coordinates[0];
var bufferLayer = turf.buffer(bboxLayer, 0.01, 'miles');
var highways = {};
var preserveType = {
'motorway': true,
'trunk': true,
'primary': true,
'secondary': true,
'tertiary': true
};
var roadSegments = {};
var osmlint = 'missingturnlinks';
for (var i = 0; i < layer.features.length; i++) {
var val = layer.features[i];
if (val.properties.highway && preserveType[val.properties.highway] && val.geometry.type === 'LineString') {
var segmets = turf.lineSegment(val);
var id = val.properties['@id'];
module.exports = function(tileLayers, tile, writeData, done) {
var layer = tileLayers.osm.osm;
var bboxLayer = turf.bboxPolygon(turf.bbox(layer));
bboxLayer.geometry.type = 'LineString';
bboxLayer.geometry.coordinates = bboxLayer.geometry.coordinates[0];
var bufferLayer = turf.buffer(bboxLayer, 0.01, {
units: 'miles'
});
var highways = {};
var bboxes = [];
var majorRoads = {
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
};
static addBuffer (geometry, radius = 0, projection = 'EPSG:3857') {
if (radius === 0) {
return geometry;
}
const geoJsonFormat = new OlFormatGeoJSON({
dataProjection: 'EPSG:4326',
featureProjection: projection
});
const geoJson = geometry instanceof OlFeature
? geoJsonFormat.writeFeatureObject(geometry)
: geoJsonFormat.writeGeometryObject(geometry);
const buffered = buffer(geoJson, radius, {
units: 'meters'
});
if (geometry instanceof OlFeature) {
return geoJsonFormat.readFeature(buffered);
} else {
return geoJsonFormat.readGeometry(buffered.geometry);
}
}
const createBufferedPolygonPoints = (polygonPoints, width) => {
return Turf.buffer(
Turf.lineString(polygonPoints),
Math.max(width, 1),
'meters'
)
}
if (!turf.booleanPointInPolygon(firstPoint, bufferLayer)) {
overlapsFirstPoint = highwaysTree.search(
objBbox(
turf.bboxPolygon(
turf.bbox(turf.buffer(firstPoint, distance, unit)),
'id'
)
)
);
}
var overlapsEndPoint = [];
if (!turf.booleanPointInPolygon(endPoint, bufferLayer)) {
overlapsEndPoint = highwaysTree.search(
objBbox(
turf.bboxPolygon(
turf.bbox(turf.buffer(endPoint, distance, unit)),
'id'
)
)
);
}
var overlapBboxes = overlapsFirstPoint.concat(overlapsEndPoint);
var arrayCorrd = [];
for (var j = 0; j < overlapBboxes.length; j++) {
var overlapBbox = overlapBboxes[j];
if (valueBbox.id !== overlapBbox.id) {
arrayCorrd = arrayCorrd.concat(
_.flatten(highways[overlapBbox.id].highway.geometry.coordinates)
);
}
}
module.exports = function(tileLayers, tile, writeData, done) {
var layer = tileLayers.osm.osm;
var bbox = turf.bbox(layer);
var bboxLineString = turf.bboxPolygon(bbox);
bboxLineString.geometry.type = 'LineString';
bboxLineString.geometry.coordinates = bboxLineString.geometry.coordinates[0];
var buffer = turf.buffer(bboxLineString, 0.0005, {
units: 'miles'
});
var result = layer.features.filter(function(val) {
val.properties._osmlint = 'unclosedways';
var valueType =
preserveType.area[val.properties.area] ||
preserveType.building[val.properties.building] ||
preserveType.landuse[val.properties.landuse] ||
preserveType.aeroway[val.properties.aeroway] ||
preserveType.leisure[val.properties.leisure] ||
preserveType.natural[val.properties.natural] ||
preserveType.man_made[val.properties.man_made];
if (
val.geometry.type === 'LineString' &&
valueType &&
const createBufferedPolygon = (coordinates, distance) =>
Turf.buffer(Turf.lineString(coordinates), Math.max(distance, 1), 'meters')