Edit

Zoomify

Example of a Zoomify source.

Zoomify is a format for deep-zooming into high resolution images. This example shows how to use the Zoomify source with a pixel projection. Internet Imaging Protocol (IIP) with JTL extension is also handled.

index.html<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Zoomify</title>
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
    <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
    <style>
      .map {
        width: 100%;
        height:400px;
      }
    </style>
  </head>
  <body>
    <div id="map" class="map"></div>
    <div class="controls">
      <select id="zoomifyProtocol">
        <option value="zoomify">Zoomify</option>
        <option value="iip">IIP</option>
        <option value="zoomifyretina">Zoomify Retina</option>
      </select>
    </div>
    <script src="index.js"></script>
  </body>
</html>
index.jsimport 'ol/ol.css';
import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import Zoomify from 'ol/source/Zoomify';

var imgWidth = 9911;
var imgHeight = 6100;

var zoomifyUrl = 'http://vips.vtech.fr/cgi-bin/iipsrv.fcgi?zoomify=' +
    '/mnt/MD1/AD00/plan_CHU-4HD-01/FOND.TIF/';
var iipUrl = 'http://vips.vtech.fr/cgi-bin/iipsrv.fcgi?FIF=' + '/mnt/MD1/AD00/plan_CHU-4HD-01/FOND.TIF' + '&JTL={z},{tileIndex}';

var layer = new TileLayer({
  source: new Zoomify({
    tileSize: 256,
    tilePixelRatio: 1,
    url: zoomifyUrl,
    size: [imgWidth, imgHeight],
    crossOrigin: 'anonymous'
  })
});

var extent = [0, -imgHeight, imgWidth, 0];

var resolutions = layer.getSource().getTileGrid().getResolutions();

var map = new Map({
  layers: [layer],
  target: 'map',
  view: new View({
    // adjust zoom levels to those provided by the source
    minResolution: resolutions[resolutions.length - 1],
    maxResolution: resolutions[0],
    // constrain the center: center cannot be set outside this extent
    extent: extent
  })
});
map.getView().fit(extent);

var control = document.getElementById('zoomifyProtocol');
control.addEventListener('change', function(event) {
  var value = event.currentTarget.value;
  if (value === 'iip') {
    var extent = [0, -imgHeight, imgWidth, 0];
    layer.setSource(
      new Zoomify({
        tileSize: 256,
        tilePixelRatio: 1,
        url: iipUrl,
        size: [imgWidth, imgHeight],
        crossOrigin: 'anonymous'
      })
    );
    var resolutions = layer.getSource().getTileGrid().getResolutions();
    map.setView(
      new View({
        // adjust zoom levels to those provided by the source
        minResolution: resolutions[resolutions.length - 1],
        maxResolution: resolutions[0],
        // constrain the center: center cannot be set outside this extent
        extent: extent
      })
    );
    map.getView().fit(extent);
  } else if (value === 'zoomify') {
    var extent$1 = [0, -imgHeight, imgWidth, 0];
    layer.setSource(
      new Zoomify({
        tileSize: 256,
        tilePixelRatio: 1,
        url: zoomifyUrl,
        size: [imgWidth, imgHeight],
        crossOrigin: 'anonymous'
      })
    );
    var resolutions$1 = layer.getSource().getTileGrid().getResolutions();
    map.setView(
      new View({
        // adjust zoom levels to those provided by the source
        minResolution: resolutions$1[resolutions$1.length - 1],
        maxResolution: resolutions$1[0],
        // constrain the center: center cannot be set outside this extent
        extent: extent$1
      })
    );
    map.getView().fit(extent$1);
  } else if (value === 'zoomifyretina') {
    var pixelRatio = 4;
    // Be careful! Image extent will be modified by pixel ratio
    var extent$2 = [0, -imgHeight / pixelRatio, imgWidth / pixelRatio, 0];
    layer.setSource(
      new Zoomify({
        tileSize: 256 / pixelRatio,
        tilePixelRatio: pixelRatio,
        url: zoomifyUrl,
        size: [imgWidth / pixelRatio, imgHeight / pixelRatio],
        crossOrigin: 'anonymous'
      })
    );
    var resolutions$2 = layer.getSource().getTileGrid().getResolutions();
    map.setView(
      new View({
        // adjust zoom levels to those provided by the source
        minResolution: resolutions$2[resolutions$2.length - 1] / pixelRatio,
        maxResolution: resolutions$2[0],
        // constrain the center: center cannot be set outside this extent
        extent: extent$2
      })
    );
    map.getView().fit(extent$2);
  }

});
package.json{
  "name": "zoomify",
  "dependencies": {
    "ol": "6.1.1"
  },
  "devDependencies": {
    "parcel": "1.11.0"
  },
  "scripts": {
    "start": "parcel index.html",
    "build": "parcel build --experimental-scope-hoisting --public-url . index.html"
  }
}