in modules/edit-modes/src/utils.ts [364:435]
export function getEditHandlesForGeometry(
geometry: Geometry,
featureIndex: number,
editHandleType: EditHandleType = 'existing'
): EditHandleFeature[] {
let handles: EditHandleFeature[] = [];
switch (geometry.type) {
case 'Point':
// positions are not nested
handles = [
{
type: 'Feature',
properties: {
guideType: 'editHandle',
editHandleType,
positionIndexes: [],
featureIndex,
},
geometry: {
type: 'Point',
coordinates: geometry.coordinates,
},
},
];
break;
case 'MultiPoint':
case 'LineString':
// positions are nested 1 level
handles = handles.concat(
getEditHandlesForCoordinates(geometry.coordinates, [], featureIndex, editHandleType)
);
break;
case 'Polygon':
case 'MultiLineString':
// positions are nested 2 levels
for (let a = 0; a < geometry.coordinates.length; a++) {
handles = handles.concat(
getEditHandlesForCoordinates(geometry.coordinates[a], [a], featureIndex, editHandleType)
);
if (geometry.type === 'Polygon') {
// Don't repeat the first/last handle for Polygons
handles = handles.slice(0, -1);
}
}
break;
case 'MultiPolygon':
// positions are nested 3 levels
for (let a = 0; a < geometry.coordinates.length; a++) {
for (let b = 0; b < geometry.coordinates[a].length; b++) {
handles = handles.concat(
getEditHandlesForCoordinates(
geometry.coordinates[a][b],
[a, b],
featureIndex,
editHandleType
)
);
// Don't repeat the first/last handle for Polygons
handles = handles.slice(0, -1);
}
}
break;
default:
// @ts-expect-error
throw Error(`Unhandled geometry type: ${geometry.type}`);
}
return handles;
}