Use geometry type enum for configuring draw interaction
This allows us to cast single-part geometries to multi-part types before adding features to the target layer. This doesn't yet allow for drawing multi-part geometries with multiple parts. That can be handled separately.
This commit is contained in:
@@ -35,7 +35,7 @@
|
||||
<p id="shortdesc">Example of using the Draw interaction.</p>
|
||||
<form class="form-inline">
|
||||
<label>Geometry type </label>
|
||||
<select id="mode">
|
||||
<select id="type">
|
||||
<option value="polygon">Polygon</option>
|
||||
<option value="linestring">Linestring</option>
|
||||
<option value="point">Point</option>
|
||||
|
||||
@@ -97,24 +97,24 @@ var map = new ol.Map({
|
||||
})
|
||||
});
|
||||
|
||||
var modeSelect = document.getElementById('mode');
|
||||
var typeSelect = document.getElementById('type');
|
||||
|
||||
var draw; // global so we can remove it later
|
||||
function addInteraction() {
|
||||
draw = new ol.interaction.Draw({
|
||||
layer: vector,
|
||||
mode: /** @type {ol.interaction.DrawMode} */
|
||||
(modeSelect.options[modeSelect.selectedIndex].value)
|
||||
type: /** @type {ol.geom.GeometryType} */
|
||||
(typeSelect.options[typeSelect.selectedIndex].value)
|
||||
});
|
||||
map.addInteraction(draw);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Let user change the draw mode.
|
||||
* Let user change the geometry type.
|
||||
* @param {Event} e Change event.
|
||||
*/
|
||||
modeSelect.onchange = function(e) {
|
||||
typeSelect.onchange = function(e) {
|
||||
map.removeInteraction(draw);
|
||||
addInteraction();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user