Exemplo n.º 1
0
 Modals.getRandom(function(err, data) {
   console.log(data)
   var fc = turf.random(type, data.count, {
     bbox: data.bbox
   })
   fc.features = fc.features.concat(layer.geojson.features)
   layer.mapLayer.clearLayers()
   layer.mapLayer = false
   LayerActions.update(layer.id, {geojson: fc})
 })
Exemplo n.º 2
0
function generate_points(polygon, number) {
    let query_points = [];
    while (query_points.length < number) {
    var chunk = turf
        .random('points', number, { bbox: turf.bbox(polygon)})
        .features
        .map(x => x.geometry.coordinates)
        .filter(pt => turf.inside(pt, polygon));
        query_points = query_points.concat(chunk);
    }
    return query_points.slice(0, number);
}
Exemplo n.º 3
0
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)
                        {
                            points.push(pt);
                        }
                    }
                });
            }
            else
            {
                points = points.concat(chunk);
            }
        }

        query_points.push(points);
    }

    return query_points;
}