Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index bigger than number of layers when loading in multilayer IIIF images #2457

Open
BeebBenjamin opened this issue Jan 22, 2024 · 11 comments
Open
Labels

Comments

@BeebBenjamin
Copy link

We are loading in manifests that contain images with multiple layers, the index value for example is 4 (so 5 layers). I have noticed that OSD throws an error when the index value is bigger than or equal to the number of layers when loading these in. For us, this is naturally because the layers are loading in asynchronously, and the count is sometimes initially smaller when this function is called, sometimes we do not get the error on a refresh. I have a feeling that something is not quite right.

@pearcetm
Copy link
Contributor

How are you actually loading these into the viewer once the information is available asynchronously? With viewer.addTiledImage()? Or some other way?

@BeebBenjamin
Copy link
Author

I will have to look at Mirador viewer and get back to you.

@BeebBenjamin
Copy link
Author

@pearcetm Mirador uses viewer.addTiledImage() in it's OpenSeadragonViewer component.

@BeebBenjamin
Copy link
Author

Here is the section:

viewer.addTiledImage({
        error: event => reject(event),
        fitBounds: new OpenSeadragon.Rect(
          ...canvasWorld.contentResourceToWorldCoordinates(contentResource),
        ),
        index: canvasWorld.layerIndexOfImageResource(contentResource),
        opacity: canvasWorld.layerOpacityOfImageResource(contentResource),
        success: event => resolve(event),
        tileSource,
      });

@pearcetm
Copy link
Contributor

I can't tell just from the code what is going on. Is there a demo page that shows the behavior you're describing? What is the error message you're seeing?

OSD can add tiled images with index undefined, and doesn't have a problem if an index is greater than viewer.world.getItemCount()+1, and even handles negative numbers as the index.

You might try using the debugger to see what value is being returned from canvasWorld.layerIndexOfImageResource(contentResource) and other mirador-specific calls.

@iangilman
Copy link
Member

I have noticed that OSD throws an error when the index value is bigger than or equal to the number of layers when loading these in.

What index value?

@BeebBenjamin
Copy link
Author

Error is:

Uncaught (in promise) Error: Index bigger than number of layers.
    at e.World.setItemIndex (mirador-with-plugins.js:2:1421440)
    at mirador-with-plugins.js:2:565942
    at Array.forEach (<anonymous>)
    at a.value (mirador-with-plugins.js:2:565813)
    at mirador-with-plugins.js:2:564695

@pearcetm
Copy link
Contributor

Ok, so the error is being thrown from World.setImageIndex(). It looks like there's a mismatch between what mirador thinks the "layer index" is (or can be) versus the number of images that have actually been loaded into viewer at the time. This is because mirador (or your application) knows about all the images that will eventually be loaded, while OSD only knows about those that have already been added to the viewer. In a viewer with only one image, it doesn't make sense to tell it that the image should be at index = 4 in the array - so OSD throws an error.

There are probably a number of ways this could be handled, but keeping track within mirador/application code of which images have actually been added to the viewer, and what index they are within the viewer.world, is probably the best approach.

@BeebBenjamin
Copy link
Author

There is a bug is Mirador 3 that might related to this issue: ProjectMirador/mirador#3585

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants