Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const d2r = Math.PI / 180; // degrees to radians
const r2d = 180 / Math.PI; // radians to degrees
const points = 32;
let result = [];
// find the radius in lat/lon
//const rlat = (radius / EARTH_RADIUS_METERS) * r2d;
//const rlng = rlat / Math.cos({coordinate.latitude * d2r);
if (initialBearing > finalBearing) finalBearing += 360;
let deltaBearing = finalBearing - initialBearing;
deltaBearing = deltaBearing/points;
for (let i=0; (i < points+1); i++)
{
result.push(geolib.computeDestinationPoint(coordinate, radius, initialBearing + i*deltaBearing));
}
return result;
};
function calculateExtensionLine(position, course, speed, extensionLineSetting) {
if (extensionLineSetting === EXTENSION_LINE_OFF) {
return undefined
}
const time = 60 * parseInt(extensionLineSetting)
if (position && position.latitude && position.longitude && course && speed > 0.5) {
const distance = speed * time // Speed in m/s
const start = [position.latitude, position.longitude]
const destination = computeDestinationPoint(
{lat: position.latitude, lon: position.longitude},
distance,
toDegrees(course)
)
const middle = computeDestinationPoint(
{lat: position.latitude, lon: position.longitude},
distance / 2,
toDegrees(course)
)
return {
start,
middle: [middle.latitude, middle.longitude],
end: [destination.latitude, destination.longitude]
}
}
return undefined
}
function calculateExtensionLine(position, course, speed, extensionLineSetting) {
if (extensionLineSetting === EXTENSION_LINE_OFF) {
return undefined
}
const time = 60 * parseInt(extensionLineSetting)
if (position && position.latitude && position.longitude && course && speed > 0.5) {
const distance = speed * time // Speed in m/s
const start = [position.latitude, position.longitude]
const destination = computeDestinationPoint(
{lat: position.latitude, lon: position.longitude},
distance,
toDegrees(course)
)
const middle = computeDestinationPoint(
{lat: position.latitude, lon: position.longitude},
distance / 2,
toDegrees(course)
)
return {
start,
middle: [middle.latitude, middle.longitude],
end: [destination.latitude, destination.longitude]
}
}
return undefined
const nextPoint = points[index + 1];
if(nextPoint && !nextPoint.final == true) {
// calculate distance between each point
const distance = Math.round(GeoLib.getDistance(point, nextPoint));
const bearing = GeoLib.getBearing(point, nextPoint);
if(bearing !== 0) {
if (distance > 1) {
for (var x = 1; x < distance; x++) {
result.push(Object.assign({}, {bearing}, GeoLib.computeDestinationPoint(point, x, bearing)));
}
} else {
result.push(Object.assign({}, {bearing}, point));
}
}
}
});