Leaflet and Turf - movo polygon to up (north) or donw (south)
In this code, we have a box (bbox) from a polygon in leflet.js
let radiusInKm = 10;
let angleInDegrees = 90;
// convert box to polygon in turf.js
let poly = turf.polygon([[[bbox[0], bbox[1]], [bbox[0], bbox[3]], [bbox[2], bbox[3]], [bbox[2], bbox[1]], [bbox[0], bbox[1]]]]);
let latlngs = poly.geometry.coordinates[0].map(function (element) {
return { "lat": element[0], "lng": element[1] };
});
let newCoords;
if (this.plusUp > 0) {
newCoords = latlngs.map(function (element) {
return L.GeometryUtil.destination(element, 90, 0.01 * 1000);
});
} else {
newCoords = latlngs.map(function (element) {
return L.GeometryUtil.destination(element, -90, 0.01 * 1000);
});
}
newCoords = newCoords.map(function (e) {
return [e['lat'], e['lng']];
});
Comentários
Postar um comentário