Skip to content

finish draw-polygon mode cartesian and add tests#641

Open
eKerney wants to merge 1 commit into
visgl:masterfrom
eKerney:feature/editmode-nomap-updates
Open

finish draw-polygon mode cartesian and add tests#641
eKerney wants to merge 1 commit into
visgl:masterfrom
eKerney:feature/editmode-nomap-updates

Conversation

@eKerney
Copy link
Copy Markdown
Contributor

@eKerney eKerney commented May 22, 2026

Finished updating draw-polygon-mode.ts to use turf(geo modes), and simple geometric functions(cartesian modes). Did not attempt turfJS kinks function which involves another order of complexity. Created simple geometry functions and tests, needed to bypass linter checks for complexity on validateAndCreateHole().

@marcomuser
Copy link
Copy Markdown

marcomuser commented May 26, 2026

Fantastic! I just stumbled over a similar issue with the ThreeClickPolygonMode. That would also need a cartesian handling. Are you planning to handle the other modes as well in future PRs?

I'm currently subclassing that mode to make it work with cartesian layers:

class CartesianDrawRectangleUsingThreePointsMode extends DrawRectangleUsingThreePointsMode {
  override getThreeClickPolygon(
    coord1: number[],
    coord2: number[],
    coord3: number[]
  ) {
    const [x1, y1] = coord1;
    const [x2, y2] = coord2;
    const [x3, y3] = coord3;

    const ex = x2 - x1;
    const ey = y2 - y1;
    const len = Math.sqrt(ex * ex + ey * ey);
    if (len === 0) return null;

    const px = -ey / len;
    const py = ex / len;
    const d = (x3 - x1) * px + (y3 - y1) * py;

    const p3 = [x2 + d * px, y2 + d * py];
    const p4 = [x1 + d * px, y1 + d * py];

    return {
      type: 'Feature' as const,
      properties: { shape: 'Rectangle' },
      geometry: {
        type: 'Polygon' as const,
        coordinates: [[coord1, coord2, p3, p4, coord1]],
      },
    };
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants