Hello,
I am trying to add cornerstone, cornerstoneTools and cornerstoneWebImageLoader in an angular 2 project.
I have managed so far to show an image in my component and (I think) to use cornerstoneWebImageLoader correctly...
After this part finishes
cornerstone.loadImage(this.imageId).then(function (image) {
cornerstone.displayImage(element, image);
I get TypeError: u.external.cornerstone.events.dispatchEvent is not a function which is coming from cornerstoneWebImageLoader.js.
Also, on mouse action on the image i get ERROR Error: element not enabled.
I am trying to understand if this is happening because cornerstoneWebImageLoader is not loaded correctly, or it has to do with the order of angular is loading components etc or ......
CODE:
in .angular.cli.json
"scripts": ["../node_modules/jquery/dist/jquery.min.js",
"../node_modules/cornerstone-core/dist/cornerstone.min.js",
"../node_modules/cornerstone-math/dist/cornerstoneMath.min.js",
"../node_modules/cornerstone-tools/dist/cornerstoneTools.min.js",
"../node_modules/cornerstone-web-image-loader/dist/cornerstoneWebImageLoader.js"],
my directive (got it from the angular2-cornerstone example)
import { Directive, ElementRef, Input } from '@angular/core';
import * as $ from 'jquery';
import * as cornerstone from 'cornerstone-core';
import * as cornerstoneMath from 'cornerstone-math';
import * as cornerstoneTools from 'cornerstone-tools';
import * as cornerstoneWebImageLoader from 'cornerstone-web-image-loader';
@Directive({
selector: '[myCornerstoneElement]',
})
export class CornerstoneElementDirective {
elementRef: ElementRef;
@Input('myCornerstoneElement') imageId: string;
constructor(elementRef: ElementRef) {
this.elementRef = elementRef;
}
ngOnInit(el: ElementRef) {
let s = document.createElement('script');
s.type = 'text/javascript';
s.innerText = 'cornerstoneWebImageLoader.external.cornerstone = cornerstone;';
this.elementRef.nativeElement.appendChild(s);
cornerstoneWebImageLoader.external.cornerstone = cornerstone;
// If no imageId is given, do nothing
if (!this.imageId) {
return;
}
// Retrieve the DOM element itself
let element = this.elementRef.nativeElement;
// Enable the element with Cornerstone
cornerstone.enable(element);
// Load the image and enable tools
cornerstone.loadImage(this.imageId).then(function (image) {
cornerstone.displayImage(element, image);
cornerstoneTools.mouseInput.enable(element);
cornerstoneTools.mouseWheelInput.enable(element);
// Enable all tools we want to use with this element
cornerstoneTools.wwwc.activate(element, 1); // ww/wc is the default tool for left mouse button
cornerstoneTools.pan.activate(element, 2); // pan is the default tool for middle mouse button
cornerstoneTools.zoom.activate(element, 4); // zoom is the default tool for right mouse button
cornerstoneTools.zoomWheel.activate(element); // zoom is the default tool for middle mouse wheel
cornerstoneTools.probe.enable(element);
cornerstoneTools.length.enable(element);
cornerstoneTools.ellipticalRoi.enable(element);
cornerstoneTools.rectangleRoi.enable(element);
cornerstoneTools.angle.enable(element);
cornerstoneTools.highlight.enable(element);
});
}
}
And my component.html
Any help would be appreciated.
Thank you in advance
Thanos