export default function createPathMarkers()

in modules/layers/src/layers/path-marker-layer/create-path-markers.ts [15:68]


export default function createPathMarkers({
  data,
  getPath = (x, context) => x.path,
  getDirection = (x) => x.direction,
  getColor = (x) => DEFAULT_COLOR,
  getMarkerPercentages = (x, info) => [0.5],
  projectFlat,
}) {
  const markers = [];

  for (const object of data) {
    const path = getPath(object, null);
    const direction = getDirection(object) || DEFAULT_DIRECTION;
    const color = getColor(object);

    const vPoints = path.map((p) => new Vector2(p));
    const vPointsReverse = vPoints.slice(0).reverse();

    // calculate total length
    const lineLength = getLineLength(vPoints);

    // Ask for where to put markers
    const percentages = getMarkerPercentages(object, { lineLength });

    // Create the markers
    for (const percentage of percentages) {
      if (direction.forward) {
        const marker = createMarkerAlongPath({
          path: vPoints,
          percentage,
          lineLength,
          color,
          object,
          projectFlat,
        });
        markers.push(marker);
      }

      if (direction.backward) {
        const marker = createMarkerAlongPath({
          path: vPointsReverse,
          percentage,
          lineLength,
          color,
          object,
          projectFlat,
        });
        markers.push(marker);
      }
    }
  }

  return markers;
}