Allow user to set drawing mode

This commit is contained in:
Tim Schaub
2013-11-01 11:23:31 -06:00
parent e3faa76770
commit 2f07433593
2 changed files with 23 additions and 1 deletions

View File

@@ -33,6 +33,15 @@
<div class="span12">
<h4 id="title">Draw features example</h4>
<p id="shortdesc">Example of using the Draw interaction.</p>
<form class="form-inline">
<label>Geometry type &nbsp;</label>
<select id="mode">
<option value="polygon">Polygon</option>
<option value="linestring">Linestring</option>
<option value="point">Point</option>
</select>
</form>
<div id="docs">
<p>See the <a href="draw-features.js" target="_blank">draw-features.js source</a> to see how this is done.</p>
</div>

View File

@@ -83,11 +83,24 @@ var vector = new ol.layer.Vector({
})
});
var modeSelect = document.getElementById('mode');
var draw = new ol.interaction.Draw({
layer: vector,
mode: /** @type {ol.interaction.DrawMode} */ ('polygon')
mode: /** @type {ol.interaction.DrawMode} */
(modeSelect.options[modeSelect.selectedIndex].value)
});
/**
* Let user change the draw mode.
* @param {Event} e Change event.
*/
modeSelect.onchange = function(e) {
draw.setMode(/** @type {ol.interaction.DrawMode} */
(modeSelect.options[modeSelect.selectedIndex].value));
};
var map = new ol.Map({
interactions: ol.interaction.defaults().extend([draw]),
layers: [raster, vector],