mirror of
https://github.com/nasa/openmct.git
synced 2025-01-07 21:58:44 +00:00
still need to clean up selection code
This commit is contained in:
parent
91ad130f8b
commit
a8949d39bf
@ -25,7 +25,7 @@
|
|||||||
ref="canvas"
|
ref="canvas"
|
||||||
class="c-image-canvas"
|
class="c-image-canvas"
|
||||||
style="width: 100%; height: 100%;"
|
style="width: 100%; height: 100%;"
|
||||||
@mousedown="mouseDown = true"
|
@mousedown="clearSelectedAnnotations"
|
||||||
@mousemove="trackAnnotationDrag"
|
@mousemove="trackAnnotationDrag"
|
||||||
@click="selectOrCreateAnnotation"
|
@click="selectOrCreateAnnotation"
|
||||||
></canvas>
|
></canvas>
|
||||||
@ -57,6 +57,7 @@ export default {
|
|||||||
context: null,
|
context: null,
|
||||||
canvas: null,
|
canvas: null,
|
||||||
annotationsIndex: null,
|
annotationsIndex: null,
|
||||||
|
selectedAnnotations: [],
|
||||||
indexToAnnotationMap: {}
|
indexToAnnotationMap: {}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@ -78,7 +79,7 @@ export default {
|
|||||||
|
|
||||||
return annotationTime === this.image.time;
|
return annotationTime === this.image.time;
|
||||||
});
|
});
|
||||||
|
if (this.annotationsForThisImage.length) {
|
||||||
// create a flatbush index for the annotations
|
// create a flatbush index for the annotations
|
||||||
this.annotationsIndex = new Flatbush(this.annotationsForThisImage.length);
|
this.annotationsIndex = new Flatbush(this.annotationsForThisImage.length);
|
||||||
this.annotationsForThisImage.forEach((annotation) => {
|
this.annotationsForThisImage.forEach((annotation) => {
|
||||||
@ -89,6 +90,12 @@ export default {
|
|||||||
this.annotationsIndex.finish();
|
this.annotationsIndex.finish();
|
||||||
|
|
||||||
this.drawAnnotations();
|
this.drawAnnotations();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
clearSelectedAnnotations() {
|
||||||
|
console.debug(`🐁 mouseDown`);
|
||||||
|
this.mouseDown = true;
|
||||||
|
this.selectedAnnotations = [];
|
||||||
},
|
},
|
||||||
drawRectInCanvas(rectangle, fillStyle, strokeStyle) {
|
drawRectInCanvas(rectangle, fillStyle, strokeStyle) {
|
||||||
console.debug(`🪟 Drawing rectangle, ${rectangle.x} ${rectangle.y} ${rectangle.width} ${rectangle.height}`, rectangle);
|
console.debug(`🪟 Drawing rectangle, ${rectangle.x} ${rectangle.y} ${rectangle.width} ${rectangle.height}`, rectangle);
|
||||||
@ -114,7 +121,6 @@ export default {
|
|||||||
width: ((event.clientX - boundingRect.left) * scaleX) - this.newAnnotationRectangle.x,
|
width: ((event.clientX - boundingRect.left) * scaleX) - this.newAnnotationRectangle.x,
|
||||||
height: ((event.clientY - boundingRect.top) * scaleY) - this.newAnnotationRectangle.y
|
height: ((event.clientY - boundingRect.top) * scaleY) - this.newAnnotationRectangle.y
|
||||||
};
|
};
|
||||||
this.clearCanvas();
|
|
||||||
this.drawAnnotations();
|
this.drawAnnotations();
|
||||||
this.drawRectInCanvas(this.newAnnotationRectangle, SELECTED_ANNOTATION_FILL_STYLE, SELECTED_ANNOTATION_STROKE_COLOR);
|
this.drawRectInCanvas(this.newAnnotationRectangle, SELECTED_ANNOTATION_FILL_STYLE, SELECTED_ANNOTATION_STROKE_COLOR);
|
||||||
}
|
}
|
||||||
@ -127,17 +133,17 @@ export default {
|
|||||||
const selection = this.createPathSelection();
|
const selection = this.createPathSelection();
|
||||||
this.openmct.selection.select(selection, true);
|
this.openmct.selection.select(selection, true);
|
||||||
},
|
},
|
||||||
|
createSelection(annotation) {
|
||||||
|
const selection = this.createPathSelection();
|
||||||
|
selection[0].context = annotation;
|
||||||
|
|
||||||
|
return selection;
|
||||||
|
},
|
||||||
createNewAnnotation() {
|
createNewAnnotation() {
|
||||||
this.dragging = false;
|
this.dragging = false;
|
||||||
// check to see if we have a rectangle
|
this.selectedAnnotations = [];
|
||||||
if (!this.newAnnotationRectangle.width && !this.newAnnotationRectangle.height) {
|
|
||||||
console.debug(`🍊 no rectangle, clearing selection`);
|
|
||||||
this.selectImageView();
|
|
||||||
|
|
||||||
return;
|
console.debug(`🖼️ Creating new image annotation`);
|
||||||
}
|
|
||||||
|
|
||||||
console.debug(`🌃 focused image: `, this.image);
|
|
||||||
|
|
||||||
const keyString = this.openmct.objects.makeKeyString(this.domainObject.identifier);
|
const keyString = this.openmct.objects.makeKeyString(this.domainObject.identifier);
|
||||||
const targetDetails = {};
|
const targetDetails = {};
|
||||||
@ -188,17 +194,22 @@ export default {
|
|||||||
const scaleY = this.canvas.height / boundingRect.height;
|
const scaleY = this.canvas.height / boundingRect.height;
|
||||||
const x = (event.clientX - boundingRect.left) * scaleX;
|
const x = (event.clientX - boundingRect.left) * scaleX;
|
||||||
const y = (event.clientY - boundingRect.top) * scaleY;
|
const y = (event.clientY - boundingRect.top) * scaleY;
|
||||||
|
if (this.annotationsIndex) {
|
||||||
const resultIndicies = this.annotationsIndex.search(x, y, x, y);
|
const resultIndicies = this.annotationsIndex.search(x, y, x, y);
|
||||||
resultIndicies.forEach((resultIndex) => {
|
resultIndicies.forEach((resultIndex) => {
|
||||||
const foundAnnotation = this.indexToAnnotationMap[resultIndex];
|
const foundAnnotation = this.indexToAnnotationMap[resultIndex];
|
||||||
console.debug(`🐭 found annotations at ${x} ${y}`, foundAnnotation);
|
console.debug(`🐭 found annotations at ${x} ${y}`, foundAnnotation);
|
||||||
|
|
||||||
|
this.selectedAnnotations.push(foundAnnotation);
|
||||||
});
|
});
|
||||||
|
this.drawAnnotations();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
selectOrCreateAnnotation(event) {
|
selectOrCreateAnnotation(event) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
this.mouseDown = false;
|
this.mouseDown = false;
|
||||||
console.debug(`🐭 mouseClick`);
|
console.debug(`🐭 mouseClick`);
|
||||||
if (!this.dragging) {
|
if ((!this.dragging) || (this.newAnnotationRectangle.width && !this.newAnnotationRectangle.height)) {
|
||||||
console.debug(`🐭 checking for existing annotations`);
|
console.debug(`🐭 checking for existing annotations`);
|
||||||
this.newAnnotationRectangle = {};
|
this.newAnnotationRectangle = {};
|
||||||
this.attemptToSelectExistingAnnotation(event);
|
this.attemptToSelectExistingAnnotation(event);
|
||||||
@ -239,9 +250,22 @@ export default {
|
|||||||
};
|
};
|
||||||
this.dragging = true;
|
this.dragging = true;
|
||||||
},
|
},
|
||||||
|
isSelectedAnnotation(annotation) {
|
||||||
|
const someSelectedAnnotationExists = this.selectedAnnotations.some((selectedAnnotation) => {
|
||||||
|
return this.openmct.objects.areIdsEqual(selectedAnnotation.identifier, annotation.identifier);
|
||||||
|
});
|
||||||
|
console.debug(`someSelectedAnnotationExists`, someSelectedAnnotationExists);
|
||||||
|
|
||||||
|
return someSelectedAnnotationExists;
|
||||||
|
},
|
||||||
drawAnnotations() {
|
drawAnnotations() {
|
||||||
|
this.clearCanvas();
|
||||||
this.annotationsForThisImage.forEach((annotation) => {
|
this.annotationsForThisImage.forEach((annotation) => {
|
||||||
|
if (this.isSelectedAnnotation(annotation)) {
|
||||||
|
this.drawRectInCanvas(annotation.targets[this.keyString].rectangle, SELECTED_ANNOTATION_FILL_STYLE, SELECTED_ANNOTATION_STROKE_COLOR);
|
||||||
|
} else {
|
||||||
this.drawRectInCanvas(annotation.targets[this.keyString].rectangle, EXISTING_ANNOTATION_FILL_STYLE, EXISTING_ANNOTATION_STROKE_STYLE);
|
this.drawRectInCanvas(annotation.targets[this.keyString].rectangle, EXISTING_ANNOTATION_FILL_STYLE, EXISTING_ANNOTATION_STROKE_STYLE);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user