How To Open Zoomify tile source in OpenLayers

295 views Asked by At

I try to switch from zoomify viewer to OpenLayers. However, I did not manage to successfully load a zoomify image.

Here is the URL: https://get.microvisioneer.com/scans/oltest2_stackoverflow.html

It loads one tile (7-57-24.jpg) from TileGroup18 successfully but nothing is displayed on the page.

What am I doing wrong?

1

There are 1 answers

0
Mike On BEST ANSWER

You need to set up and open the view

<!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>