Remove setMode method from interaction in favor of add/removeInteraction

This makes the example a bit more awkward, but eventually adding and removing interactions will be the job of an editing control.
This commit is contained in:
Tim Schaub
2013-11-11 16:11:52 -07:00
parent dbcfdbc76f
commit 8194ba9f0a
3 changed files with 26 additions and 33 deletions

View File

@@ -87,26 +87,7 @@ var vector = new ol.layer.Vector({
})
});
var modeSelect = document.getElementById('mode');
var draw = new ol.interaction.Draw({
layer: vector,
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],
renderer: ol.RendererHint.CANVAS,
target: 'map',
@@ -115,3 +96,27 @@ var map = new ol.Map({
zoom: 4
})
});
var modeSelect = document.getElementById('mode');
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)
});
map.addInteraction(draw);
}
/**
* Let user change the draw mode.
* @param {Event} e Change event.
*/
modeSelect.onchange = function(e) {
map.removeInteraction(draw);
addInteraction();
};
addInteraction();