Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Annotation to Openseadragon

var viewer = OpenSeadragon({
    id: "openseadragon1",
    prefixUrl: "images/openseadragon/",
    showNavigator:  true,
    navigatorPosition:   "BOTTOM_RIGHT",
    tileSources: '/fcgi-bin/iipsrv.fcgi?Deepzoom=<?=$plink?>.jp2.dzi',
    crossOriginPolicy: 'Anonymous',
    zoomInButton:   "zoom-in",
    zoomOutButton:  "zoom-out",
    homeButton:     "home",
    fullPageButton: "full-page"
});

anno.makeAnnotatable(viewer);

$.ajax({
    url: "handlers/H_AnnotationHandler.php",
    data: "case_id=<?=$case_id?>&plink=<?=$plink?>&mode=get",
    type: "post",
    dataType: "json",
    success: function(response) {
        if (!response.error) {
            for (var i=0; i<response.annots.length; i++) {
                console.log(response.annots[i].comment);
                anno.addAnnotation({
                    text: response.annots[i].comment,
                    shapes: [{
                        type: 'rect',
                        geometry: {
                            x: response.annots[i].rect_x,
                            y: response.annots[i].rect_y,
                            width: response.annots[i].rect_w,
                            height: response.annots[i].rect_h
                        }
                    }]
                });
            }
        } else {
            console.log(response.error);
        }
    }
});

I can add annotation live : http://annotorious.github.io/demos/openseadragon-preview.html

After user added the annotation, I store in my database. When the user refresh the page, I am loading saved datas from database using ajax call (H_AnnotationHandler.php). Returning data is true, but I could not draw annotation on jpeg2000 image using anno.addAnnotation, how can I draw it ?

Reference : Add annotations API.

like image 465
Levent Tulun Avatar asked Jan 15 '16 10:01

Levent Tulun


1 Answers

You are missing src attribute in anno.addAnnotation method, the thing is that I don't really know what value should go there, there is nothing in documentation about that, the only thing I could find in internet is this plugin:

https://github.com/dgutman/OpenSeadragon-Plugins/tree/master/annotationState_Code

You could try that instead.

EDIT

I actually managed to attach event programatically on the demo page, the open sea dragon module there is registered as a dzi://openseadragon/something, knowing this you can invoke the function

anno.addAnnotation({
    src : 'dzi://openseadragon/something',
    text : 'My annotation',
    shapes : [{
        type : 'rect',
        geometry : { x : 0.8, y: 0.8, width : 0.2, height: 0.2 }
    }]
});

from console (or in your code within the ajax-success loop) and it will be added to the image. Yet, the naming method is pretty... well, I found this in the source code:

annotorious.mediatypes.openseadragon.OpenSeadragonModule.prototype.getItemURL = function(item) {
  // TODO implement something decent!
  return 'dzi://openseadragon/something';
}

so be assured that this might change in future.

like image 129
Maciej Kwas Avatar answered Oct 03 '22 10:10

Maciej Kwas