javascript - 添加/定位独立覆盖到 openseadragon 图像和相关错误消息

标签 javascript html css openseadragon

我正在关注 Basic Single-Row Tile Source Collection具有与示例中提到的相同配置和图 block 源的示例。

我现在正尝试在第一张和第二张图片上添加叠加层,但遇到了麻烦。

第一个叠加层应该放在第一个图像的顶部,第二个叠加层应该放在第二个图像上,但它不是那样发生的..

我正在将 overlays 集合添加到 tileSources 集合。

叠加对于不同的页面不是独立的吗?

此外,我在添加叠加层后在控制台中收到以下错误,我不明白如何在插件的这种基本初始化中使用 TiledImage.imageToViewportRectangle。

[Viewport.imageToViewportRectangle] is not accurate with multi-image; use TiledImage.imageToViewportRectangle instead

.

Codepen 示例网址:https://codepen.io/hussainb/pen/QQPPvL

Codepen 代码:

html:

<div id="overlays">
    <div id="overlay1">Overlay One</div>
    <div id="overlay2">Overlay Two</div>
</div>

<div id="viewer"></div>

CSS:

    body {
        margin:0;
        padding:0;
    }
    #viewer {
        width:100%;
        height: 600px;
        margin: auto;
        background-color: lightgray;
    }
    #overlay1, #overlay2 {
        width: 100px;
        height: 100px;
        background-color:powderblue;
    }

Javascript:

$( document ).ready(function(){

        var viewer = OpenSeadragon({
            id: "viewer",
            prefixUrl: "https://cdnjs.cloudflare.com/ajax/libs/openseadragon/2.3.1/images/",
            debugMode: false, //if you want to see the render grid

            collectionMode: true,
            collectionRows: 1,
            collectionTileSize: 1024,
            collectionTileMargin: 256,

            tileSources: [
                {
                    Image: {
                        xmlns: "http://schemas.microsoft.com/deepzoom/2008",
                        Url: "https://openseadragon.github.io/example-images/highsmith/highsmith_files/",
                        Format: "jpg",
                        Overlap: "2",
                        TileSize: "256",
                        Size: {
                            Height: "9221",
                            Width: "7026"
                        }
                    }
                    ,
                    overlays: [{
                        id: 'overlay1',
                        px: 100,
                        py: 0,
                        width: 200,
                        height: 200,
                        className: 'filter'
                    }]
                },
                {
                    Image: {
                        xmlns: "http://schemas.microsoft.com/deepzoom/2008",
                        Url: "https://openseadragon.github.io/example-images/highsmith/highsmith_files/",
                        Format: "jpg",
                        Overlap: "2",
                        TileSize: "256",
                        Size: {
                            Height: "9221",
                            Width: "7026"
                        }
                    },
                    overlays: [{
                        id: 'overlay2',
                        px: 100,
                        py: 0,
                        width: 500,
                        height: 500,
                        className: 'filter'
                    }]
                },
                {
                    Image: {
                        xmlns: "http://schemas.microsoft.com/deepzoom/2008",
                        Url: "https://openseadragon.github.io/example-images/highsmith/highsmith_files/",
                        Format: "jpg",
                        Overlap: "2",
                        TileSize: "256",
                        Size: {
                            Height: "9221",
                            Width: "7026"
                        }
                    }
                },
                {
                    Image: {
                        xmlns: "http://schemas.microsoft.com/deepzoom/2008",
                        Url: "https://openseadragon.github.io/example-images/highsmith/highsmith_files/",
                        Format: "jpg",
                        Overlap: "2",
                        TileSize: "256",
                        Size: {
                            Height: "9221",
                            Width: "7026"
                        }
                    }
                },
                {
                    Image: {
                        xmlns: "http://schemas.microsoft.com/deepzoom/2008",
                        Url: "https://openseadragon.github.io/example-images/highsmith/highsmith_files/",
                        Format: "jpg",
                        Overlap: "2",
                        TileSize: "256",
                        Size: {
                            Height: "9221",
                            Width: "7026"
                        }
                    }
                },
                {
                    Image: {
                        xmlns: "http://schemas.microsoft.com/deepzoom/2008",
                        Url: "https://openseadragon.github.io/example-images/highsmith/highsmith_files/",
                        Format: "jpg",
                        Overlap: "2",
                        TileSize: "256",
                        Size: {
                            Height: "9221",
                            Width: "7026"
                        }
                    }
                }
            ]
        });


})

最佳答案

看起来这是 OpenSeadragon 的一个错误!这是问题单:

https://github.com/openseadragon/openseadragon/issues/1412

您可以通过单独存储叠加层并在图像打开后添加它们来解决这个问题,就像这样(假设您已经创建了一个查看器):

var overlaySets = [
  [{
    id: 'overlay1',
    px: 100,
    py: 0,
    width: 200,
    height: 200,
    className: 'filter'
  }],
  [{
    id: 'overlay2',
    px: 100,
    py: 0,
    width: 500,
    height: 500,
    className: 'filter'
  }]
];

viewer.addHandler('open', function() {
  overlaySets.forEach(function(overlaySet, setIndex) {
    var tiledImage = viewer.world.getItemAt(setIndex);
    if (!overlaySet || !tiledImage) {
      return;
    }

    overlaySet.forEach(function(overlay) {
      var rect = new OpenSeadragon.Rect(overlay.px, overlay.py, overlay.width, overlay.height);
      rect = tiledImage.imageToViewportRectangle(rect);
      overlay.x = rect.x;
      overlay.y = rect.y;
      overlay.width = rect.width;
      overlay.height = rect.height;
      delete overlay.px;
      delete overlay.py;
      viewer.addOverlay(overlay);
    });
  });
});

你可以在这里看到这个:

https://codepen.io/iangilman/pen/aqgzJZ

关于javascript - 添加/定位独立覆盖到 openseadragon 图像和相关错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49096137/

相关文章:

javascript - ons-modal 中的自动换行

html - 什么是 HTML 中的表单控件?

javascript - Handlebars.js - 使用变量键访问对象值

javascript - 测试 Redux Thunk Action Creator

html - <Span> 不是 block 文本

html - 为部分创建响应图像

javascript - 如何在Jquery多选中限制所选元素的空间

html - 四列表格布局与CSS

使用正则表达式的 Javascript 密码验证

javascript - 在 Javascript 日期中使用 UTC 时区