Add undo to draw-features example

This commit is contained in:
Andreas Hocevar
2020-10-29 22:55:08 +01:00
parent 48f357d518
commit 4980e58db0
2 changed files with 8 additions and 3 deletions

View File

@@ -6,17 +6,18 @@ docs: >
Example of using the Draw interaction. Select a geometry type from the Example of using the Draw interaction. Select a geometry type from the
dropdown above to start drawing. To finish drawing, click the last dropdown above to start drawing. To finish drawing, click the last
point. To activate freehand drawing for lines, polygons, and circles, hold point. To activate freehand drawing for lines, polygons, and circles, hold
the `Shift` key. the `Shift` key. To remove the last point of a line or polygon, press "Undo".
tags: "draw, edit, freehand, vector" tags: "draw, edit, freehand, vector"
--- ---
<div id="map" class="map"></div> <div id="map" class="map"></div>
<form class="form-inline"> <form class="form-inline">
<label for="type">Geometry type &nbsp;</label> <label for="type">Geometry type: &nbsp;</label>
<select id="type"> <select class="form-control mr-2 mb-2 mt-2" id="type">
<option value="Point">Point</option> <option value="Point">Point</option>
<option value="LineString">LineString</option> <option value="LineString">LineString</option>
<option value="Polygon">Polygon</option> <option value="Polygon">Polygon</option>
<option value="Circle">Circle</option> <option value="Circle">Circle</option>
<option value="None">None</option> <option value="None">None</option>
</select> </select>
<input class="form-control mr-2 mb-2 mt-2" type="button" value="Undo" id="undo"></input>
</form> </form>

View File

@@ -45,4 +45,8 @@ typeSelect.onchange = function () {
addInteraction(); addInteraction();
}; };
document.getElementById('undo').addEventListener('click', function () {
draw.removeLastPoint();
});
addInteraction(); addInteraction();