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