Merge pull request #2059 from bartvde/draw-geometryname
Add geometryName option to ol.interaction.Draw (r=@elemoine)
This commit is contained in:
@@ -1608,7 +1608,8 @@ olx.interaction.DragZoomOptions.prototype.style;
|
||||
* snapTolerance: (number|undefined),
|
||||
* type: ol.geom.GeometryType,
|
||||
* minPointsPerRing: (number|undefined),
|
||||
* style: (ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction|undefined)}}
|
||||
* style: (ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction|undefined),
|
||||
* geometryName: (string|undefined)}}
|
||||
* @todo api
|
||||
*/
|
||||
olx.interaction.DrawOptions;
|
||||
@@ -1658,6 +1659,13 @@ olx.interaction.DrawOptions.prototype.minPointsPerRing;
|
||||
olx.interaction.DrawOptions.prototype.style;
|
||||
|
||||
|
||||
/**
|
||||
* Geometry name to use for features created by the draw interaction.
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
olx.interaction.DrawOptions.prototype.geometryName;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{condition: (ol.events.ConditionType|undefined),
|
||||
* pixelDelta: (number|undefined)}}
|
||||
|
||||
@@ -182,6 +182,13 @@ ol.interaction.Draw = function(options) {
|
||||
options.style : ol.interaction.Draw.getDefaultStyleFunction()
|
||||
});
|
||||
|
||||
/**
|
||||
* Name of the geometry attribute for newly created features.
|
||||
* @type {string|undefined}
|
||||
* @private
|
||||
*/
|
||||
this.geometryName_ = options.geometryName;
|
||||
|
||||
};
|
||||
goog.inherits(ol.interaction.Draw, ol.interaction.Pointer);
|
||||
|
||||
@@ -350,7 +357,11 @@ ol.interaction.Draw.prototype.startDrawing_ = function(event) {
|
||||
}
|
||||
}
|
||||
goog.asserts.assert(goog.isDef(geometry));
|
||||
this.sketchFeature_ = new ol.Feature(geometry);
|
||||
this.sketchFeature_ = new ol.Feature();
|
||||
if (goog.isDef(this.geometryName_)) {
|
||||
this.sketchFeature_.setGeometryName(this.geometryName_);
|
||||
}
|
||||
this.sketchFeature_.setGeometry(geometry);
|
||||
this.updateSketchFeatures_();
|
||||
this.dispatchEvent(new ol.DrawEvent(ol.DrawEventType.DRAWSTART,
|
||||
this.sketchFeature_));
|
||||
|
||||
@@ -69,6 +69,28 @@ describe('ol.interaction.Draw', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('specifying a geometryName', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
var draw = new ol.interaction.Draw({
|
||||
source: source,
|
||||
geometryName: 'the_geom',
|
||||
type: ol.geom.GeometryType.POINT
|
||||
});
|
||||
map.addInteraction(draw);
|
||||
});
|
||||
|
||||
it('creates a feature with the correct geometryName', function() {
|
||||
simulateEvent('pointermove', 10, 20);
|
||||
simulateEvent('pointerdown', 10, 20);
|
||||
simulateEvent('pointerup', 10, 20);
|
||||
var features = source.getFeatures();
|
||||
var geometry = features[0].getGeometry();
|
||||
expect(features[0].getGeometryName()).to.equal('the_geom');
|
||||
expect(geometry).to.be.a(ol.geom.Point);
|
||||
});
|
||||
});
|
||||
|
||||
describe('drawing points', function() {
|
||||
var draw;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user