Skip to content
Snippets Groups Projects
Commit d5ca35a2 authored by fsdavid's avatar fsdavid
Browse files

fix polygons in list

parent 9aec8346
No related branches found
No related tags found
No related merge requests found
......@@ -14,8 +14,8 @@ export class AnnotationList {
get annotationsToShow() {
return this.ans.annotations
// .filter(a => this.annotationFilter === 'all' || a.templateName === this.ans.selectedTemplate)
// .filter(a => (a.type !== 'polygon' || +a.id.split('_')[1] === 0)
// .filter(a => this.annotationFilter === 'all' || a.templateName === this.ans.selectedTemplate)
// .filter(a => (a.type !== 'polygon' || +a.id.split('_')[1] === 0)
// let transformed = [...this.ans.annotations]
//
......@@ -115,4 +115,18 @@ export class AnnotationList {
this.ans.saveAnnotation(annotation)
}
savePolygonPosition(position, inputVal) {
position.lines.forEach(l => {
if (l.point === 2) {
const annotation = this.ans.annotations.find(a => a.id === l.id)
annotation.position2 = inputVal
this.saveAnnotation(annotation)
} else {
const annotation = this.ans.annotations.find(a => a.id === l.id)
annotation.position1 = inputVal
this.saveAnnotation(annotation)
}
})
}
}
......@@ -86,8 +86,9 @@
<div *ngFor="let position of annotation.positions" class="w-100 d-flex align-items-center justify-content-between mb-2">
<input class="w-100 font-italic d-flex align-items-center outline-none color-inherit"
[value]="position?.position"
(keyup)="this.saveAnnotation(annotation)"/>
<small class="d-flex align-items-center">mm <i class="fas fa-map-marked-alt mr-2 ml-2 cursor-pointer" (click)="navigate(annotation?.position?.position)"></i></small>
#polygonPositionInput
(keyup)="this.savePolygonPosition(position, polygonPositionInput.value)"/>
<small class="d-flex align-items-center">mm <i class="fas fa-map-marked-alt mr-2 ml-2 cursor-pointer" (click)="navigate(position?.position)"></i></small>
</div>
</div>
......
......@@ -122,18 +122,20 @@ export class AnnotationService implements OnDestroy {
}
}
giveNameByType(type) {
const pointAnnotationNumber = this.annotations
.filter(a => a.name && a.name.startsWith(type) && (+a.name.split(type)[1]))
.map(a => +a.name.split(type)[1])
return pointAnnotationNumber && pointAnnotationNumber.length?
`${type}${Math.max(...pointAnnotationNumber) + 1}` : `${type}1`
}
storeAnnotation(annotation) {
// give names by type + number
if (!annotation.name) {
const pointAnnotationNumber = this.annotations
.filter(a => a.name && a.name.startsWith(annotation.type) && (+a.name.split(annotation.type)[1]))
.map(a => +a.name.split(annotation.type)[1])
if (pointAnnotationNumber && pointAnnotationNumber.length) {
annotation.name = `${annotation.type}${Math.max(...pointAnnotationNumber) + 1}`
} else {
annotation.name = `${annotation.type}1`
}
annotation.name = this.giveNameByType(annotation.type)
}
const foundIndex = this.annotations.findIndex(x => x.id === annotation.id)
......@@ -198,6 +200,7 @@ export class AnnotationService implements OnDestroy {
removeAnnotation(id) {
this.removeAnnotationFromViewer(id)
this.annotations = this.annotations.filter(a => a.id !== id)
this.displayAnnotations = this.annotations.filter(a => a.id !== id)
this.storeToLocalStorage()
}
......@@ -227,29 +230,33 @@ export class AnnotationService implements OnDestroy {
const polygonAnnotations = annotations.filter(a => a.id.split('_')[0] === annotationId[0]
&& a.id.split('_')[1])
const polygonPositions = polygonAnnotations.map((a, i) => {
return i+1 !== polygonAnnotations.length? {
const polygonPositions = polygonAnnotations.map((a, index) => {
return (index+1) !== polygonAnnotations.length? {
position: a.position2,
lines: [
{id: a.id, point: 2},
{id: polygonAnnotations[i+1], point: 1}
{id: polygonAnnotations[index+1].id, point: 1}
]
} : polygonAnnotations[i].position2 !== polygonAnnotations[0].position1? {
} : a.position2 !== polygonAnnotations[0].position1? {
position: a.position2,
lines: [
{id: a.id, point: 2}
]
} : {
position: a.position2,
lines: [
{id: a.id, point: 2},
{id: polygonAnnotations[0].id, point: 1}
]
}
} : null
}).filter(a => !!a)
polygonPositions.unshift({
position: polygonAnnotations[0].position1,
lines: polygonAnnotations[0].position1 === [...polygonAnnotations].pop().position2?
[{id: polygonAnnotations[0].id, point: 1}, {id: [...polygonAnnotations].pop().id, point: 2}]
: [{id: polygonAnnotations[0].id, point: 1}]
})
transformed = transformed.filter(a => a.id.split('_')[0] !== annotationId[0])
if (!annotations[i].name) {
annotations[i].name = this.giveNameByType(annotations[i].type)
}
transformed.push({
id: annotationId[0],
name: annotations[i].name,
......@@ -263,10 +270,15 @@ export class AnnotationService implements OnDestroy {
}
this.displayAnnotations = [
...this.displayAnnotations,
...transformed
]
transformed.forEach(tr=> {
const foundIndex = this.displayAnnotations.findIndex(x => x.id === tr.id)
if (foundIndex >= 0) {
this.displayAnnotations[foundIndex] = tr
} else {
this.displayAnnotations.push(tr)
}
})
}
changeAnnotationFilter(filter) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment