finish draw-polygon mode cartesian and add tests#641
Open
eKerney wants to merge 1 commit into
Open
Conversation
|
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]],
},
};
}
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Finished updating
draw-polygon-mode.tsto 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 onvalidateAndCreateHole().