in modules/edit-modes/src/lib/draw-90degree-polygon-mode.ts [97:157]
handleClick(event: ClickEvent, props: ModeProps<FeatureCollection>) {
const { picks } = event;
const tentativeFeature = this.getTentativeGuide(props);
this.addClickSequence(event);
const clickSequence = this.getClickSequence();
if (!tentativeFeature) {
// nothing else to do
return;
}
if (clickSequence.length === 3 && tentativeFeature.geometry.type === 'LineString') {
const lineString: LineString = tentativeFeature.geometry;
// Tweak the clicked position to be the snapped 90 degree point along the polygon
clickSequence[clickSequence.length - 1] =
lineString.coordinates[lineString.coordinates.length - 1];
} else if (clickSequence.length > 3 && tentativeFeature.geometry.type === 'Polygon') {
const polygon: Polygon = tentativeFeature.geometry;
// Tweak the clicked position to be the snapped 90 degree point along the polygon
clickSequence[clickSequence.length - 1] =
polygon.coordinates[0][polygon.coordinates[0].length - 2];
const clickedEditHandle = getPickedEditHandle(picks);
if (
clickedEditHandle &&
Array.isArray(clickedEditHandle.properties.positionIndexes) &&
(clickedEditHandle.properties.positionIndexes[1] === 0 ||
clickedEditHandle.properties.positionIndexes[1] === polygon.coordinates[0].length - 3)
) {
// They clicked the first or last point (or double-clicked), so complete the polygon
const polygonToAdd: Polygon = {
type: 'Polygon',
coordinates: this.finalizedCoordinates([...polygon.coordinates[0]]),
};
this.resetClickSequence();
const editAction = this.getAddFeatureOrBooleanPolygonAction(polygonToAdd, props);
if (editAction) {
props.onEdit(editAction);
}
}
}
// Trigger pointer move right away in order for it to update edit handles (to support double-click)
const fakePointerMoveEvent: PointerMoveEvent = {
screenCoords: [-1, -1],
mapCoords: event.mapCoords,
picks: [],
pointerDownPicks: null,
pointerDownScreenCoords: null,
pointerDownMapCoords: null,
cancelPan: () => {},
sourceEvent: null,
};
this.handlePointerMove(fakePointerMoveEvent, props);
}