Skip to content

Commit

Permalink
Fix missing DistanceMeasurement "measurementEnd" event for touch #1019
Browse files Browse the repository at this point in the history
  • Loading branch information
xeolabs committed Apr 6, 2023
1 parent 5c20d08 commit 9ca13d2
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class DistanceMeasurementsControl extends Component {
this._active = false;

// Mouse input uses a combo of events that requires us to track
// the current DistanceMeasurement under construction. This is not used for touch input.
// the current DistanceMeasurement under construction. This is not used for touch input, which
// just uses touch-move-release to make a measurement.
this._currentDistanceMeasurementByMouse = null;

this._currentDistanceMeasurementByMouseInittouchState = {
Expand Down Expand Up @@ -218,6 +219,7 @@ class DistanceMeasurementsControl extends Component {

this._onPickedNothing = cameraControl.on("pickedNothing", event => {
if (this._currentDistanceMeasurementByMouse) {
this.fire("measurementCancel", this._currentDistanceMeasurementByMouse);
this._currentDistanceMeasurementByMouse.destroy();
this._currentDistanceMeasurementByMouse = null;
}
Expand Down Expand Up @@ -260,7 +262,7 @@ class DistanceMeasurementsControl extends Component {
case SECOND_TOUCH_EXPECTED:
startDot.setVisible(false);
this._touchStartMarker.worldPos = pickResult.worldPos;
const measurement = plugin.createMeasurement({
const measurement = plugin.createMeasurement({
id: math.createUUID(),
origin: {
entity: mouseHoverEntity,
Expand All @@ -274,6 +276,7 @@ class DistanceMeasurementsControl extends Component {
});
measurement.clickable = true;
touchState = FIRST_TOUCH_EXPECTED;
this.fire("measurementEnd", measurement);
break;
}
} else {
Expand Down Expand Up @@ -315,7 +318,11 @@ class DistanceMeasurementsControl extends Component {
canvas.removeEventListener("touchstart", this._onCanvasTouchStart);
canvas.removeEventListener("touchend", this._onCanvasTouchEnd);

this._currentDistanceMeasurementByMouse = null;
if (this._currentDistanceMeasurementByMouse) {
this.fire("measurementCancel", this._currentDistanceMeasurementByMouse);
this._currentDistanceMeasurementByMouse.destroy();
this._currentDistanceMeasurementByMouse = null;
}

this._active = false;
}
Expand All @@ -332,6 +339,7 @@ class DistanceMeasurementsControl extends Component {
return;
}
if (this._currentDistanceMeasurementByMouse) {
this.fire("measurementCancel", this._currentDistanceMeasurementByMouse);
this._currentDistanceMeasurementByMouse.destroy();
this._currentDistanceMeasurementByMouse = null;
}
Expand Down

0 comments on commit 9ca13d2

Please sign in to comment.