seikichi/tiff.js

countDirectory decrementing

cvaughn42 opened this issue · 2 comments

I have the following code to iterate through the tiff pages:

       function displayTiff(index)
        {
            if (tiff)
            {
                if (index >= 0 && index < tiff.countDirectory())
                {
                    tiff.setDirectory(index);

                    var canvas = tiff.toCanvas();

                    if (canvas)
                    {
                        canvas.setAttribute('style', 'width: 4.25in;'); 
                    }

                    canvas.addEventListener('mouseout', function(e) {
                        $('#mouseCoodinates').text('');
                    }, false);

                    canvas.addEventListener('mousemove', function(e) {

                        $('#mouseCoodinates').text('x=' + e.x + ';y=' + e.y);

                        // zoomImage(e.x, e.y);
                    }, false);
                    
                    $('#tiffDiv canvas').remove();
                    
                    $('#tiffDiv').append(canvas);
                }
            }
        }

I could never page to the end of the tiff -- I usually stopped around page 5 even though I new my TIFF had more pages. I put in a watch and saw that countDirectory() was decrementing. I expected if the TIFF had 8 pages it would always be 8, but by the time I reached the fifth page, countDirectory() was returning 5 and I couldn't page further. I changed my code to capture the value of countDirectory() immediately after loading the tiff and then used that value as my max and the code works, but I wanted to let you know this might be an issue (maybe I don't understand how "countDirectory()" is supposed to work.)

Thank you for a great product, though!

+1!!!

@cvaughn42
Problem solved
setDirectory(index) index begins from 0 but the page value begins from 1.

handlePageChange = page => {
    const { tiff } = this;
    tiff.setDirectory(page - 1);
    this.renderCanvas();
    this.setState({ page });
};