Added circle drawing to draw interaction.
This commit is contained in:
@@ -13,6 +13,7 @@ goog.require('ol.MapBrowserEvent');
|
||||
goog.require('ol.MapBrowserEvent.EventType');
|
||||
goog.require('ol.Object');
|
||||
goog.require('ol.events.condition');
|
||||
goog.require('ol.geom.Circle');
|
||||
goog.require('ol.geom.GeometryType');
|
||||
goog.require('ol.geom.LineString');
|
||||
goog.require('ol.geom.MultiLineString');
|
||||
@@ -294,6 +295,8 @@ ol.interaction.Draw.handleUpEvent_ = function(event) {
|
||||
if (goog.isNull(this.finishCoordinate_)) {
|
||||
this.startDrawing_(event);
|
||||
} else if (this.mode_ === ol.interaction.DrawMode.POINT ||
|
||||
this.mode_ === ol.interaction.DrawMode.CIRCLE &&
|
||||
!goog.isNull(this.finishCoordinate_) ||
|
||||
this.atFinish_(event)) {
|
||||
this.finishDrawing();
|
||||
} else {
|
||||
@@ -402,6 +405,10 @@ ol.interaction.Draw.prototype.startDrawing_ = function(event) {
|
||||
start.slice()]));
|
||||
this.sketchPolygonCoords_ = [[start.slice(), start.slice()]];
|
||||
geometry = new ol.geom.Polygon(this.sketchPolygonCoords_);
|
||||
} else if (this.mode_ === ol.interaction.DrawMode.CIRCLE) {
|
||||
geometry = new ol.geom.Circle(start.slice(), 1000);
|
||||
this.sketchLine_ = new ol.Feature(new ol.geom.LineString([start.slice(),
|
||||
start.slice()]));
|
||||
}
|
||||
}
|
||||
goog.asserts.assert(goog.isDef(geometry));
|
||||
@@ -424,7 +431,7 @@ ol.interaction.Draw.prototype.startDrawing_ = function(event) {
|
||||
ol.interaction.Draw.prototype.modifyDrawing_ = function(event) {
|
||||
var coordinate = event.coordinate;
|
||||
var geometry = this.sketchFeature_.getGeometry();
|
||||
var coordinates, last;
|
||||
var coordinates, last, sketchLineGeom;
|
||||
if (this.mode_ === ol.interaction.DrawMode.POINT) {
|
||||
goog.asserts.assertInstanceof(geometry, ol.geom.Point);
|
||||
last = geometry.getCoordinates();
|
||||
@@ -438,6 +445,9 @@ ol.interaction.Draw.prototype.modifyDrawing_ = function(event) {
|
||||
} else if (this.mode_ === ol.interaction.DrawMode.POLYGON) {
|
||||
goog.asserts.assertInstanceof(geometry, ol.geom.Polygon);
|
||||
coordinates = this.sketchPolygonCoords_[0];
|
||||
} else if (this.mode_ === ol.interaction.DrawMode.CIRCLE) {
|
||||
goog.asserts.assertInstanceof(geometry, ol.geom.Circle);
|
||||
coordinates = geometry.getCenter();
|
||||
}
|
||||
if (this.atFinish_(event)) {
|
||||
// snap to finish
|
||||
@@ -453,11 +463,17 @@ ol.interaction.Draw.prototype.modifyDrawing_ = function(event) {
|
||||
goog.asserts.assertInstanceof(geometry, ol.geom.LineString);
|
||||
geometry.setCoordinates(coordinates);
|
||||
} else if (this.mode_ === ol.interaction.DrawMode.POLYGON) {
|
||||
var sketchLineGeom = this.sketchLine_.getGeometry();
|
||||
sketchLineGeom = this.sketchLine_.getGeometry();
|
||||
goog.asserts.assertInstanceof(sketchLineGeom, ol.geom.LineString);
|
||||
sketchLineGeom.setCoordinates(coordinates);
|
||||
goog.asserts.assertInstanceof(geometry, ol.geom.Polygon);
|
||||
geometry.setCoordinates(this.sketchPolygonCoords_);
|
||||
} else if (this.mode_ === ol.interaction.DrawMode.CIRCLE) {
|
||||
goog.asserts.assertInstanceof(geometry, ol.geom.Circle);
|
||||
sketchLineGeom = this.sketchLine_.getGeometry();
|
||||
goog.asserts.assertInstanceof(sketchLineGeom, ol.geom.LineString);
|
||||
sketchLineGeom.setCoordinates([geometry.getCenter(), coordinate]);
|
||||
geometry.setRadius(sketchLineGeom.getLength());
|
||||
}
|
||||
}
|
||||
this.updateSketchFeatures_();
|
||||
@@ -561,7 +577,7 @@ ol.interaction.Draw.prototype.shouldStopEvent = goog.functions.FALSE;
|
||||
|
||||
|
||||
/**
|
||||
* Redraw the skecth features.
|
||||
* Redraw the sketch features.
|
||||
* @private
|
||||
*/
|
||||
ol.interaction.Draw.prototype.updateSketchFeatures_ = function() {
|
||||
@@ -610,6 +626,8 @@ ol.interaction.Draw.getMode_ = function(type) {
|
||||
} else if (type === ol.geom.GeometryType.POLYGON ||
|
||||
type === ol.geom.GeometryType.MULTI_POLYGON) {
|
||||
mode = ol.interaction.DrawMode.POLYGON;
|
||||
} else if (type === ol.geom.GeometryType.CIRCLE) {
|
||||
mode = ol.interaction.DrawMode.CIRCLE;
|
||||
}
|
||||
goog.asserts.assert(goog.isDef(mode));
|
||||
return mode;
|
||||
@@ -624,5 +642,6 @@ ol.interaction.Draw.getMode_ = function(type) {
|
||||
ol.interaction.DrawMode = {
|
||||
POINT: 'Point',
|
||||
LINE_STRING: 'LineString',
|
||||
POLYGON: 'Polygon'
|
||||
POLYGON: 'Polygon',
|
||||
CIRCLE: 'Circle'
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user