Skip to content

Commit

Permalink
Implement requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aneust committed Feb 5, 2025
1 parent 12fd12b commit dc64908
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ import Styles from '../../stores/styles';
import { shiftKeyOnly } from '@biigle/ol/events/condition';
import snapInteraction from '../../snapInteraction.vue';
import { Point } from '@biigle/ol/geom';
import * as preventDoubleclick from '../../../prevent-doubleclick';
function computeDistance(point1, point2) {
let p1=point1.getCoordinates();
let p2=point2.getCoordinates();
return Math.sqrt(Math.pow(p2[0] - p1[0], 2) + Math.pow(p2[1] - p1[1], 2));
}
/**
* Mixin for the annotationCanvas component that contains logic for the draw interactions.
*
Expand All @@ -21,9 +16,6 @@ function computeDistance(point1, point2) {
let drawInteraction;
const POINT_CLICK_COOLDOWN = 400;
const POINT_CLICK_DISTANCE = 5;
// Custom OpenLayers freehandCondition that is true if a pen is used for input or
// if Shift is pressed otherwise.
let penOrShift = function (mapBrowserEvent) {
Expand Down Expand Up @@ -142,8 +134,8 @@ export default {
}
},
isPointDoubleClick(e) {
return new Date().getTime() - this.lastDrawnPointTime < POINT_CLICK_COOLDOWN
&& computeDistance(this.lastDrawnPoint,e.feature.getGeometry()) < POINT_CLICK_DISTANCE;
return new Date().getTime() - this.lastDrawnPointTime < preventDoubleclick.POINT_CLICK_COOLDOWN
&& preventDoubleclick.computeDistance(this.lastDrawnPoint,e.feature.getGeometry()) < preventDoubleclick.POINT_CLICK_DISTANCE;
},
},
watch: {
Expand Down
18 changes: 18 additions & 0 deletions resources/assets/js/prevent-doubleclick.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Compute the Euclidean distance between two points.
*
* @param Object point1 - The first point with getCoordinates() method.
* @param Object point2 - The second point with getCoordinates() method.
* @returns number - The computed distance between the two points.
*/

const POINT_CLICK_COOLDOWN = 400;
const POINT_CLICK_DISTANCE = 5;

let computeDistance = function (point1, point2) {
let p1 = point1.getCoordinates();
let p2 = point2.getCoordinates();
return Math.sqrt(Math.pow(p2[0] - p1[0], 2) + Math.pow(p2[1] - p1[1], 2));
};

export { computeDistance, POINT_CLICK_COOLDOWN, POINT_CLICK_DISTANCE };
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ import VectorSource from '@biigle/ol/source/Vector';
import snapInteraction from "./snapInteraction.vue";
import { isInvalidShape } from '../../../annotations/utils';
import { Point } from '@biigle/ol/geom';
import { computeDistance } from '../../utils';
import * as preventDoubleclick from '../../../prevent-doubleclick';
/**
* Mixin for the videoScreen component that contains logic for the draw interactions.
*
* @type {Object}
*/
const POINT_CLICK_COOLDOWN = 400;
const POINT_CLICK_DISTANCE = 5;
export default {
mixins: [snapInteraction],
data() {
Expand Down Expand Up @@ -213,19 +210,31 @@ export default {
let lastFrame = this.pendingAnnotation.frames[this.pendingAnnotation.frames.length - 1];
if (lastFrame === undefined || lastFrame < this.video.currentTime) {
if (this.singleAnnotation && this.isPointDoubleClick(e)) {
this.pendingAnnotationSource.once('addfeature', function (e) {
this.removeFeature(e.feature);
});
} else {
this.pendingAnnotation.frames.push(this.video.currentTime);
this.pendingAnnotation.points.push(this.getPointsFromGeometry(e.feature.getGeometry()));
this.pendingAnnotation.frames.push(this.video.currentTime);
this.pendingAnnotation.points.push(this.getPointsFromGeometry(e.feature.getGeometry()));
if (!this.video.ended && this.autoplayDraw > 0) {
this.play();
window.clearTimeout(this.autoplayDrawTimeout);
this.autoplayDrawTimeout = window.setTimeout(this.pause, this.autoplayDraw * 1000);
}
if (!this.video.ended && this.autoplayDraw > 0) {
this.play();
window.clearTimeout(this.autoplayDrawTimeout);
this.autoplayDrawTimeout = window.setTimeout(this.pause, this.autoplayDraw * 1000);
if (this.singleAnnotation) {
if (this.isDrawingPoint) {
if (this.isPointDoubleClick(e)) {
// The feature is added to the source only after this event
// is handled, so remove has to happen after the addfeature
// event.
this.pendingAnnotationSource.once('addfeature', function (e) {
this.removeFeature(e.feature);
});
this.resetPendingAnnotation(this.pendingAnnotation.shape);
return
}
this.lastDrawnPointTime = new Date().getTime();
this.lastDrawnPoint = e.feature.getGeometry();
}
this.pendingAnnotationSource.once('addfeature', this.finishDrawAnnotation);
}
} else {
// If the pending annotation (time) is invalid, remove it again.
Expand All @@ -238,21 +247,10 @@ export default {
this.$emit('pending-annotation', this.pendingAnnotation);
if (this.singleAnnotation) {
if (this.isDrawingPoint) {
if (this.isPointDoubleClick(e)) {
this.resetPendingAnnotation(this.pendingAnnotation.shape);
return;
}
this.lastDrawnPointTime = new Date().getTime();
this.lastDrawnPoint = e.feature.getGeometry();
}
this.pendingAnnotationSource.once('addfeature', this.finishDrawAnnotation);
}
},
isPointDoubleClick(e) {
return new Date().getTime() - this.lastDrawnPointTime < POINT_CLICK_COOLDOWN
&& computeDistance(this.lastDrawnPoint, e.feature.getGeometry()) < POINT_CLICK_DISTANCE;
return new Date().getTime() - this.lastDrawnPointTime < preventDoubleclick.POINT_CLICK_COOLDOWN
&& preventDoubleclick.computeDistance(this.lastDrawnPoint, e.feature.getGeometry()) < preventDoubleclick.POINT_CLICK_DISTANCE;
},
},
created() {
Expand Down
2 changes: 1 addition & 1 deletion resources/views/videos/show/sidebar-settings.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</div>

<div class="sidebar-tab__section">
<power-toggle :active="singleAnnotation" title-off="Enable Single-Frame Annotation" title-on="Disable Single-Frame Annotation" v-on:on="handleSingleAnnotation" v-on:off="handleDisableSingleAnnotation">Single-Frame Annotation</power-toggle>
<power-toggle :active="singleAnnotation" title-off="Enable always creating single-frame annotations" title-on="Disable always creating single-frame annotations" v-on:on="handleSingleAnnotation" v-on:off="handleDisableSingleAnnotation">Single-Frame Annotation</power-toggle>
</div>
</div>
</settings-tab>
Expand Down

0 comments on commit dc64908

Please sign in to comment.