Show sketch vertex for all geometry types

This commit is contained in:
Andreas Hocevar
2014-06-30 19:40:28 +02:00
parent c6083f0592
commit 29370a04aa
+24 -4
View File
@@ -301,6 +301,8 @@ ol.interaction.Draw.prototype.handlePointerMove_ = function(event) {
this.startDrawing_(event); this.startDrawing_(event);
} else if (!goog.isNull(this.finishCoordinate_)) { } else if (!goog.isNull(this.finishCoordinate_)) {
this.modifyDrawing_(event); this.modifyDrawing_(event);
} else {
this.createOrUpdateSketchPoint_(event);
} }
return true; return true;
}; };
@@ -348,6 +350,23 @@ ol.interaction.Draw.prototype.atFinish_ = function(event) {
}; };
/**
* @param {ol.MapBrowserEvent} event Event.
* @private
*/
ol.interaction.Draw.prototype.createOrUpdateSketchPoint_ = function(event) {
var coordinates = event.coordinate.slice();
if (goog.isNull(this.sketchPoint_)) {
this.sketchPoint_ = new ol.Feature(new ol.geom.Point(coordinates));
this.updateSketchFeatures_();
} else {
var sketchPointGeom = this.sketchPoint_.getGeometry();
goog.asserts.assertInstanceof(sketchPointGeom, ol.geom.Point);
sketchPointGeom.setCoordinates(coordinates);
}
};
/** /**
* Start the drawing. * Start the drawing.
* @param {ol.MapBrowserEvent} event Event. * @param {ol.MapBrowserEvent} event Event.
@@ -360,8 +379,6 @@ ol.interaction.Draw.prototype.startDrawing_ = function(event) {
if (this.mode_ === ol.interaction.DrawMode.POINT) { if (this.mode_ === ol.interaction.DrawMode.POINT) {
geometry = new ol.geom.Point(start.slice()); geometry = new ol.geom.Point(start.slice());
} else { } else {
this.sketchPoint_ = new ol.Feature(new ol.geom.Point(start.slice()));
if (this.mode_ === ol.interaction.DrawMode.LINE_STRING) { if (this.mode_ === ol.interaction.DrawMode.LINE_STRING) {
geometry = new ol.geom.LineString([start.slice(), start.slice()]); geometry = new ol.geom.LineString([start.slice(), start.slice()]);
} else if (this.mode_ === ol.interaction.DrawMode.POLYGON) { } else if (this.mode_ === ol.interaction.DrawMode.POLYGON) {
@@ -439,7 +456,7 @@ ol.interaction.Draw.prototype.modifyDrawing_ = function(event) {
ol.interaction.Draw.prototype.addToDrawing_ = function(event) { ol.interaction.Draw.prototype.addToDrawing_ = function(event) {
var coordinate = event.coordinate; var coordinate = event.coordinate;
var geometry = this.sketchFeature_.getGeometry(); var geometry = this.sketchFeature_.getGeometry();
var coordinates, last; var coordinates;
if (this.mode_ === ol.interaction.DrawMode.LINE_STRING) { if (this.mode_ === ol.interaction.DrawMode.LINE_STRING) {
this.finishCoordinate_ = coordinate.slice(); this.finishCoordinate_ = coordinate.slice();
goog.asserts.assertInstanceof(geometry, ol.geom.LineString); goog.asserts.assertInstanceof(geometry, ol.geom.LineString);
@@ -527,7 +544,10 @@ ol.interaction.Draw.prototype.abortDrawing_ = function() {
* @private * @private
*/ */
ol.interaction.Draw.prototype.updateSketchFeatures_ = function() { ol.interaction.Draw.prototype.updateSketchFeatures_ = function() {
var sketchFeatures = [this.sketchFeature_]; var sketchFeatures = [];
if (!goog.isNull(this.sketchFeature_)) {
sketchFeatures.push(this.sketchFeature_);
}
if (!goog.isNull(this.sketchLine_)) { if (!goog.isNull(this.sketchLine_)) {
sketchFeatures.push(this.sketchLine_); sketchFeatures.push(this.sketchLine_);
} }