From 1c3d2554e9d0f9d6fa396ee6ff2f61e4df1f8f51 Mon Sep 17 00:00:00 2001 From: Leane Schlundt Date: Fri, 22 Dec 2023 09:40:51 +0100 Subject: [PATCH 1/6] Check feature's availability before removing it Fix #660 --- .../videos/components/videoScreen/annotationPlayback.vue | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/resources/assets/js/videos/components/videoScreen/annotationPlayback.vue b/resources/assets/js/videos/components/videoScreen/annotationPlayback.vue index ac65ed8ea..4e8c06e8f 100644 --- a/resources/assets/js/videos/components/videoScreen/annotationPlayback.vue +++ b/resources/assets/js/videos/components/videoScreen/annotationPlayback.vue @@ -90,10 +90,13 @@ export default { toCreate.push(annotation.self); } } - + if (hasRenderedFeatures) { Object.values(oldRendered).forEach(function (feature) { - source.removeFeature(feature); + // source.hasFeature(feature) does not work here, because it is always true + if (source.getFeatures().includes(feature)) { + source.removeFeature(feature); + } selected.remove(feature); }); } else { From 7fa0a9050612886c2197d8cade688a8b24ee2176 Mon Sep 17 00:00:00 2001 From: Leane Schlundt Date: Mon, 15 Jan 2024 10:40:05 +0100 Subject: [PATCH 2/6] Delete and update features from annotationSource --- .../videoScreen/annotationPlayback.vue | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/resources/assets/js/videos/components/videoScreen/annotationPlayback.vue b/resources/assets/js/videos/components/videoScreen/annotationPlayback.vue index 4e8c06e8f..0eed3d29b 100644 --- a/resources/assets/js/videos/components/videoScreen/annotationPlayback.vue +++ b/resources/assets/js/videos/components/videoScreen/annotationPlayback.vue @@ -63,7 +63,6 @@ export default { // a seek was performed to the exact annotation time. Hence, we round the // time here to the maximum of 4 decimals, too. time = rtp(time); - for (let i = 0, length = annotations.length; i < length; i++) { // We can skip ahead and break early because of the sorting in the // annotationsPreparedToRender array. @@ -90,13 +89,13 @@ export default { toCreate.push(annotation.self); } } - if (hasRenderedFeatures) { Object.values(oldRendered).forEach(function (feature) { - // source.hasFeature(feature) does not work here, because it is always true - if (source.getFeatures().includes(feature)) { - source.removeFeature(feature); - } + // The annotation source uses featureChangeKeys method with featureKey as parameter. + // Feature and oldFeature do not have the same key, + // which is why featureChangeKeys returns undefined in removeFeature(feature). + let oldFeature = source.getFeatureById(feature.getId()); + source.removeFeature(oldFeature); selected.remove(feature); }); } else { @@ -110,8 +109,7 @@ export default { selected.clear(); } } - - + let features = toCreate.map(this.createFeature); features.forEach(function (feature) { newRendered[feature.getId()] = feature; @@ -138,7 +136,13 @@ export default { source.addFeature(newFeature); }, createFeature(annotation) { - let feature = new Feature(this.getGeometryFromPoints(annotation.shape, annotation.points[0])); + // Use feature from annotationSource if it exists, + // otherwise annotations are not updated on video after label-swap and deletion. + let feature = this.annotationSource.getFeatureById(annotation.id); + + if (feature === null){ + feature = new Feature(this.getGeometryFromPoints(annotation.shape, annotation.points[0])); + } feature.setId(annotation.id); feature.set('annotation', annotation); From 02d209ac764937aa64f41a84b711075fbc432d23 Mon Sep 17 00:00:00 2001 From: Leane Schlundt Date: Tue, 16 Jan 2024 08:33:09 +0100 Subject: [PATCH 3/6] Revert "Delete and update features from annotationSource" This reverts commit 7fa0a9050612886c2197d8cade688a8b24ee2176. --- .../videoScreen/annotationPlayback.vue | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/resources/assets/js/videos/components/videoScreen/annotationPlayback.vue b/resources/assets/js/videos/components/videoScreen/annotationPlayback.vue index 0eed3d29b..4e8c06e8f 100644 --- a/resources/assets/js/videos/components/videoScreen/annotationPlayback.vue +++ b/resources/assets/js/videos/components/videoScreen/annotationPlayback.vue @@ -63,6 +63,7 @@ export default { // a seek was performed to the exact annotation time. Hence, we round the // time here to the maximum of 4 decimals, too. time = rtp(time); + for (let i = 0, length = annotations.length; i < length; i++) { // We can skip ahead and break early because of the sorting in the // annotationsPreparedToRender array. @@ -89,13 +90,13 @@ export default { toCreate.push(annotation.self); } } + if (hasRenderedFeatures) { Object.values(oldRendered).forEach(function (feature) { - // The annotation source uses featureChangeKeys method with featureKey as parameter. - // Feature and oldFeature do not have the same key, - // which is why featureChangeKeys returns undefined in removeFeature(feature). - let oldFeature = source.getFeatureById(feature.getId()); - source.removeFeature(oldFeature); + // source.hasFeature(feature) does not work here, because it is always true + if (source.getFeatures().includes(feature)) { + source.removeFeature(feature); + } selected.remove(feature); }); } else { @@ -109,7 +110,8 @@ export default { selected.clear(); } } - + + let features = toCreate.map(this.createFeature); features.forEach(function (feature) { newRendered[feature.getId()] = feature; @@ -136,13 +138,7 @@ export default { source.addFeature(newFeature); }, createFeature(annotation) { - // Use feature from annotationSource if it exists, - // otherwise annotations are not updated on video after label-swap and deletion. - let feature = this.annotationSource.getFeatureById(annotation.id); - - if (feature === null){ - feature = new Feature(this.getGeometryFromPoints(annotation.shape, annotation.points[0])); - } + let feature = new Feature(this.getGeometryFromPoints(annotation.shape, annotation.points[0])); feature.setId(annotation.id); feature.set('annotation', annotation); From 77bf4c02ca6f3d0d0ff17c87579efbada08ed5e8 Mon Sep 17 00:00:00 2001 From: Leane Schlundt Date: Tue, 16 Jan 2024 08:34:17 +0100 Subject: [PATCH 4/6] Revert "Check feature's availability before removing it" This reverts commit 1c3d2554e9d0f9d6fa396ee6ff2f61e4df1f8f51. --- .../videos/components/videoScreen/annotationPlayback.vue | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/resources/assets/js/videos/components/videoScreen/annotationPlayback.vue b/resources/assets/js/videos/components/videoScreen/annotationPlayback.vue index 4e8c06e8f..ac65ed8ea 100644 --- a/resources/assets/js/videos/components/videoScreen/annotationPlayback.vue +++ b/resources/assets/js/videos/components/videoScreen/annotationPlayback.vue @@ -90,13 +90,10 @@ export default { toCreate.push(annotation.self); } } - + if (hasRenderedFeatures) { Object.values(oldRendered).forEach(function (feature) { - // source.hasFeature(feature) does not work here, because it is always true - if (source.getFeatures().includes(feature)) { - source.removeFeature(feature); - } + source.removeFeature(feature); selected.remove(feature); }); } else { From 85858d98dccf2c1b2899b21fbc54e783182c5fbc Mon Sep 17 00:00:00 2001 From: Leane Schlundt Date: Tue, 16 Jan 2024 08:49:40 +0100 Subject: [PATCH 5/6] Change color only when refreshing annotation Fix bug by using old feature instead of creating new one. --- .../components/videoScreen/annotationPlayback.vue | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/resources/assets/js/videos/components/videoScreen/annotationPlayback.vue b/resources/assets/js/videos/components/videoScreen/annotationPlayback.vue index ac65ed8ea..cfdbe4b17 100644 --- a/resources/assets/js/videos/components/videoScreen/annotationPlayback.vue +++ b/resources/assets/js/videos/components/videoScreen/annotationPlayback.vue @@ -128,11 +128,12 @@ export default { refreshSingleAnnotation(annotation) { let source = this.annotationSource; - let newFeature = this.createFeature(annotation); - let oldFeature = source.getFeatureById(annotation.id) - - source.removeFeature(oldFeature); - source.addFeature(newFeature); + let feature = source.getFeatureById(annotation.id) + + source.removeFeature(feature); + + feature.set('color', annotation.labels[0].label.color); + source.addFeature(feature); }, createFeature(annotation) { let feature = new Feature(this.getGeometryFromPoints(annotation.shape, annotation.points[0])); From 8bc71316db3a88cab648f507e20dc00491b62407 Mon Sep 17 00:00:00 2001 From: Leane Schlundt Date: Wed, 17 Jan 2024 07:28:15 +0100 Subject: [PATCH 6/6] Remove unnecessary code --- .../js/videos/components/videoScreen/annotationPlayback.vue | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/resources/assets/js/videos/components/videoScreen/annotationPlayback.vue b/resources/assets/js/videos/components/videoScreen/annotationPlayback.vue index cfdbe4b17..fa0f65cc2 100644 --- a/resources/assets/js/videos/components/videoScreen/annotationPlayback.vue +++ b/resources/assets/js/videos/components/videoScreen/annotationPlayback.vue @@ -128,12 +128,9 @@ export default { refreshSingleAnnotation(annotation) { let source = this.annotationSource; - let feature = source.getFeatureById(annotation.id) - - source.removeFeature(feature); + let feature = source.getFeatureById(annotation.id); feature.set('color', annotation.labels[0].label.color); - source.addFeature(feature); }, createFeature(annotation) { let feature = new Feature(this.getGeometryFromPoints(annotation.shape, annotation.points[0]));