Skip to content

Commit

Permalink
Use the createBox() geometry function
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaub committed Oct 16, 2016
1 parent 9b12cac commit 1e6c447
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions examples/draw-features.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
goog.require('ol.Map');
goog.require('ol.View');
goog.require('ol.geom.Polygon');
goog.require('ol.interaction.Draw');
goog.require('ol.layer.Tile');
goog.require('ol.layer.Vector');
Expand Down Expand Up @@ -51,30 +50,18 @@ var draw; // global so we can remove it later
function addInteraction() {
var value = typeSelect.value;
if (value !== 'None') {
var geometryFunction, maxPoints;
var geometryFunction;
if (value === 'Square') {
value = 'Circle';
geometryFunction = ol.interaction.Draw.createRegularPolygon(4);
} else if (value === 'Box') {
value = 'LineString';
maxPoints = 2;
geometryFunction = function(coordinates, geometry) {
if (!geometry) {
geometry = new ol.geom.Polygon(null);
}
var start = coordinates[0];
var end = coordinates[1];
geometry.setCoordinates([
[start, [start[0], end[1]], end, [end[0], start[1]], start]
]);
return geometry;
};
value = 'Circle';
geometryFunction = ol.interaction.Draw.createBox();
}
draw = new ol.interaction.Draw({
source: source,
type: /** @type {ol.geom.GeometryType} */ (value),
geometryFunction: geometryFunction,
maxPoints: maxPoints
geometryFunction: geometryFunction
});
map.addInteraction(draw);
}
Expand Down

0 comments on commit 1e6c447

Please sign in to comment.