Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix geometry validity test in DrawAzimut #5064

Merged
merged 2 commits into from
Aug 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 9 additions & 18 deletions src/interaction/DrawAzimut.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import VectorSource from 'ol/source/Vector.js';

/**
* @typedef {Object} Options
* @property {VectorSource<import("ol/geom/Geometry.js").default>} source
* @property {!VectorSource<import("ol/geom/Geometry.js").default>} source
* @property {import('ol/style/Style.js').StyleLike} style
*/

Expand Down Expand Up @@ -43,28 +43,28 @@ class DrawAzimut extends olInteractionPointer {

/**
* Target source for drawn features.
* @type {import("ol/source/Vector.js").default<import("ol/geom/Geometry.js").default>}
* @type {!import("ol/source/Vector.js").default<import("ol/geom/Geometry.js").default>}
* @private
*/
this.source_ = options.source;

/**
* Tglls whether the drawing has started or not.
* Whether the drawing has started or not.
* @type {boolean}
* @private
*/
this.started_ = false;

/**
* Sketch feature.
* @type {Feature<import("ol/geom/Geometry.js").default>}
* @type {Feature<import("ol/geom/GeometryCollection.js").default>}
* @private
*/
this.sketchFeature_ = new Feature();

/**
* Sketch point.
* @type {Feature<import("ol/geom/Geometry.js").default>}
* @type {Feature<import("ol/geom/Point.js").default>}
* @private
*/
this.sketchPoint_ = new Feature();
Expand Down Expand Up @@ -117,14 +117,12 @@ class DrawAzimut extends olInteractionPointer {
*/
createOrUpdateSketchPoint_(event) {
const coordinates = event.coordinate.slice();
if (this.sketchPoint_.getGeometry() === null) {
const sketchPointGeom = this.sketchPoint_.getGeometry();
if (!sketchPointGeom) {
this.sketchPoint_ = new Feature(new olGeomPoint(coordinates));
this.updateSketchFeatures_();
} else {
const sketchPointGeom = this.sketchPoint_.getGeometry();
if (sketchPointGeom instanceof olGeomPoint) {
sketchPointGeom.setCoordinates(coordinates);
}
sketchPointGeom.setCoordinates(coordinates);
}
}

Expand All @@ -136,9 +134,6 @@ class DrawAzimut extends olInteractionPointer {
const sketchFeatures = [];
sketchFeatures.push(this.sketchFeature_);
sketchFeatures.push(this.sketchPoint_);
/**
* @type {VectorSource<import("ol/geom/Geometry.js").default>}
*/
const source = this.sketchLayer_.getSource();
source.clear(true);
source.addFeatures(sketchFeatures);
Expand All @@ -158,7 +153,6 @@ class DrawAzimut extends olInteractionPointer {
this.sketchFeature_ = new Feature();
this.sketchFeature_.setGeometry(geometry);
this.updateSketchFeatures_();
/** @type {import('ngeo/interaction/common.js').DrawEvent} */
const evt = new ngeoCustomEvent('drawstart', {feature: this.sketchFeature_});
this.dispatchEvent(evt);
}
Expand Down Expand Up @@ -233,11 +227,8 @@ class DrawAzimut extends olInteractionPointer {
finishDrawing_() {
const sketchFeature = this.abortDrawing_();

if (this.source_ !== null) {
this.source_.addFeature(sketchFeature);
}
this.source_.addFeature(sketchFeature);

/** @type {import('ngeo/interaction/common.js').DrawEvent} */
const event = new ngeoCustomEvent('drawend', {feature: this.sketchFeature_});
this.dispatchEvent(event);
}
Expand Down