annotorious / annotorious-openseadragon

An OpenSeadragon plugin for annotating high-res zoomable images
https://annotorious.github.io
BSD 3-Clause "New" or "Revised" License
121 stars 42 forks source link

Firebase plugin is not working with OSD and dynamic tile sources #129

Closed darkmich closed 1 year ago

darkmich commented 2 years ago

Steps to replicate: Set up an OpenSeadragon instance using a dynamic tile source, initialize the Annotorious OSD plugin. Try to load the Firebase plugin.

Error: When annotations are saved, they're always saved as the base URL plus "undefined".

This seems to be due to Firebase using the URL from OSDAnnotationLayer.js (lines 66+67):

      const src = this.viewer.world.getItemAt(0).source['@id'] || 
        new URL(this.viewer.world.getItemAt(0).source.url, document.baseURI).href;

In our OSD implementation, this.viewer.world.getItemAt(0).source.url is undefined. This can be worked around by setting it prior to calling Firebase - that has to be done in TileDoneHandler to make sure that source is defined, as it's only defined when OSD actually puts something in the canvas:

var tileDrawnHandler = function(event) {
  viewer.removeHandler('tile-drawn', tileDrawnHandler);
viewer.world.getItemAt(0).source.url = <URL>

I suspect this is because our OSD tile source isn't a file - we're loading tiles from S3-storage as we need them.

    var viewer = OpenSeadragon({
        id: "openseadragon1",
        prefixUrl: "https://cdnjs.cloudflare.com/ajax/libs/openseadragon/2.4.2/images/",
        navigatorAutoFade:  false,
        showNavigator:  true,
        zoomInButton:   "zoomIn",
        zoomOutButton:  "zoomOut",
        homeButton:     "home",
        fullPageButton: "fullscreen",
        gestureSettingsTouch: {
            pinchRotate: true
        },
        success: function(event) {
            imageDone = true;
        },
    tileSources:   {height: 243848,
width: 106312,
tileSize: 2048,

        overlap: 1,
        getTileUrl: function( level, x, y ){return "<URL>"+ level + "/" + x + "_" + y + ".jpg";
        }
    }
});

I suspect OSD isn't setting source.url because there's no one URL for the source - we get the tiles as we go along.

rsimon commented 1 year ago

Yikes - sorry, I completely missed this issue. Not sure if it's still relevant half a year later. In any case: yes, the source URL isn't really a defined concept in OpenSeadragon. (It does work with IIIF sources and when using a normal image file.) Nonetheless, the Firebase plugin requires a source property to be present, so it can query the Firebase DB for the annotations on that particular image.

The only two workarounds would be to patch the url in the tilehandler, as you did - or hack the Firebase plugin. (I agree that your workaround is the preferable one!)