Manage multi geometries modes
This commit is contained in:
@@ -9,6 +9,9 @@ goog.require('ol.MapBrowserEvent');
|
|||||||
goog.require('ol.MapBrowserEvent.EventType');
|
goog.require('ol.MapBrowserEvent.EventType');
|
||||||
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.MultiPoint');
|
||||||
|
goog.require('ol.geom.MultiPolygon');
|
||||||
goog.require('ol.geom.Point');
|
goog.require('ol.geom.Point');
|
||||||
goog.require('ol.geom.Polygon');
|
goog.require('ol.geom.Polygon');
|
||||||
goog.require('ol.interaction.Interaction');
|
goog.require('ol.interaction.Interaction');
|
||||||
@@ -396,7 +399,10 @@ ol.interaction.Draw.prototype.finishDrawing_ = function(event) {
|
|||||||
goog.asserts.assert(!goog.isNull(sketchFeature));
|
goog.asserts.assert(!goog.isNull(sketchFeature));
|
||||||
var coordinates;
|
var coordinates;
|
||||||
var geometry = sketchFeature.getGeometry();
|
var geometry = sketchFeature.getGeometry();
|
||||||
if (this.mode_ === ol.interaction.DrawMode.LINE_STRING) {
|
if (this.mode_ === ol.interaction.DrawMode.POINT) {
|
||||||
|
goog.asserts.assertInstanceof(geometry, ol.geom.Point);
|
||||||
|
coordinates = geometry.getCoordinates();
|
||||||
|
} else if (this.mode_ === ol.interaction.DrawMode.LINE_STRING) {
|
||||||
goog.asserts.assertInstanceof(geometry, ol.geom.LineString);
|
goog.asserts.assertInstanceof(geometry, ol.geom.LineString);
|
||||||
coordinates = geometry.getCoordinates();
|
coordinates = geometry.getCoordinates();
|
||||||
// remove the redundant last point
|
// remove the redundant last point
|
||||||
@@ -408,6 +414,16 @@ ol.interaction.Draw.prototype.finishDrawing_ = function(event) {
|
|||||||
// force clockwise order for exterior ring
|
// force clockwise order for exterior ring
|
||||||
sketchFeature.setGeometry(new ol.geom.Polygon(coordinates));
|
sketchFeature.setGeometry(new ol.geom.Polygon(coordinates));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cast multi-part geometries
|
||||||
|
if (this.type_ === ol.geom.GeometryType.MULTI_POINT) {
|
||||||
|
sketchFeature.setGeometry(new ol.geom.MultiPoint([coordinates]));
|
||||||
|
} else if (this.type_ === ol.geom.GeometryType.MULTI_LINE_STRING) {
|
||||||
|
sketchFeature.setGeometry(new ol.geom.MultiLineString([coordinates]));
|
||||||
|
} else if (this.type_ === ol.geom.GeometryType.MULTI_POLYGON) {
|
||||||
|
sketchFeature.setGeometry(new ol.geom.MultiPolygon([coordinates]));
|
||||||
|
}
|
||||||
|
|
||||||
if (this.layer_) {
|
if (this.layer_) {
|
||||||
this.layer_.getSource().addFeature(sketchFeature);
|
this.layer_.getSource().addFeature(sketchFeature);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user