Add ol.interaction.Draw#extend

This commit adds an `extend` method to the draw interaction. This method makes it possible to extend (continue drawing) an existing line string feature. It only works on line string features, where this functionality makes the most sense.

Here's an example on how to use `extend`:

```js
var vectorSource = vectorLayer.getSource();
vectroSource.removeFeature(feature);
drawInteraction.extend(feature);
```
This commit is contained in:
Éric Lemoine
2015-08-25 13:53:13 +02:00
parent f5df71ba70
commit 95030cd838
2 changed files with 58 additions and 0 deletions

View File

@@ -781,12 +781,43 @@ describe('ol.interaction.Draw', function() {
expect(coordinates[0][0][1]).to.roughlyEqual(20, 1e-9);
});
});
describe('extend an existing feature', function() {
var draw;
var feature;
beforeEach(function() {
draw = new ol.interaction.Draw({
source: source,
type: ol.geom.GeometryType.LINE_STRING
});
map.addInteraction(draw);
feature = new ol.Feature(
new ol.geom.LineString([[0, 0], [1, 1], [2, 0]]));
});
it('sets the initial state', function() {
draw.extend(feature);
expect(draw.sketchCoords_).to.have.length(4);
expect(draw.sketchCoords_).to.eql([[0, 0], [1, 1], [2, 0], [2, 0]]);
expect(draw.finishCoordinate_).to.eql([2, 0]);
});
it('dispatches a drawstart event', function() {
var spy = sinon.spy();
goog.events.listen(draw, ol.interaction.DrawEventType.DRAWSTART, spy);
draw.extend(feature);
expect(spy.callCount).to.be(1);
});
});
});
goog.require('goog.dispose');
goog.require('goog.events');
goog.require('goog.events.BrowserEvent');
goog.require('goog.style');
goog.require('ol.Feature');
goog.require('ol.Map');
goog.require('ol.MapBrowserPointerEvent');
goog.require('ol.View');