1

我想在 vue.js(vue 3)模板中使用 annotorious(带有 openseadragon 插件)。我已经用 npm 安装了 annotorious。这是我到目前为止所得到的:

    <template>
        <div class="flex-grow">
            <img ref="tag_img" width="100%" :id="img_id" src='../../assets/images/apple.png'>
        </div>
    </template>
    
    <script>
    import * as Annotorious from '@recogito/annotorious-openseadragon'
    import '@recogito/annotorious-openseadragon/dist/annotorious.min.css'
    
    export default {
      props: {
        img_id: String
      },
      mounted: function () {
        var anno = Annotorious({
          image: this.$refs.tag_img
        }, {})
        anno.setDrawingTool('polygon')
      }
    }
    </script>

我在浏览器中收到以下错误:

    [Vue warn]: Error in mounted hook: "TypeError: Cannot read property 'style' of undefined"

found in

---> <AnnotoriousImage> at src/components/interaction/AnnotoriousImage.vue
       <Tagging> at src/components/pages/Tagging.vue
         <App> at src/App.vue
           <Root>
warn @ vue.esm.js?efeb:628
logError @ vue.esm.js?efeb:1893
...
vue.esm.js?efeb:1897 TypeError: Cannot read property 'style' of undefined
4

2 回答 2

0

我相信您正在混淆 Annotorious 的标准版本(用于图像)和 OpenSeadragon 插件(用于高分辨率图像,显示在 OpenSeadragon 查看器中)。

您正在import学习的是 OpenSeadragon 版本。但是您初始化的方式是用于 Annotorious 标准版本的方式。

假设您要注释普通图像:init 是正确的。但你需要

 import * as Annotorious from '@recogito/annotorious'
于 2021-04-30T18:56:08.640 回答
0

Rainer 的回答将我带到了一个工作版本。可以在 annotorious 的 mount 函数中初始化它。

    import OpenSeadragon from 'openseadragon'
    import * as Annotorious from '@recogito/annotorious-openseadragon'
    import '@recogito/annotorious-openseadragon/dist/annotorious.min.css'

export default {
      props: {
        img_url: String,
        default: '../../../assets/images/apple.png'
      },
      mounted: function () {
        const viewer = OpenSeadragon({
          id: 'annotorious_container',
          minZoomImageRatio: 0,
          maxZoomPixelRatio: Infinity,
          tileSources: {
            type: 'image',
            url: require('../../../assets/images/apple.png'),
            ajaxWithCredentials: false,
            fitBounds: true
          }
        })
    
        var options = {
          disableEditor: true // the default editor is disabled to implement a custom behaviour
        }
        var anno = Annotorious(viewer, options)
        anno.setDrawingTool('polygon')
        
        window.viewer = viewer
        window.anno = anno
      },
      components: {
        'Icon': Icon,
        'AnnotoriusEditorPopup': AnnotoriusEditorPopup


         }
}
    
于 2021-05-03T12:57:21.767 回答