如何在 OpenLayers 中打开 Zoomify 磁贴源

How To Open Zoomify tile source in OpenLayers

我尝试从 zoomify 查看器切换到 OpenLayers。 但是,我未能成功加载缩放图像。

这是 URL: https://get.microvisioneer.com/scans/oltest2_Whosebug.html

它从 TileGroup18 成功加载了一个图块 (7-57-24.jpg),但页面上没有任何显示。

我做错了什么?

您需要设置并打开视图

<!doctype html>
<html lang="en">
  <head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.3.1/css/ol.css" type="text/css">
    <style>
      .map {
        height: 400px;
        width: 400px;
      }
    </style>
    <script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.3.1/build/ol.js"></script>
    <title>OpenLayers example</title>
  </head>
  <body>
    <h2>My Map</h2>
    <div id="map" class="map"></div>
    <script type="text/javascript">
 var imgWidth = 29184;
 var imgHeight = 12288;
 
 var zoomifyUrl = 'https://get.microvisioneer.com/scans/US20-589.svs.zoomify/';
 
 var source = new ol.source.Zoomify({
   url: zoomifyUrl,
   size: [imgWidth, imgHeight],
   zDirection: -1 // Ensure we get a tile with the screen resolution or higher
 });

      var map = new ol.Map({
        target: 'map',
        layers: [
          new ol.layer.Tile({
            source: source
          })
        ],
        view: new ol.View({
          // adjust zoom levels to those provided by the source
          resolutions: source.getTileGrid().getResolutions(),
          // constrain the center: center cannot be set outside this extent
          extent: source.getTileGrid().getExtent(),
          constrainOnlyCenter: true
        })
      });
      map.getView().fit(source.getTileGrid().getExtent());
    </script>
  </body>
</html>