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:
@@ -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();
|
||||
|
||||
@@ -347,20 +347,6 @@ ol.interaction.Draw.prototype.abortDrawing_ = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the drawing mode.
|
||||
* TODO: Decide if we want interactions to be purely event driven - if so, this
|
||||
* method would be removed, and users would remove this interaction and create a
|
||||
* new one with the desired mode instead.
|
||||
* @param {ol.interaction.DrawMode} mode Draw mode ('point', 'linestring', or
|
||||
* 'polygon').
|
||||
*/
|
||||
ol.interaction.Draw.prototype.setMode = function(mode) {
|
||||
this.abortDrawing_();
|
||||
this.mode_ = mode;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Draw mode.
|
||||
* @enum {string}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
@exportClass ol.Map ol.MapOptions
|
||||
@exportProperty ol.Map.prototype.addControl
|
||||
@exportProperty ol.Map.prototype.addInteraction
|
||||
@exportProperty ol.Map.prototype.addLayer
|
||||
@exportProperty ol.Map.prototype.addOverlay
|
||||
@exportProperty ol.Map.prototype.beforeRender
|
||||
@@ -14,6 +15,7 @@
|
||||
@exportProperty ol.Map.prototype.getRenderer
|
||||
@exportProperty ol.Map.prototype.getViewport
|
||||
@exportProperty ol.Map.prototype.removeControl
|
||||
@exportProperty ol.Map.prototype.removeInteraction
|
||||
@exportProperty ol.Map.prototype.removeLayer
|
||||
@exportProperty ol.Map.prototype.removeOverlay
|
||||
@exportProperty ol.Map.prototype.updateSize
|
||||
|
||||
Reference in New Issue
Block a user