terra-draw
terra-draw copied to clipboard
[Feature Request] Enable read-access to currentId from Linestring mode subclasses
Is your feature request related to a problem? Please describe.
As mentioned in https://github.com/JamesLMilner/terra-draw/issues/714, we've been building out a custom extension of the linestring.mode. Specifically, we want to restrict which cursors are used and whether clicks start the drawing of a new line based on external factors (in our case, a new line should only be drawn from an existing line in the store). So far, the extension points available have made this fairly easy to do. But we're missing one piece of information available in TerraDrawLineStringMode that is currently completely private api.
Our subclass of linestring mode can't easily determine whether a line has been started yet using public api (either currentId or currentCoordinate would answer the question we're asking). That information is available during the snapping.toCustom phase, but we need the info before a click occurs.
Describe your proposed idea for the solution to this problem
It would be lovely to add a protected getCurrentCoordinate() or getCurrentId() method to TerraDrawLineStringMode that makes it possible to access those details from subclasses where needed. And because we already expose this information when sending details to this.snapping.toCustom, we don't make future api changes any harder than they already are:
https://github.com/JamesLMilner/terra-draw/blob/b69c2c93e1c3585a63539bd63fcc742911fcccb7/packages/terra-draw/src/modes/linestring/linestring.mode.ts#L1044-L1055
Describe alternatives you've considered We're currently handling the question by reaching into private as seen below:
private isPlacingFirstPoint(): boolean {
// If currentId is not set, we haven't placed the first point yet
return ((this as any).currentId === undefined);
}
We could also setup tracking of this information in various places in our subclass if needed. But because the information is already easily accessible, thought it was worth asking if we should expose it. Happy to send in a PR if you want to do this