Rename _ol_interaction_Draw_ to Draw

This commit is contained in:
Marc Jansen
2017-12-15 10:35:18 +01:00
committed by Tim Schaub
parent b92118b5ab
commit 4868098495
11 changed files with 108 additions and 107 deletions

View File

@@ -1,6 +1,6 @@
import _ol_Map_ from '../src/ol/Map.js'; import _ol_Map_ from '../src/ol/Map.js';
import _ol_View_ from '../src/ol/View.js'; import _ol_View_ from '../src/ol/View.js';
import _ol_interaction_Draw_ from '../src/ol/interaction/Draw.js'; import Draw from '../src/ol/interaction/Draw.js';
import _ol_interaction_Modify_ from '../src/ol/interaction/Modify.js'; import _ol_interaction_Modify_ from '../src/ol/interaction/Modify.js';
import _ol_interaction_Snap_ from '../src/ol/interaction/Snap.js'; import _ol_interaction_Snap_ from '../src/ol/interaction/Snap.js';
import _ol_layer_Tile_ from '../src/ol/layer/Tile.js'; import _ol_layer_Tile_ from '../src/ol/layer/Tile.js';
@@ -52,7 +52,7 @@ var draw, snap; // global so we can remove them later
var typeSelect = document.getElementById('type'); var typeSelect = document.getElementById('type');
function addInteractions() { function addInteractions() {
draw = new _ol_interaction_Draw_({ draw = new Draw({
source: source, source: source,
type: typeSelect.value type: typeSelect.value
}); });

View File

@@ -1,6 +1,6 @@
import _ol_Map_ from '../src/ol/Map.js'; import _ol_Map_ from '../src/ol/Map.js';
import _ol_View_ from '../src/ol/View.js'; import _ol_View_ from '../src/ol/View.js';
import _ol_interaction_Draw_ from '../src/ol/interaction/Draw.js'; import Draw from '../src/ol/interaction/Draw.js';
import _ol_layer_Tile_ from '../src/ol/layer/Tile.js'; import _ol_layer_Tile_ from '../src/ol/layer/Tile.js';
import _ol_layer_Vector_ from '../src/ol/layer/Vector.js'; import _ol_layer_Vector_ from '../src/ol/layer/Vector.js';
import _ol_source_OSM_ from '../src/ol/source/OSM.js'; import _ol_source_OSM_ from '../src/ol/source/OSM.js';
@@ -31,7 +31,7 @@ var draw; // global so we can remove it later
function addInteraction() { function addInteraction() {
var value = typeSelect.value; var value = typeSelect.value;
if (value !== 'None') { if (value !== 'None') {
draw = new _ol_interaction_Draw_({ draw = new Draw({
source: source, source: source,
type: typeSelect.value type: typeSelect.value
}); });

View File

@@ -1,6 +1,6 @@
import _ol_Map_ from '../src/ol/Map.js'; import _ol_Map_ from '../src/ol/Map.js';
import _ol_View_ from '../src/ol/View.js'; import _ol_View_ from '../src/ol/View.js';
import _ol_interaction_Draw_ from '../src/ol/interaction/Draw.js'; import Draw from '../src/ol/interaction/Draw.js';
import _ol_layer_Tile_ from '../src/ol/layer/Tile.js'; import _ol_layer_Tile_ from '../src/ol/layer/Tile.js';
import _ol_layer_Vector_ from '../src/ol/layer/Vector.js'; import _ol_layer_Vector_ from '../src/ol/layer/Vector.js';
import _ol_source_OSM_ from '../src/ol/source/OSM.js'; import _ol_source_OSM_ from '../src/ol/source/OSM.js';
@@ -31,7 +31,7 @@ var draw; // global so we can remove it later
function addInteraction() { function addInteraction() {
var value = typeSelect.value; var value = typeSelect.value;
if (value !== 'None') { if (value !== 'None') {
draw = new _ol_interaction_Draw_({ draw = new Draw({
source: source, source: source,
type: typeSelect.value, type: typeSelect.value,
freehand: true freehand: true

View File

@@ -1,7 +1,7 @@
import _ol_Map_ from '../src/ol/Map.js'; import _ol_Map_ from '../src/ol/Map.js';
import _ol_View_ from '../src/ol/View.js'; import _ol_View_ from '../src/ol/View.js';
import Polygon from '../src/ol/geom/Polygon.js'; import Polygon from '../src/ol/geom/Polygon.js';
import _ol_interaction_Draw_ from '../src/ol/interaction/Draw.js'; import Draw from '../src/ol/interaction/Draw.js';
import _ol_layer_Tile_ from '../src/ol/layer/Tile.js'; import _ol_layer_Tile_ from '../src/ol/layer/Tile.js';
import _ol_layer_Vector_ from '../src/ol/layer/Vector.js'; import _ol_layer_Vector_ from '../src/ol/layer/Vector.js';
import _ol_source_OSM_ from '../src/ol/source/OSM.js'; import _ol_source_OSM_ from '../src/ol/source/OSM.js';
@@ -35,10 +35,10 @@ function addInteraction() {
var geometryFunction; var geometryFunction;
if (value === 'Square') { if (value === 'Square') {
value = 'Circle'; value = 'Circle';
geometryFunction = _ol_interaction_Draw_.createRegularPolygon(4); geometryFunction = Draw.createRegularPolygon(4);
} else if (value === 'Box') { } else if (value === 'Box') {
value = 'Circle'; value = 'Circle';
geometryFunction = _ol_interaction_Draw_.createBox(); geometryFunction = Draw.createBox();
} else if (value === 'Star') { } else if (value === 'Star') {
value = 'Circle'; value = 'Circle';
geometryFunction = function(coordinates, geometry) { geometryFunction = function(coordinates, geometry) {
@@ -65,7 +65,7 @@ function addInteraction() {
return geometry; return geometry;
}; };
} }
draw = new _ol_interaction_Draw_({ draw = new Draw({
source: source, source: source,
type: value, type: value,
geometryFunction: geometryFunction geometryFunction: geometryFunction

View File

@@ -1,7 +1,7 @@
import _ol_Map_ from '../src/ol/Map.js'; import _ol_Map_ from '../src/ol/Map.js';
import _ol_View_ from '../src/ol/View.js'; import _ol_View_ from '../src/ol/View.js';
import Point from '../src/ol/geom/Point.js'; import Point from '../src/ol/geom/Point.js';
import _ol_interaction_Draw_ from '../src/ol/interaction/Draw.js'; import Draw from '../src/ol/interaction/Draw.js';
import _ol_layer_Tile_ from '../src/ol/layer/Tile.js'; import _ol_layer_Tile_ from '../src/ol/layer/Tile.js';
import _ol_layer_Vector_ from '../src/ol/layer/Vector.js'; import _ol_layer_Vector_ from '../src/ol/layer/Vector.js';
import _ol_source_OSM_ from '../src/ol/source/OSM.js'; import _ol_source_OSM_ from '../src/ol/source/OSM.js';
@@ -60,7 +60,7 @@ var map = new _ol_Map_({
}) })
}); });
map.addInteraction(new _ol_interaction_Draw_({ map.addInteraction(new Draw({
source: source, source: source,
type: 'LineString' type: 'LineString'
})); }));

View File

@@ -5,7 +5,7 @@ import _ol_Sphere_ from '../src/ol/Sphere.js';
import _ol_View_ from '../src/ol/View.js'; import _ol_View_ from '../src/ol/View.js';
import LineString from '../src/ol/geom/LineString.js'; import LineString from '../src/ol/geom/LineString.js';
import Polygon from '../src/ol/geom/Polygon.js'; import Polygon from '../src/ol/geom/Polygon.js';
import _ol_interaction_Draw_ from '../src/ol/interaction/Draw.js'; import Draw from '../src/ol/interaction/Draw.js';
import _ol_layer_Tile_ from '../src/ol/layer/Tile.js'; import _ol_layer_Tile_ from '../src/ol/layer/Tile.js';
import _ol_layer_Vector_ from '../src/ol/layer/Vector.js'; import _ol_layer_Vector_ from '../src/ol/layer/Vector.js';
import _ol_source_OSM_ from '../src/ol/source/OSM.js'; import _ol_source_OSM_ from '../src/ol/source/OSM.js';
@@ -177,7 +177,7 @@ var formatArea = function(polygon) {
function addInteraction() { function addInteraction() {
var type = (typeSelect.value == 'area' ? 'Polygon' : 'LineString'); var type = (typeSelect.value == 'area' ? 'Polygon' : 'LineString');
draw = new _ol_interaction_Draw_({ draw = new Draw({
source: source, source: source,
type: type, type: type,
style: new _ol_style_Style_({ style: new _ol_style_Style_({

View File

@@ -1,6 +1,6 @@
import _ol_Map_ from '../src/ol/Map.js'; import _ol_Map_ from '../src/ol/Map.js';
import _ol_View_ from '../src/ol/View.js'; import _ol_View_ from '../src/ol/View.js';
import _ol_interaction_Draw_ from '../src/ol/interaction/Draw.js'; import Draw from '../src/ol/interaction/Draw.js';
import _ol_interaction_Modify_ from '../src/ol/interaction/Modify.js'; import _ol_interaction_Modify_ from '../src/ol/interaction/Modify.js';
import _ol_interaction_Select_ from '../src/ol/interaction/Select.js'; import _ol_interaction_Select_ from '../src/ol/interaction/Select.js';
import _ol_interaction_Snap_ from '../src/ol/interaction/Snap.js'; import _ol_interaction_Snap_ from '../src/ol/interaction/Snap.js';
@@ -73,7 +73,7 @@ Modify.init();
var optionsForm = document.getElementById('options-form'); var optionsForm = document.getElementById('options-form');
var Draw = { var ExampleDraw = {
init: function() { init: function() {
map.addInteraction(this.Point); map.addInteraction(this.Point);
this.Point.setActive(false); this.Point.setActive(false);
@@ -84,19 +84,19 @@ var Draw = {
map.addInteraction(this.Circle); map.addInteraction(this.Circle);
this.Circle.setActive(false); this.Circle.setActive(false);
}, },
Point: new _ol_interaction_Draw_({ Point: new Draw({
source: vector.getSource(), source: vector.getSource(),
type: 'Point' type: 'Point'
}), }),
LineString: new _ol_interaction_Draw_({ LineString: new Draw({
source: vector.getSource(), source: vector.getSource(),
type: 'LineString' type: 'LineString'
}), }),
Polygon: new _ol_interaction_Draw_({ Polygon: new Draw({
source: vector.getSource(), source: vector.getSource(),
type: 'Polygon' type: 'Polygon'
}), }),
Circle: new _ol_interaction_Draw_({ Circle: new Draw({
source: vector.getSource(), source: vector.getSource(),
type: 'Circle' type: 'Circle'
}), }),
@@ -115,7 +115,7 @@ var Draw = {
} }
} }
}; };
Draw.init(); ExampleDraw.init();
/** /**

View File

@@ -7,7 +7,7 @@ import _ol_View_ from '../src/ol/View.js';
import Point from '../src/ol/geom/Point.js'; import Point from '../src/ol/geom/Point.js';
import LineString from '../src/ol/geom/LineString.js'; import LineString from '../src/ol/geom/LineString.js';
import Polygon from '../src/ol/geom/Polygon.js'; import Polygon from '../src/ol/geom/Polygon.js';
import _ol_interaction_Draw_ from '../src/ol/interaction/Draw.js'; import Draw from '../src/ol/interaction/Draw.js';
import _ol_interaction_Snap_ from '../src/ol/interaction/Snap.js'; import _ol_interaction_Snap_ from '../src/ol/interaction/Snap.js';
import _ol_layer_Tile_ from '../src/ol/layer/Tile.js'; import _ol_layer_Tile_ from '../src/ol/layer/Tile.js';
import _ol_layer_Vector_ from '../src/ol/layer/Vector.js'; import _ol_layer_Vector_ from '../src/ol/layer/Vector.js';
@@ -204,7 +204,7 @@ function onDrawend(e) {
} }
} }
var draw = new _ol_interaction_Draw_({ var draw = new Draw({
type: 'LineString' type: 'LineString'
}); });
draw.on('drawend', onDrawend); draw.on('drawend', onDrawend);

View File

@@ -2,7 +2,7 @@ import _ol_Map_ from '../src/ol/Map.js';
import _ol_View_ from '../src/ol/View.js'; import _ol_View_ from '../src/ol/View.js';
import _ol_format_EsriJSON_ from '../src/ol/format/EsriJSON.js'; import _ol_format_EsriJSON_ from '../src/ol/format/EsriJSON.js';
import _ol_interaction_ from '../src/ol/interaction.js'; import _ol_interaction_ from '../src/ol/interaction.js';
import _ol_interaction_Draw_ from '../src/ol/interaction/Draw.js'; import Draw from '../src/ol/interaction/Draw.js';
import _ol_interaction_Modify_ from '../src/ol/interaction/Modify.js'; import _ol_interaction_Modify_ from '../src/ol/interaction/Modify.js';
import _ol_interaction_Select_ from '../src/ol/interaction/Select.js'; import _ol_interaction_Select_ from '../src/ol/interaction/Select.js';
import _ol_layer_Tile_ from '../src/ol/layer/Tile.js'; import _ol_layer_Tile_ from '../src/ol/layer/Tile.js';
@@ -62,7 +62,7 @@ var raster = new _ol_layer_Tile_({
}) })
}); });
var draw = new _ol_interaction_Draw_({ var draw = new Draw({
source: vectorSource, source: vectorSource,
type: 'Polygon' type: 'Polygon'
}); });

View File

@@ -36,12 +36,12 @@ import _ol_style_Style_ from '../style/Style.js';
* @param {olx.interaction.DrawOptions} options Options. * @param {olx.interaction.DrawOptions} options Options.
* @api * @api
*/ */
var _ol_interaction_Draw_ = function(options) { var Draw = function(options) {
_ol_interaction_Pointer_.call(this, { _ol_interaction_Pointer_.call(this, {
handleDownEvent: _ol_interaction_Draw_.handleDownEvent_, handleDownEvent: Draw.handleDownEvent_,
handleEvent: _ol_interaction_Draw_.handleEvent, handleEvent: Draw.handleEvent,
handleUpEvent: _ol_interaction_Draw_.handleUpEvent_ handleUpEvent: Draw.handleUpEvent_
}); });
/** /**
@@ -95,7 +95,7 @@ var _ol_interaction_Draw_ = function(options) {
* @type {ol.interaction.Draw.Mode_} * @type {ol.interaction.Draw.Mode_}
* @private * @private
*/ */
this.mode_ = _ol_interaction_Draw_.getMode_(this.type_); this.mode_ = Draw.getMode_(this.type_);
/** /**
* Stop click, singleclick, and doubleclick events from firing during drawing. * Stop click, singleclick, and doubleclick events from firing during drawing.
@@ -114,7 +114,7 @@ var _ol_interaction_Draw_ = function(options) {
*/ */
this.minPoints_ = options.minPoints ? this.minPoints_ = options.minPoints ?
options.minPoints : options.minPoints :
(this.mode_ === _ol_interaction_Draw_.Mode_.POLYGON ? 3 : 2); (this.mode_ === Draw.Mode_.POLYGON ? 3 : 2);
/** /**
* The number of points that can be drawn before a polygon ring or line string * The number of points that can be drawn before a polygon ring or line string
@@ -151,11 +151,11 @@ var _ol_interaction_Draw_ = function(options) {
} else { } else {
var Constructor; var Constructor;
var mode = this.mode_; var mode = this.mode_;
if (mode === _ol_interaction_Draw_.Mode_.POINT) { if (mode === Draw.Mode_.POINT) {
Constructor = Point; Constructor = Point;
} else if (mode === _ol_interaction_Draw_.Mode_.LINE_STRING) { } else if (mode === Draw.Mode_.LINE_STRING) {
Constructor = LineString; Constructor = LineString;
} else if (mode === _ol_interaction_Draw_.Mode_.POLYGON) { } else if (mode === Draw.Mode_.POLYGON) {
Constructor = Polygon; Constructor = Polygon;
} }
/** /**
@@ -167,7 +167,7 @@ var _ol_interaction_Draw_ = function(options) {
geometryFunction = function(coordinates, opt_geometry) { geometryFunction = function(coordinates, opt_geometry) {
var geometry = opt_geometry; var geometry = opt_geometry;
if (geometry) { if (geometry) {
if (mode === _ol_interaction_Draw_.Mode_.POLYGON) { if (mode === Draw.Mode_.POLYGON) {
if (coordinates[0].length) { if (coordinates[0].length) {
// Add a closing coordinate to match the first // Add a closing coordinate to match the first
geometry.setCoordinates([coordinates[0].concat([coordinates[0][0]])]); geometry.setCoordinates([coordinates[0].concat([coordinates[0][0]])]);
@@ -255,7 +255,7 @@ var _ol_interaction_Draw_ = function(options) {
wrapX: options.wrapX ? options.wrapX : false wrapX: options.wrapX ? options.wrapX : false
}), }),
style: options.style ? options.style : style: options.style ? options.style :
_ol_interaction_Draw_.getDefaultStyleFunction() Draw.getDefaultStyleFunction()
}); });
/** /**
@@ -290,13 +290,13 @@ var _ol_interaction_Draw_ = function(options) {
}; };
inherits(_ol_interaction_Draw_, _ol_interaction_Pointer_); inherits(Draw, _ol_interaction_Pointer_);
/** /**
* @return {ol.StyleFunction} Styles. * @return {ol.StyleFunction} Styles.
*/ */
_ol_interaction_Draw_.getDefaultStyleFunction = function() { Draw.getDefaultStyleFunction = function() {
var styles = _ol_style_Style_.createDefaultEditing(); var styles = _ol_style_Style_.createDefaultEditing();
return function(feature, resolution) { return function(feature, resolution) {
return styles[feature.getGeometry().getType()]; return styles[feature.getGeometry().getType()];
@@ -307,7 +307,7 @@ _ol_interaction_Draw_.getDefaultStyleFunction = function() {
/** /**
* @inheritDoc * @inheritDoc
*/ */
_ol_interaction_Draw_.prototype.setMap = function(map) { Draw.prototype.setMap = function(map) {
_ol_interaction_Pointer_.prototype.setMap.call(this, map); _ol_interaction_Pointer_.prototype.setMap.call(this, map);
this.updateState_(); this.updateState_();
}; };
@@ -321,8 +321,8 @@ _ol_interaction_Draw_.prototype.setMap = function(map) {
* @this {ol.interaction.Draw} * @this {ol.interaction.Draw}
* @api * @api
*/ */
_ol_interaction_Draw_.handleEvent = function(event) { Draw.handleEvent = function(event) {
this.freehand_ = this.mode_ !== _ol_interaction_Draw_.Mode_.POINT && this.freehandCondition_(event); this.freehand_ = this.mode_ !== Draw.Mode_.POINT && this.freehandCondition_(event);
var pass = true; var pass = true;
if (this.freehand_ && if (this.freehand_ &&
event.type === MapBrowserEventType.POINTERDRAG && event.type === MapBrowserEventType.POINTERDRAG &&
@@ -347,7 +347,7 @@ _ol_interaction_Draw_.handleEvent = function(event) {
* @this {ol.interaction.Draw} * @this {ol.interaction.Draw}
* @private * @private
*/ */
_ol_interaction_Draw_.handleDownEvent_ = function(event) { Draw.handleDownEvent_ = function(event) {
this.shouldHandle_ = !this.freehand_; this.shouldHandle_ = !this.freehand_;
if (this.freehand_) { if (this.freehand_) {
@@ -371,17 +371,17 @@ _ol_interaction_Draw_.handleDownEvent_ = function(event) {
* @this {ol.interaction.Draw} * @this {ol.interaction.Draw}
* @private * @private
*/ */
_ol_interaction_Draw_.handleUpEvent_ = function(event) { Draw.handleUpEvent_ = function(event) {
var pass = true; var pass = true;
this.handlePointerMove_(event); this.handlePointerMove_(event);
var circleMode = this.mode_ === _ol_interaction_Draw_.Mode_.CIRCLE; var circleMode = this.mode_ === Draw.Mode_.CIRCLE;
if (this.shouldHandle_) { if (this.shouldHandle_) {
if (!this.finishCoordinate_) { if (!this.finishCoordinate_) {
this.startDrawing_(event); this.startDrawing_(event);
if (this.mode_ === _ol_interaction_Draw_.Mode_.POINT) { if (this.mode_ === Draw.Mode_.POINT) {
this.finishDrawing(); this.finishDrawing();
} }
} else if (this.freehand_ || circleMode) { } else if (this.freehand_ || circleMode) {
@@ -411,7 +411,7 @@ _ol_interaction_Draw_.handleUpEvent_ = function(event) {
* @return {boolean} Pass the event to other interactions. * @return {boolean} Pass the event to other interactions.
* @private * @private
*/ */
_ol_interaction_Draw_.prototype.handlePointerMove_ = function(event) { Draw.prototype.handlePointerMove_ = function(event) {
if (this.downPx_ && if (this.downPx_ &&
((!this.freehand_ && this.shouldHandle_) || ((!this.freehand_ && this.shouldHandle_) ||
(this.freehand_ && !this.shouldHandle_))) { (this.freehand_ && !this.shouldHandle_))) {
@@ -440,14 +440,14 @@ _ol_interaction_Draw_.prototype.handlePointerMove_ = function(event) {
* @return {boolean} The event is within the snapping tolerance of the start. * @return {boolean} The event is within the snapping tolerance of the start.
* @private * @private
*/ */
_ol_interaction_Draw_.prototype.atFinish_ = function(event) { Draw.prototype.atFinish_ = function(event) {
var at = false; var at = false;
if (this.sketchFeature_) { if (this.sketchFeature_) {
var potentiallyDone = false; var potentiallyDone = false;
var potentiallyFinishCoordinates = [this.finishCoordinate_]; var potentiallyFinishCoordinates = [this.finishCoordinate_];
if (this.mode_ === _ol_interaction_Draw_.Mode_.LINE_STRING) { if (this.mode_ === Draw.Mode_.LINE_STRING) {
potentiallyDone = this.sketchCoords_.length > this.minPoints_; potentiallyDone = this.sketchCoords_.length > this.minPoints_;
} else if (this.mode_ === _ol_interaction_Draw_.Mode_.POLYGON) { } else if (this.mode_ === Draw.Mode_.POLYGON) {
potentiallyDone = this.sketchCoords_[0].length > potentiallyDone = this.sketchCoords_[0].length >
this.minPoints_; this.minPoints_;
potentiallyFinishCoordinates = [this.sketchCoords_[0][0], potentiallyFinishCoordinates = [this.sketchCoords_[0][0],
@@ -478,7 +478,7 @@ _ol_interaction_Draw_.prototype.atFinish_ = function(event) {
* @param {ol.MapBrowserEvent} event Event. * @param {ol.MapBrowserEvent} event Event.
* @private * @private
*/ */
_ol_interaction_Draw_.prototype.createOrUpdateSketchPoint_ = function(event) { Draw.prototype.createOrUpdateSketchPoint_ = function(event) {
var coordinates = event.coordinate.slice(); var coordinates = event.coordinate.slice();
if (!this.sketchPoint_) { if (!this.sketchPoint_) {
this.sketchPoint_ = new _ol_Feature_(new Point(coordinates)); this.sketchPoint_ = new _ol_Feature_(new Point(coordinates));
@@ -495,17 +495,17 @@ _ol_interaction_Draw_.prototype.createOrUpdateSketchPoint_ = function(event) {
* @param {ol.MapBrowserEvent} event Event. * @param {ol.MapBrowserEvent} event Event.
* @private * @private
*/ */
_ol_interaction_Draw_.prototype.startDrawing_ = function(event) { Draw.prototype.startDrawing_ = function(event) {
var start = event.coordinate; var start = event.coordinate;
this.finishCoordinate_ = start; this.finishCoordinate_ = start;
if (this.mode_ === _ol_interaction_Draw_.Mode_.POINT) { if (this.mode_ === Draw.Mode_.POINT) {
this.sketchCoords_ = start.slice(); this.sketchCoords_ = start.slice();
} else if (this.mode_ === _ol_interaction_Draw_.Mode_.POLYGON) { } else if (this.mode_ === Draw.Mode_.POLYGON) {
this.sketchCoords_ = [[start.slice(), start.slice()]]; this.sketchCoords_ = [[start.slice(), start.slice()]];
this.sketchLineCoords_ = this.sketchCoords_[0]; this.sketchLineCoords_ = this.sketchCoords_[0];
} else { } else {
this.sketchCoords_ = [start.slice(), start.slice()]; this.sketchCoords_ = [start.slice(), start.slice()];
if (this.mode_ === _ol_interaction_Draw_.Mode_.CIRCLE) { if (this.mode_ === Draw.Mode_.CIRCLE) {
this.sketchLineCoords_ = this.sketchCoords_; this.sketchLineCoords_ = this.sketchCoords_;
} }
} }
@@ -520,7 +520,7 @@ _ol_interaction_Draw_.prototype.startDrawing_ = function(event) {
} }
this.sketchFeature_.setGeometry(geometry); this.sketchFeature_.setGeometry(geometry);
this.updateSketchFeatures_(); this.updateSketchFeatures_();
this.dispatchEvent(new _ol_interaction_Draw_.Event( this.dispatchEvent(new Draw.Event(
_ol_interaction_DrawEventType_.DRAWSTART, this.sketchFeature_)); _ol_interaction_DrawEventType_.DRAWSTART, this.sketchFeature_));
}; };
@@ -530,13 +530,13 @@ _ol_interaction_Draw_.prototype.startDrawing_ = function(event) {
* @param {ol.MapBrowserEvent} event Event. * @param {ol.MapBrowserEvent} event Event.
* @private * @private
*/ */
_ol_interaction_Draw_.prototype.modifyDrawing_ = function(event) { Draw.prototype.modifyDrawing_ = function(event) {
var coordinate = event.coordinate; var coordinate = event.coordinate;
var geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry()); var geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry());
var coordinates, last; var coordinates, last;
if (this.mode_ === _ol_interaction_Draw_.Mode_.POINT) { if (this.mode_ === Draw.Mode_.POINT) {
last = this.sketchCoords_; last = this.sketchCoords_;
} else if (this.mode_ === _ol_interaction_Draw_.Mode_.POLYGON) { } else if (this.mode_ === Draw.Mode_.POLYGON) {
coordinates = this.sketchCoords_[0]; coordinates = this.sketchCoords_[0];
last = coordinates[coordinates.length - 1]; last = coordinates[coordinates.length - 1];
if (this.atFinish_(event)) { if (this.atFinish_(event)) {
@@ -556,7 +556,7 @@ _ol_interaction_Draw_.prototype.modifyDrawing_ = function(event) {
} }
var sketchLineGeom; var sketchLineGeom;
if (geometry instanceof Polygon && if (geometry instanceof Polygon &&
this.mode_ !== _ol_interaction_Draw_.Mode_.POLYGON) { this.mode_ !== Draw.Mode_.POLYGON) {
if (!this.sketchLine_) { if (!this.sketchLine_) {
this.sketchLine_ = new _ol_Feature_(new LineString(null)); this.sketchLine_ = new _ol_Feature_(new LineString(null));
} }
@@ -577,12 +577,12 @@ _ol_interaction_Draw_.prototype.modifyDrawing_ = function(event) {
* @param {ol.MapBrowserEvent} event Event. * @param {ol.MapBrowserEvent} event Event.
* @private * @private
*/ */
_ol_interaction_Draw_.prototype.addToDrawing_ = function(event) { Draw.prototype.addToDrawing_ = function(event) {
var coordinate = event.coordinate; var coordinate = event.coordinate;
var geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry()); var geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry());
var done; var done;
var coordinates; var coordinates;
if (this.mode_ === _ol_interaction_Draw_.Mode_.LINE_STRING) { if (this.mode_ === Draw.Mode_.LINE_STRING) {
this.finishCoordinate_ = coordinate.slice(); this.finishCoordinate_ = coordinate.slice();
coordinates = this.sketchCoords_; coordinates = this.sketchCoords_;
if (coordinates.length >= this.maxPoints_) { if (coordinates.length >= this.maxPoints_) {
@@ -594,7 +594,7 @@ _ol_interaction_Draw_.prototype.addToDrawing_ = function(event) {
} }
coordinates.push(coordinate.slice()); coordinates.push(coordinate.slice());
this.geometryFunction_(coordinates, geometry); this.geometryFunction_(coordinates, geometry);
} else if (this.mode_ === _ol_interaction_Draw_.Mode_.POLYGON) { } else if (this.mode_ === Draw.Mode_.POLYGON) {
coordinates = this.sketchCoords_[0]; coordinates = this.sketchCoords_[0];
if (coordinates.length >= this.maxPoints_) { if (coordinates.length >= this.maxPoints_) {
if (this.freehand_) { if (this.freehand_) {
@@ -620,20 +620,20 @@ _ol_interaction_Draw_.prototype.addToDrawing_ = function(event) {
* Remove last point of the feature currently being drawn. * Remove last point of the feature currently being drawn.
* @api * @api
*/ */
_ol_interaction_Draw_.prototype.removeLastPoint = function() { Draw.prototype.removeLastPoint = function() {
if (!this.sketchFeature_) { if (!this.sketchFeature_) {
return; return;
} }
var geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry()); var geometry = /** @type {ol.geom.SimpleGeometry} */ (this.sketchFeature_.getGeometry());
var coordinates, sketchLineGeom; var coordinates, sketchLineGeom;
if (this.mode_ === _ol_interaction_Draw_.Mode_.LINE_STRING) { if (this.mode_ === Draw.Mode_.LINE_STRING) {
coordinates = this.sketchCoords_; coordinates = this.sketchCoords_;
coordinates.splice(-2, 1); coordinates.splice(-2, 1);
this.geometryFunction_(coordinates, geometry); this.geometryFunction_(coordinates, geometry);
if (coordinates.length >= 2) { if (coordinates.length >= 2) {
this.finishCoordinate_ = coordinates[coordinates.length - 2].slice(); this.finishCoordinate_ = coordinates[coordinates.length - 2].slice();
} }
} else if (this.mode_ === _ol_interaction_Draw_.Mode_.POLYGON) { } else if (this.mode_ === Draw.Mode_.POLYGON) {
coordinates = this.sketchCoords_[0]; coordinates = this.sketchCoords_[0];
coordinates.splice(-2, 1); coordinates.splice(-2, 1);
sketchLineGeom = /** @type {ol.geom.LineString} */ (this.sketchLine_.getGeometry()); sketchLineGeom = /** @type {ol.geom.LineString} */ (this.sketchLine_.getGeometry());
@@ -655,15 +655,15 @@ _ol_interaction_Draw_.prototype.removeLastPoint = function() {
* inserting the feature. * inserting the feature.
* @api * @api
*/ */
_ol_interaction_Draw_.prototype.finishDrawing = function() { Draw.prototype.finishDrawing = function() {
var sketchFeature = this.abortDrawing_(); var sketchFeature = this.abortDrawing_();
var coordinates = this.sketchCoords_; var coordinates = this.sketchCoords_;
var geometry = /** @type {ol.geom.SimpleGeometry} */ (sketchFeature.getGeometry()); var geometry = /** @type {ol.geom.SimpleGeometry} */ (sketchFeature.getGeometry());
if (this.mode_ === _ol_interaction_Draw_.Mode_.LINE_STRING) { if (this.mode_ === Draw.Mode_.LINE_STRING) {
// remove the redundant last point // remove the redundant last point
coordinates.pop(); coordinates.pop();
this.geometryFunction_(coordinates, geometry); this.geometryFunction_(coordinates, geometry);
} else if (this.mode_ === _ol_interaction_Draw_.Mode_.POLYGON) { } else if (this.mode_ === Draw.Mode_.POLYGON) {
// remove the redundant last point in ring // remove the redundant last point in ring
coordinates[0].pop(); coordinates[0].pop();
this.geometryFunction_(coordinates, geometry); this.geometryFunction_(coordinates, geometry);
@@ -680,7 +680,7 @@ _ol_interaction_Draw_.prototype.finishDrawing = function() {
} }
// First dispatch event to allow full set up of feature // First dispatch event to allow full set up of feature
this.dispatchEvent(new _ol_interaction_Draw_.Event( this.dispatchEvent(new Draw.Event(
_ol_interaction_DrawEventType_.DRAWEND, sketchFeature)); _ol_interaction_DrawEventType_.DRAWEND, sketchFeature));
// Then insert feature // Then insert feature
@@ -698,7 +698,7 @@ _ol_interaction_Draw_.prototype.finishDrawing = function() {
* @return {ol.Feature} The sketch feature (or null if none). * @return {ol.Feature} The sketch feature (or null if none).
* @private * @private
*/ */
_ol_interaction_Draw_.prototype.abortDrawing_ = function() { Draw.prototype.abortDrawing_ = function() {
this.finishCoordinate_ = null; this.finishCoordinate_ = null;
var sketchFeature = this.sketchFeature_; var sketchFeature = this.sketchFeature_;
if (sketchFeature) { if (sketchFeature) {
@@ -718,7 +718,7 @@ _ol_interaction_Draw_.prototype.abortDrawing_ = function() {
* @param {!ol.Feature} feature Feature to be extended. * @param {!ol.Feature} feature Feature to be extended.
* @api * @api
*/ */
_ol_interaction_Draw_.prototype.extend = function(feature) { Draw.prototype.extend = function(feature) {
var geometry = feature.getGeometry(); var geometry = feature.getGeometry();
var lineString = /** @type {ol.geom.LineString} */ (geometry); var lineString = /** @type {ol.geom.LineString} */ (geometry);
this.sketchFeature_ = feature; this.sketchFeature_ = feature;
@@ -727,7 +727,7 @@ _ol_interaction_Draw_.prototype.extend = function(feature) {
this.finishCoordinate_ = last.slice(); this.finishCoordinate_ = last.slice();
this.sketchCoords_.push(last.slice()); this.sketchCoords_.push(last.slice());
this.updateSketchFeatures_(); this.updateSketchFeatures_();
this.dispatchEvent(new _ol_interaction_Draw_.Event( this.dispatchEvent(new Draw.Event(
_ol_interaction_DrawEventType_.DRAWSTART, this.sketchFeature_)); _ol_interaction_DrawEventType_.DRAWSTART, this.sketchFeature_));
}; };
@@ -735,14 +735,14 @@ _ol_interaction_Draw_.prototype.extend = function(feature) {
/** /**
* @inheritDoc * @inheritDoc
*/ */
_ol_interaction_Draw_.prototype.shouldStopEvent = FALSE; Draw.prototype.shouldStopEvent = FALSE;
/** /**
* Redraw the sketch features. * Redraw the sketch features.
* @private * @private
*/ */
_ol_interaction_Draw_.prototype.updateSketchFeatures_ = function() { Draw.prototype.updateSketchFeatures_ = function() {
var sketchFeatures = []; var sketchFeatures = [];
if (this.sketchFeature_) { if (this.sketchFeature_) {
sketchFeatures.push(this.sketchFeature_); sketchFeatures.push(this.sketchFeature_);
@@ -762,7 +762,7 @@ _ol_interaction_Draw_.prototype.updateSketchFeatures_ = function() {
/** /**
* @private * @private
*/ */
_ol_interaction_Draw_.prototype.updateState_ = function() { Draw.prototype.updateState_ = function() {
var map = this.getMap(); var map = this.getMap();
var active = this.getActive(); var active = this.getActive();
if (!map || !active) { if (!map || !active) {
@@ -785,7 +785,7 @@ _ol_interaction_Draw_.prototype.updateState_ = function() {
* polygon. * polygon.
* @api * @api
*/ */
_ol_interaction_Draw_.createRegularPolygon = function(opt_sides, opt_angle) { Draw.createRegularPolygon = function(opt_sides, opt_angle) {
return ( return (
/** /**
* @param {ol.Coordinate|Array.<ol.Coordinate>|Array.<Array.<ol.Coordinate>>} coordinates * @param {ol.Coordinate|Array.<ol.Coordinate>|Array.<Array.<ol.Coordinate>>} coordinates
@@ -815,7 +815,7 @@ _ol_interaction_Draw_.createRegularPolygon = function(opt_sides, opt_angle) {
* @return {ol.DrawGeometryFunctionType} Function that draws a box-shaped polygon. * @return {ol.DrawGeometryFunctionType} Function that draws a box-shaped polygon.
* @api * @api
*/ */
_ol_interaction_Draw_.createBox = function() { Draw.createBox = function() {
return ( return (
/** /**
* @param {Array.<ol.Coordinate>} coordinates * @param {Array.<ol.Coordinate>} coordinates
@@ -845,19 +845,19 @@ _ol_interaction_Draw_.createBox = function() {
* @return {ol.interaction.Draw.Mode_} Drawing mode. * @return {ol.interaction.Draw.Mode_} Drawing mode.
* @private * @private
*/ */
_ol_interaction_Draw_.getMode_ = function(type) { Draw.getMode_ = function(type) {
var mode; var mode;
if (type === GeometryType.POINT || if (type === GeometryType.POINT ||
type === GeometryType.MULTI_POINT) { type === GeometryType.MULTI_POINT) {
mode = _ol_interaction_Draw_.Mode_.POINT; mode = Draw.Mode_.POINT;
} else if (type === GeometryType.LINE_STRING || } else if (type === GeometryType.LINE_STRING ||
type === GeometryType.MULTI_LINE_STRING) { type === GeometryType.MULTI_LINE_STRING) {
mode = _ol_interaction_Draw_.Mode_.LINE_STRING; mode = Draw.Mode_.LINE_STRING;
} else if (type === GeometryType.POLYGON || } else if (type === GeometryType.POLYGON ||
type === GeometryType.MULTI_POLYGON) { type === GeometryType.MULTI_POLYGON) {
mode = _ol_interaction_Draw_.Mode_.POLYGON; mode = Draw.Mode_.POLYGON;
} else if (type === GeometryType.CIRCLE) { } else if (type === GeometryType.CIRCLE) {
mode = _ol_interaction_Draw_.Mode_.CIRCLE; mode = Draw.Mode_.CIRCLE;
} }
return /** @type {!ol.interaction.Draw.Mode_} */ (mode); return /** @type {!ol.interaction.Draw.Mode_} */ (mode);
}; };
@@ -869,7 +869,7 @@ _ol_interaction_Draw_.getMode_ = function(type) {
* @enum {string} * @enum {string}
* @private * @private
*/ */
_ol_interaction_Draw_.Mode_ = { Draw.Mode_ = {
POINT: 'Point', POINT: 'Point',
LINE_STRING: 'LineString', LINE_STRING: 'LineString',
POLYGON: 'Polygon', POLYGON: 'Polygon',
@@ -887,7 +887,7 @@ _ol_interaction_Draw_.Mode_ = {
* @param {ol.interaction.DrawEventType} type Type. * @param {ol.interaction.DrawEventType} type Type.
* @param {ol.Feature} feature The feature drawn. * @param {ol.Feature} feature The feature drawn.
*/ */
_ol_interaction_Draw_.Event = function(type, feature) { Draw.Event = function(type, feature) {
Event.call(this, type); Event.call(this, type);
@@ -899,5 +899,6 @@ _ol_interaction_Draw_.Event = function(type, feature) {
this.feature = feature; this.feature = feature;
}; };
inherits(_ol_interaction_Draw_.Event, Event); inherits(Draw.Event, Event);
export default _ol_interaction_Draw_;
export default Draw;

View File

@@ -12,7 +12,7 @@ import MultiPoint from '../../../../src/ol/geom/MultiPoint.js';
import MultiPolygon from '../../../../src/ol/geom/MultiPolygon.js'; import MultiPolygon from '../../../../src/ol/geom/MultiPolygon.js';
import Point from '../../../../src/ol/geom/Point.js'; import Point from '../../../../src/ol/geom/Point.js';
import Polygon from '../../../../src/ol/geom/Polygon.js'; import Polygon from '../../../../src/ol/geom/Polygon.js';
import _ol_interaction_Draw_ from '../../../../src/ol/interaction/Draw.js'; import Draw from '../../../../src/ol/interaction/Draw.js';
import Interaction from '../../../../src/ol/interaction/Interaction.js'; import Interaction from '../../../../src/ol/interaction/Interaction.js';
import _ol_layer_Vector_ from '../../../../src/ol/layer/Vector.js'; import _ol_layer_Vector_ from '../../../../src/ol/layer/Vector.js';
import _ol_pointer_PointerEvent_ from '../../../../src/ol/pointer/PointerEvent.js'; import _ol_pointer_PointerEvent_ from '../../../../src/ol/pointer/PointerEvent.js';
@@ -79,16 +79,16 @@ describe('ol.interaction.Draw', function() {
describe('constructor', function() { describe('constructor', function() {
it('creates a new interaction', function() { it('creates a new interaction', function() {
var draw = new _ol_interaction_Draw_({ var draw = new Draw({
source: source, source: source,
type: 'Point' type: 'Point'
}); });
expect(draw).to.be.a(_ol_interaction_Draw_); expect(draw).to.be.a(Draw);
expect(draw).to.be.a(Interaction); expect(draw).to.be.a(Interaction);
}); });
it('accepts a freehand option', function() { it('accepts a freehand option', function() {
var draw = new _ol_interaction_Draw_({ var draw = new Draw({
source: source, source: source,
type: 'LineString', type: 'LineString',
freehand: true freehand: true
@@ -108,7 +108,7 @@ describe('ol.interaction.Draw', function() {
describe('specifying a geometryName', function() { describe('specifying a geometryName', function() {
beforeEach(function() { beforeEach(function() {
var draw = new _ol_interaction_Draw_({ var draw = new Draw({
source: source, source: source,
geometryName: 'the_geom', geometryName: 'the_geom',
type: 'Point' type: 'Point'
@@ -129,7 +129,7 @@ describe('ol.interaction.Draw', function() {
describe('specifying a clickTolerance', function() { describe('specifying a clickTolerance', function() {
beforeEach(function() { beforeEach(function() {
var draw = new _ol_interaction_Draw_({ var draw = new Draw({
source: source, source: source,
type: 'Point', type: 'Point',
clickTolerance: 6 clickTolerance: 6
@@ -158,7 +158,7 @@ describe('ol.interaction.Draw', function() {
var draw; var draw;
beforeEach(function() { beforeEach(function() {
draw = new _ol_interaction_Draw_({ draw = new Draw({
source: source, source: source,
type: 'Point' type: 'Point'
}); });
@@ -236,7 +236,7 @@ describe('ol.interaction.Draw', function() {
describe('drawing multipoints', function() { describe('drawing multipoints', function() {
beforeEach(function() { beforeEach(function() {
map.addInteraction(new _ol_interaction_Draw_({ map.addInteraction(new Draw({
source: source, source: source,
type: 'MultiPoint' type: 'MultiPoint'
})); }));
@@ -259,7 +259,7 @@ describe('ol.interaction.Draw', function() {
var draw; var draw;
beforeEach(function() { beforeEach(function() {
draw = new _ol_interaction_Draw_({ draw = new Draw({
source: source, source: source,
type: 'LineString' type: 'LineString'
}); });
@@ -427,7 +427,7 @@ describe('ol.interaction.Draw', function() {
describe('drawing with a finishCondition', function() { describe('drawing with a finishCondition', function() {
beforeEach(function() { beforeEach(function() {
var draw = new _ol_interaction_Draw_({ var draw = new Draw({
source: source, source: source,
type: 'LineString', type: 'LineString',
finishCondition: function(event) { finishCondition: function(event) {
@@ -477,7 +477,7 @@ describe('ol.interaction.Draw', function() {
describe('drawing multi-linestrings', function() { describe('drawing multi-linestrings', function() {
beforeEach(function() { beforeEach(function() {
map.addInteraction(new _ol_interaction_Draw_({ map.addInteraction(new Draw({
source: source, source: source,
type: 'MultiLineString' type: 'MultiLineString'
})); }));
@@ -511,7 +511,7 @@ describe('ol.interaction.Draw', function() {
var draw; var draw;
beforeEach(function() { beforeEach(function() {
draw = new _ol_interaction_Draw_({ draw = new Draw({
source: source, source: source,
type: 'Polygon' type: 'Polygon'
}); });
@@ -697,7 +697,7 @@ describe('ol.interaction.Draw', function() {
describe('drawing multi-polygons', function() { describe('drawing multi-polygons', function() {
beforeEach(function() { beforeEach(function() {
map.addInteraction(new _ol_interaction_Draw_({ map.addInteraction(new Draw({
source: source, source: source,
type: 'MultiPolygon' type: 'MultiPolygon'
})); }));
@@ -774,7 +774,7 @@ describe('ol.interaction.Draw', function() {
var draw; var draw;
beforeEach(function() { beforeEach(function() {
draw = new _ol_interaction_Draw_({ draw = new Draw({
source: source, source: source,
type: 'Circle' type: 'Circle'
}); });
@@ -846,7 +846,7 @@ describe('ol.interaction.Draw', function() {
var interaction; var interaction;
beforeEach(function() { beforeEach(function() {
interaction = new _ol_interaction_Draw_({ interaction = new Draw({
type: 'LineString' type: 'LineString'
}); });
@@ -915,7 +915,7 @@ describe('ol.interaction.Draw', function() {
var interaction; var interaction;
beforeEach(function() { beforeEach(function() {
interaction = new _ol_interaction_Draw_({ interaction = new Draw({
type: 'LineString' type: 'LineString'
}); });
expect(interaction.getActive()).to.be(true); expect(interaction.getActive()).to.be(true);
@@ -968,11 +968,11 @@ describe('ol.interaction.Draw', function() {
describe('ol.interaction.Draw.createRegularPolygon', function() { describe('ol.interaction.Draw.createRegularPolygon', function() {
it('creates a regular polygon in Circle mode', function() { it('creates a regular polygon in Circle mode', function() {
var draw = new _ol_interaction_Draw_({ var draw = new Draw({
source: source, source: source,
type: 'Circle', type: 'Circle',
geometryFunction: geometryFunction:
_ol_interaction_Draw_.createRegularPolygon(4, Math.PI / 4) Draw.createRegularPolygon(4, Math.PI / 4)
}); });
map.addInteraction(draw); map.addInteraction(draw);
@@ -998,10 +998,10 @@ describe('ol.interaction.Draw', function() {
describe('ol.interaction.Draw.createBox', function() { describe('ol.interaction.Draw.createBox', function() {
it('creates a box-shaped polygon in Circle mode', function() { it('creates a box-shaped polygon in Circle mode', function() {
var draw = new _ol_interaction_Draw_({ var draw = new Draw({
source: source, source: source,
type: 'Circle', type: 'Circle',
geometryFunction: _ol_interaction_Draw_.createBox() geometryFunction: Draw.createBox()
}); });
map.addInteraction(draw); map.addInteraction(draw);
@@ -1030,7 +1030,7 @@ describe('ol.interaction.Draw', function() {
var feature; var feature;
beforeEach(function() { beforeEach(function() {
draw = new _ol_interaction_Draw_({ draw = new Draw({
source: source, source: source,
type: 'LineString' type: 'LineString'
}); });