Use Mode.LINE_STRING for Circle geometries
Make predefined geometry functions compatible with removeLastPoint Add undo to example Make geometry function for Star compatible with use of removeLastPoint Additional createRegularPolygon tests
This commit is contained in:
@@ -43,28 +43,30 @@ function addInteraction() {
|
||||
} else if (value === 'Star') {
|
||||
value = 'Circle';
|
||||
geometryFunction = function (coordinates, geometry) {
|
||||
const center = coordinates[0];
|
||||
const last = coordinates[1];
|
||||
const dx = center[0] - last[0];
|
||||
const dy = center[1] - last[1];
|
||||
const radius = Math.sqrt(dx * dx + dy * dy);
|
||||
const rotation = Math.atan2(dy, dx);
|
||||
const newCoordinates = [];
|
||||
const numPoints = 12;
|
||||
for (let i = 0; i < numPoints; ++i) {
|
||||
const angle = rotation + (i * 2 * Math.PI) / numPoints;
|
||||
const fraction = i % 2 === 0 ? 1 : 0.5;
|
||||
const offsetX = radius * fraction * Math.cos(angle);
|
||||
const offsetY = radius * fraction * Math.sin(angle);
|
||||
newCoordinates.push([center[0] + offsetX, center[1] + offsetY]);
|
||||
if (coordinates.length) {
|
||||
const center = coordinates[0];
|
||||
const last = coordinates[coordinates.length - 1];
|
||||
const dx = center[0] - last[0];
|
||||
const dy = center[1] - last[1];
|
||||
const radius = Math.sqrt(dx * dx + dy * dy);
|
||||
const rotation = Math.atan2(dy, dx);
|
||||
const newCoordinates = [];
|
||||
const numPoints = 12;
|
||||
for (let i = 0; i < numPoints; ++i) {
|
||||
const angle = rotation + (i * 2 * Math.PI) / numPoints;
|
||||
const fraction = i % 2 === 0 ? 1 : 0.5;
|
||||
const offsetX = radius * fraction * Math.cos(angle);
|
||||
const offsetY = radius * fraction * Math.sin(angle);
|
||||
newCoordinates.push([center[0] + offsetX, center[1] + offsetY]);
|
||||
}
|
||||
newCoordinates.push(newCoordinates[0].slice());
|
||||
if (!geometry) {
|
||||
geometry = new Polygon([newCoordinates]);
|
||||
} else {
|
||||
geometry.setCoordinates([newCoordinates]);
|
||||
}
|
||||
return geometry;
|
||||
}
|
||||
newCoordinates.push(newCoordinates[0].slice());
|
||||
if (!geometry) {
|
||||
geometry = new Polygon([newCoordinates]);
|
||||
} else {
|
||||
geometry.setCoordinates([newCoordinates]);
|
||||
}
|
||||
return geometry;
|
||||
};
|
||||
}
|
||||
draw = new Draw({
|
||||
@@ -84,4 +86,8 @@ typeSelect.onchange = function () {
|
||||
addInteraction();
|
||||
};
|
||||
|
||||
document.getElementById('undo').addEventListener('click', function () {
|
||||
draw.removeLastPoint();
|
||||
});
|
||||
|
||||
addInteraction();
|
||||
|
||||
Reference in New Issue
Block a user