import turfBearing from "@turf/bearing";
import turfDestination from "@turf/destination";
import turfDistance from "@turf/distance";
import { lineString as turfLineString } from "@turf/helpers";
import turfLineDistance from "@turf/length";
import turfLineArc from "@turf/line-arc";
import turfMidpoint from "@turf/midpoint";
import {
  toMercator as turfToMercator,
  toWgs84 as turfToWgs84
} from "@turf/projection";
const getArcFeatureItem = (coordinates) => {
  const feature = turfLineString(coordinates);
  const parsedLineString = turfToWgs84(feature);
  const {
    geometry: {
      coordinates: [start, end]
    }
  } = parsedLineString;
  const lineDistance = turfLineDistance(parsedLineString);
  const midPoint = turfMidpoint(start, end);
  const bearing = turfBearing(start, end) - 90;
  const center = turfDestination(midPoint, lineDistance, bearing);
  const lineArc = turfLineArc(
    center,
    turfDistance(center, start),
    turfBearing(center, end),
    turfBearing(center, start),
    { steps: 256 }
  );
  return turfToMercator(lineArc);
};
const getArcLineFeatures = (path, featureProperties) => {
  if (path.length < 2) {
    return [];
  }
  const finalCoordinates = [];
  for (let i = 0; i < path.length - 1; i++) {
    const start = path[i];
    const end = path[i + 1];
    const coordinates = [
      [start.longitude, start.latitude],
      [end.longitude, end.latitude]
    ];
    const feature = getArcFeatureItem(coordinates);
    finalCoordinates.push(...feature.geometry.coordinates.reverse());
  }
  const finalFeature = turfLineString(finalCoordinates, {
    ...featureProperties
  });
  return [finalFeature];
};
export {
  getArcLineFeatures
};
//# sourceMappingURL=get-arc-line-features.js.map
