【问题标题】:Add Annotation to Openseadragon为 Openseadragon 添加注解
【发布时间】:2016-01-15 10:07:52
【问题描述】:
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);
        }
    }
});

我可以实时添加注释:http://annotorious.github.io/demos/openseadragon-preview.html

用户添加注释后,我存储在我的数据库中。当用户刷新页面时,我正在使用 ajax 调用 (H_AnnotationHandler.php) 从数据库中加载保存的数据。返回数据是真的,但是我无法使用anno.addAnnotation在jpeg2000图像上绘制注释,我该如何绘制它?

参考:添加注解API

【问题讨论】:

  • 你能创建一个jsFiddle吗?
  • @Gavriel 您在预览页面上几乎有一对一的演示,无需摆弄这个
  • @MaciejKwas,我不这么认为。我可以,就像他在演示页面上写的那样做一个注释,但他的问题是从数据库中检索它并调用 API 再次显示它。我想看到一个“硬编码”字符串,它表示通过 api 调用从数据库中保存的值。
  • @Gavriel 你的浏览器中有一个控制台,我向你保证这就是你所需要的:)) anno.addAnnotation 的问题是它需要 src 参数作为图像而不需要 openseadragon正在考虑的模块。我认为这是脚本设计问题,因为 _modules 数组没有公开,因此您不能直接调用它的方法。
  • 嗨,我可以使用 openseadragon.github.io/examples/ui-overlays 和我的 annotation.js 插件坐标添加矩形。但它们看起来不同(我的意思是css)。而且我的数据库坐标是真的,但是 anno.addAnnotation 对我不起作用...

标签: javascript php jquery openseadragon


【解决方案1】:

您在anno.addAnnotation 方法中缺少src 属性,问题是我真的不知道应该去那里的值,文档中没有关于此的内容,我在互联网上唯一能找到的就是这个插件:

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

你可以试试。

编辑

我实际上设法在演示页面上以编程方式附加事件,那里的海龙模块注册为dzi://openseadragon/something,知道这一点你可以调用该函数

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 }
    }]
});

来自控制台(或在 ajax-success 循环中的代码中),它将被添加到图像中。不过,命名方法还不错……嗯,我在源代码中找到了这个:

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

所以请放心,这在未来可能会改变。

【讨论】:

  • 你看到这个了吗?我认为它不起作用:jsfiddle.net/peLokacs/4
  • 打开有问题的演示页面,打开javascript控制台,粘贴代码并注意注释。就这么容易。为此制作小提琴完全是浪费时间
【解决方案2】:

由于您没有分享您的代码,因此我尝试在此处设置:https://jsfiddle.net/peLokacs/3/,请进行必要的更改,以便我可以看到注释。我还收到“Annotorious 在当前版本或构建配置中不支持此媒体类型”。错误,如果您设法保存了注释,那么您可能也知道如何修复它。

var viewer = OpenSeadragon({
    id: "openseadragon-1",
    prefixUrl: "https://neswork.com/javascript/openseadragon-bin-2.1.0/images/",
    //tileSources: "https://openseadragon.github.io/example-images/highsmith/highsmith.dzi",
    tileSources: { type: 'legacy-image-pyramid', levels: [{ url: '0001q.jpg', height: 889, width:  600 }, { url: '0001r.jpg', height: 2201, width: 1485 }, { url: '0001v.jpg', height: 4402, width: 2970 }]},
    showNavigator: true,
});

【讨论】:

  • 我不相信你是否理解这个问题。从数据库中检索数据没有问题,问题是未记录的方法,您所要做的就是在注释器源代码中找到解决方案。
  • 我明白这一点,但我为什么要浪费时间编写他声称已经实现的代码。为了能够开始测试代码,需要注释。如果他提供可以测试和改进的代码,而不是复制和粘贴需要花费大量精力来解决问题的部分代码,那就更好了。
  • @Gavriel 如果我与您分享我的代码,您将无法打开图像。因为图片大小是1GB,我怎么上传呢?我像你的代码一样使用 openseadragon。
猜你喜欢
  • 1970-01-01
  • 2017-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-07
  • 2013-07-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多