Allow user to set drawing mode
This commit is contained in:
@@ -33,6 +33,15 @@
|
|||||||
<div class="span12">
|
<div class="span12">
|
||||||
<h4 id="title">Draw features example</h4>
|
<h4 id="title">Draw features example</h4>
|
||||||
<p id="shortdesc">Example of using the Draw interaction.</p>
|
<p id="shortdesc">Example of using the Draw interaction.</p>
|
||||||
|
<form class="form-inline">
|
||||||
|
<label>Geometry type </label>
|
||||||
|
<select id="mode">
|
||||||
|
<option value="polygon">Polygon</option>
|
||||||
|
<option value="linestring">Linestring</option>
|
||||||
|
<option value="point">Point</option>
|
||||||
|
</select>
|
||||||
|
</form>
|
||||||
|
|
||||||
<div id="docs">
|
<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>
|
<p>See the <a href="draw-features.js" target="_blank">draw-features.js source</a> to see how this is done.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -83,11 +83,24 @@ var vector = new ol.layer.Vector({
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var modeSelect = document.getElementById('mode');
|
||||||
|
|
||||||
var draw = new ol.interaction.Draw({
|
var draw = new ol.interaction.Draw({
|
||||||
layer: vector,
|
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({
|
var map = new ol.Map({
|
||||||
interactions: ol.interaction.defaults().extend([draw]),
|
interactions: ol.interaction.defaults().extend([draw]),
|
||||||
layers: [raster, vector],
|
layers: [raster, vector],
|
||||||
|
|||||||
Reference in New Issue
Block a user