Skip to content

Commit

Permalink
Measure fix (#970)
Browse files Browse the repository at this point in the history
* fix(measure): abort drawing cause measure label stay on map.

* wip

Co-authored-by: Pierre-Étienne Lord <[email protected]>
  • Loading branch information
pelord and Pierre-Étienne Lord authored Feb 8, 2022
1 parent 000de63 commit 5212624
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/geo/src/lib/geometry/shared/controls/draw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export class DrawControl {
*/
public select$: Subject<any> = new Subject();

/**
* Draw abort observable (abort drawn features)
*/
public abort$: Subject<any> = new Subject();

/**
* Freehand mode observable (defaults to false)
*/
Expand All @@ -72,6 +77,7 @@ export class DrawControl {
private olModifyInteraction: OlModify;
private onDrawStartKey: EventsKey;
private onDrawEndKey: EventsKey;
private onDrawAbortKey: EventsKey;
private onDrawKey: EventsKey;

private mousePosition: [number, number];
Expand Down Expand Up @@ -209,6 +215,7 @@ export class DrawControl {

this.onDrawStartKey = olDrawInteraction.on('drawstart', (event: OlDrawEvent) => this.onDrawStart(event));
this.onDrawEndKey = olDrawInteraction.on('drawend', (event: OlDrawEvent) => this.onDrawEnd(event));
this.onDrawAbortKey = olDrawInteraction.on('drawabort', (event: OlDrawEvent) => this.abort$.next(event.feature.getGeometry()));

if (activateModifyAndSelect) {
// Create a Modify interaction, add it to map and create a listener
Expand Down Expand Up @@ -238,7 +245,7 @@ export class DrawControl {
*/
private removeOlInteractions() {
this.unsubscribeKeyDown();
unByKey([this.onDrawStartKey, this.onDrawEndKey, this.onDrawKey]);
unByKey([this.onDrawStartKey, this.onDrawEndKey, this.onDrawKey, this.onDrawAbortKey]);

if (this.olMap) {
this.olMap.removeInteraction(this.olDrawInteraction);
Expand Down
6 changes: 5 additions & 1 deletion packages/geo/src/lib/measure/measurer/measurer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,11 @@ export class MeasurerComponent implements OnInit, OnDestroy {
.subscribe((olGeometry: OlLineString | OlPolygon) => this.onDrawEnd(olGeometry));
this.drawChanges$$ = drawControl.changes$
.subscribe((olGeometry: OlLineString | OlPolygon) => this.onDrawChanges(olGeometry));

this.drawChanges$$ = drawControl.abort$
.subscribe((olGeometry: OlLineString | OlPolygon) => {
this.clearTooltipsOfOlGeometry(olGeometry);
this.clearMeasures();
});
drawControl.setOlMap(this.map.ol, false);
}

Expand Down

0 comments on commit 5212624

Please sign in to comment.