mirror of
https://github.com/nasa/openmct.git
synced 2025-02-12 21:56:13 +00:00
loading annotations from db
This commit is contained in:
parent
2d868cdb58
commit
cb32dd94f8
@ -25,9 +25,9 @@
|
|||||||
ref="canvas"
|
ref="canvas"
|
||||||
class="c-image-canvas"
|
class="c-image-canvas"
|
||||||
style="width: 100%; height: 100%;"
|
style="width: 100%; height: 100%;"
|
||||||
@mousedown="mouseDown"
|
@mousedown="startAnnotationDrag"
|
||||||
@mousemove="mouseMove"
|
@mousemove="trackAnnotationDrag"
|
||||||
@click="mouseClick"
|
@click="createAnnotationSelection"
|
||||||
></canvas>
|
></canvas>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -36,11 +36,15 @@
|
|||||||
export default {
|
export default {
|
||||||
inject: ['openmct', 'domainObject', 'objectPath'],
|
inject: ['openmct', 'domainObject', 'objectPath'],
|
||||||
props: {
|
props: {
|
||||||
|
image: {
|
||||||
|
type: Object,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
dragging: false,
|
dragging: false,
|
||||||
rectangle: {}
|
newAnnotationRectangle: {}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
@ -50,8 +54,8 @@ export default {
|
|||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
drawRectInCanvas() {
|
drawRectInCanvas(rectangle) {
|
||||||
console.debug(`🪟 Drawing rectangle, ${this.rectangle.x} ${this.rectangle.y} ${this.rectangle.width} ${this.rectangle.height}`, this.rectangle);
|
console.debug(`🪟 Drawing rectangle, ${rectangle.x} ${rectangle.y} ${rectangle.width} ${rectangle.height}`, rectangle);
|
||||||
const canvas = this.$refs.canvas;
|
const canvas = this.$refs.canvas;
|
||||||
const context = canvas.getContext("2d");
|
const context = canvas.getContext("2d");
|
||||||
context.clearRect(0, 0, canvas.width, canvas.height);
|
context.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
@ -59,11 +63,11 @@ export default {
|
|||||||
context.lineWidth = "1";
|
context.lineWidth = "1";
|
||||||
context.fillStyle = "rgba(199, 87, 231, 0.2)";
|
context.fillStyle = "rgba(199, 87, 231, 0.2)";
|
||||||
context.strokeStyle = "#c757e7";
|
context.strokeStyle = "#c757e7";
|
||||||
context.rect(this.rectangle.x, this.rectangle.y, this.rectangle.width, this.rectangle.height);
|
context.rect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
|
||||||
context.fill();
|
context.fill();
|
||||||
context.stroke();
|
context.stroke();
|
||||||
},
|
},
|
||||||
mouseMove(event) {
|
trackAnnotationDrag(event) {
|
||||||
if (this.dragging) {
|
if (this.dragging) {
|
||||||
console.debug(`🐭 mouseMove: ${event.type}`);
|
console.debug(`🐭 mouseMove: ${event.type}`);
|
||||||
const canvas = this.$refs.canvas;
|
const canvas = this.$refs.canvas;
|
||||||
@ -71,26 +75,50 @@ export default {
|
|||||||
const boundingRect = canvas.getBoundingClientRect();
|
const boundingRect = canvas.getBoundingClientRect();
|
||||||
const scaleX = canvas.width / boundingRect.width;
|
const scaleX = canvas.width / boundingRect.width;
|
||||||
const scaleY = canvas.height / boundingRect.height;
|
const scaleY = canvas.height / boundingRect.height;
|
||||||
this.rectangle = {
|
this.newAnnotationRectangle = {
|
||||||
x: this.rectangle.x,
|
x: this.newAnnotationRectangle.x,
|
||||||
y: this.rectangle.y,
|
y: this.newAnnotationRectangle.y,
|
||||||
width: ((event.clientX - boundingRect.left) * scaleX) - this.rectangle.x,
|
width: ((event.clientX - boundingRect.left) * scaleX) - this.newAnnotationRectangle.x,
|
||||||
height: ((event.clientY - boundingRect.top) * scaleY) - this.rectangle.y
|
height: ((event.clientY - boundingRect.top) * scaleY) - this.newAnnotationRectangle.y
|
||||||
};
|
};
|
||||||
this.drawRectInCanvas();
|
this.drawRectInCanvas(this.newAnnotationRectangle);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mouseClick(event) {
|
clearNewRectangleSelection() {
|
||||||
|
this.newAnnotationRectangle = {};
|
||||||
|
const canvas = this.$refs.canvas;
|
||||||
|
const context = canvas.getContext("2d");
|
||||||
|
context.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
|
},
|
||||||
|
selectImageView() {
|
||||||
|
// should show ImageView itself if we have no annotations to display
|
||||||
|
const selection = this.createPathSelection();
|
||||||
|
this.openmct.selection.select(selection, true);
|
||||||
|
},
|
||||||
|
createAnnotationSelection(event) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
console.debug(`🐭 mouseUp, dragging disabled`);
|
console.debug(`🐭 mouseClick, dragging disabled`);
|
||||||
this.dragging = false;
|
this.dragging = false;
|
||||||
|
// check to see if we have a rectangle
|
||||||
|
if (!this.newAnnotationRectangle.width && !this.newAnnotationRectangle.height) {
|
||||||
|
console.debug(`🍊 no rectangle, clearing selection`);
|
||||||
|
this.selectImageView();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = {};
|
||||||
targetDetails[keyString] = {
|
targetDetails[keyString] = {
|
||||||
x: this.rectangle.x,
|
rectangle: {
|
||||||
y: this.rectangle.y,
|
x: this.newAnnotationRectangle.x,
|
||||||
width: this.rectangle.width,
|
y: this.newAnnotationRectangle.y,
|
||||||
height: this.rectangle.height
|
width: this.newAnnotationRectangle.width,
|
||||||
|
height: this.newAnnotationRectangle.height
|
||||||
|
},
|
||||||
|
time: this.image.time
|
||||||
};
|
};
|
||||||
const targetDomainObjects = {};
|
const targetDomainObjects = {};
|
||||||
targetDomainObjects[keyString] = this.domainObject;
|
targetDomainObjects[keyString] = this.domainObject;
|
||||||
@ -142,24 +170,33 @@ export default {
|
|||||||
|
|
||||||
return selection;
|
return selection;
|
||||||
},
|
},
|
||||||
mouseDown(event) {
|
startAnnotationDrag(event) {
|
||||||
console.debug(`🐭 mouseDown`);
|
console.debug(`🐭 mouseDown`);
|
||||||
|
this.clearNewRectangleSelection();
|
||||||
const canvas = this.$refs.canvas;
|
const canvas = this.$refs.canvas;
|
||||||
|
|
||||||
const boundingRect = canvas.getBoundingClientRect();
|
const boundingRect = canvas.getBoundingClientRect();
|
||||||
const scaleX = canvas.width / boundingRect.width;
|
const scaleX = canvas.width / boundingRect.width;
|
||||||
const scaleY = canvas.height / boundingRect.height;
|
const scaleY = canvas.height / boundingRect.height;
|
||||||
this.rectangle = {
|
this.newAnnotationRectangle = {
|
||||||
x: (event.clientX - boundingRect.left) * scaleX,
|
x: (event.clientX - boundingRect.left) * scaleX,
|
||||||
y: (event.clientY - boundingRect.top) * scaleY,
|
y: (event.clientY - boundingRect.top) * scaleY
|
||||||
width: scaleX,
|
|
||||||
height: scaleY
|
|
||||||
};
|
};
|
||||||
this.drawRectInCanvas();
|
|
||||||
this.dragging = true;
|
this.dragging = true;
|
||||||
|
|
||||||
},
|
},
|
||||||
drawAnnotations() {
|
async drawAnnotations() {
|
||||||
|
// find annotations for this image time
|
||||||
|
const annotationsForThisObject = await this.openmct.annotation.getAnnotations(this.domainObject.identifier);
|
||||||
|
const keyString = this.openmct.objects.makeKeyString(this.domainObject.identifier);
|
||||||
|
const annotationsForThisImage = annotationsForThisObject.filter((foundAnnotation) => {
|
||||||
|
const annotationTime = foundAnnotation.targets[keyString].time;
|
||||||
|
|
||||||
|
return annotationTime === this.image.time;
|
||||||
|
});
|
||||||
|
annotationsForThisImage.forEach((annotation) => {
|
||||||
|
this.drawRectInCanvas(annotation.targets[keyString].rectangle);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -98,6 +98,7 @@
|
|||||||
/>
|
/>
|
||||||
<AnnotationsCanvas
|
<AnnotationsCanvas
|
||||||
v-if="shouldDisplayCompass"
|
v-if="shouldDisplayCompass"
|
||||||
|
:image="focusedImage"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user