dimanche 26 juin 2016

Bootstrap Modal + Cornerstone.js Library


I'm working on a solution that displays a list of thumbnails that are medical images. We have a requirement that states if a user clicks a thumbnail a Bootstrap modal should open that display the image (jpg, png or dicom) using the cornerstone.js library.

Using cornerstone seems pretty straightforward. I setup a quick plunker here.

Here's the code for the working plunk:

<!DOCTYPE html>
<html>

<head>
  <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
  <script src="jquery.min.js"></script>
  <script src="cornerstone.js"></script>
  <script src="exampleImageIdLoader.js"></script>
  <script type="text/javascript">
    $(document).ready(function() {
      var imageId = 'example://1';
      var element = document.getElementById('dicomImage');
      cornerstone.enable(element);
      cornerstone.loadImage(imageId).then(function(image) {
        cornerstone.displayImage(element, image);
      });
    });
  </script>
</head>

<body>
  <div class="container">
    <h1>This works just fine...</h1> 
    <br>
    <div id="dicomImage" style="width:512px;height:512px;">
    </div>
  </div>
</body>

</html>

I can't seem to figure out why the images are not loading when I use the same code in a Bootstrap modal. The plunk that I'm trying to get working is here.

Here's the code for the broken plunk:

<!DOCTYPE html>
<html>

<head>
  <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <script src="jquery.min.js"></script>
  <script src="cornerstone.js"></script>
  <script src="exampleImageIdLoader.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  <script type="text/javascript">
    $(document).ready(function() {
      var imageId = 'example://1';
      var element = document.getElementById('dicomImage');
      cornerstone.enable(element);
      cornerstone.loadImage(imageId).then(function(image) {
        cornerstone.displayImage(element, image);
      });
    });
  </script>
</head>

<body>
  <div class="container">
    <h1>When this modal is opened the canvas looks like it's drawn at 0px x 0px...</h1>
    <br />
    <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
    <div id="myModal" class="modal fade" role="dialog">
      <div class="modal-dialog">
        <!-- Modal content-->
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">×</button>
            <h4 class="modal-title">Modal Header</h4>
          </div>
          <div class="modal-body">
            <div id="dicomImage" style="width:512px;height:512px;"></div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</body>

</html>

After hours or trying to figure it out I figured I would see if anyone out there has any ideas. It looks like the plunk with the modal is drawing the canvas at 0x0 pixels...

Any thoughts or help would be GREATLY appreciated. Thanks all.

Update 6/26

I may have found a potential workaround, but it's not as clean as I would like it to be. I also haven't tested it by playing a series of CT images.

My thoughts are to use the working solution from the first plunk and to call .hide() on #dicomImage on document.ready. Then, when a user clicks a thumbnail, I will use:

$(".modal-body").appendTO("#dicomImage);

Not the cleanest solution, but it could work...


Aucun commentaire:

Enregistrer un commentaire