question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TIFF File not loading in the Plain Javascript

See original GitHub issue
<html>
<body>
<div id="openseadragon1" >
</div>

<script src="tiff.min.js"></script>
<script src="openseadragon.min.js"></script>
<script src="jquery-2.0.3.min.js"></script>
<script src="imaginghelper.js"></script>
<script type="text/javascript">

  var viewer = OpenSeadragon({
    id: "openseadragon1",
        prefixUrl: "images/",
		 crossOriginPolicy: 'Anonymous',
		   ajaxWithCredentials: false,
		    
		sequenceMode:  true,
		preload:true,
		  tileSources: [{
            x: 0.883,
            y: 1,
            width: 100,
            tileSource: "file_example_TIFF_1MB.tiff"
        },
        {
            x: 1,
            y: 1,
            width: 200,
            tileSource: "file_example_TIFF_1MB.tiff"
        }
   ] 
});

 

/*viewer.addHandler("page", function (data) {
viewer.open();
   viewer.addTiledImage({
    tileSource: '20190022.177000.01.tif',
    x: 5,
    y: 0,
    width: 10
});
	
});*/

 
function FnOnlcik()
{
	alert(11)
}
</script>
</body>
</html>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
iangilmancommented, Feb 15, 2019

I don’t think OSD currently supports directly loading from canvas (though that’s an interesting feature idea). You would need to convert it to a dataURL and then add the image once it’s ready. Something like so:

var viewer = OpenSeadragon({
  id: "openseadragon1",
  prefixUrl: "images/",
  crossOriginPolicy: 'Anonymous',
  ajaxWithCredentials: false,
  sequenceMode: true,
  preload: true,
  showNavigator: true
});

function fnLoadData() {
  var width = 100;
  try {
    var xhr = new XMLHttpRequest();
    xhr.open('GET', "A1001001A19B13B55647B25937.tif");
    xhr.responseType = 'arraybuffer';
    xhr.onload = function (e) {
      var tiff = new Tiff({ buffer: xhr.response });
      alert(tiff.countDirectory());
      for (var i = 0, len = tiff.countDirectory(); i < len; ++i) {
        tiff.setDirectory(i);
        var canvas = tiff.toCanvas();
        viewer.addTiledImage({
          tileSource: {
            type: 'image',
            url: canvas.toDataURL(),
            buildPyramid: false
          },
          x: i * width,
          y: 0,
          width: width
        });
      }
    };

    xhr.send();
  }
  catch (e) {
    alert(e.description);
  }
}

fnLoadData();

BTW, note that I’m providing positioning info with each of the images, but you’re creating the viewer with sequenceMode: true, which means it’ll override that positioning info. You can try it both ways to see which you prefer.

Also note that I’ve mode buildPyramid: false into the tileSource; it’s not a viewer option.

0reactions
farookshaikcommented, Feb 20, 2019

Thank you. Your approach works perfectly for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Display an image as .tiff or .tif - javascript - Stack Overflow
Displaying Tiff File in angular by displaying the image in the canvas. Download the 'tiff.min.js' from https://github.com/seikichi/tiff.js ...
Read more >
How to visualize GeoTIFF images - Luciad Developer Platform
This article describes how to load and visualize GeoTIFF data in LuciadRIA. ... geotiff.js is a small library to parse TIFF files for...
Read more >
QuPath not loading pyramid TIFFs properly - Usage & Issues
I'm trying to load large files (at least 3GB in size) in QuPath. Information about the images: (i) Single channel (ii) unsigned 16...
Read more >
problem with adding a tiff-file to a map - Esri Community
hello, maybe this is a very simple question, but I'm quite new to ArcGIS: I want to add a shapefile and a tiff-file...
Read more >
How to view multipages tiff files using JavaScript or HTML5
Why is my external JavaScript file not working? 29,202 Views · Which is best for building a browser video game: HTML5 Canvas, SVG,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found