Skip to content

Zoomify ​

Zoomify示例。 zoomify deepzoom IIP pixel 投影

Zoomify 是一种可对高分辨率图像进行深度缩放的格式。本示例演示如何在像素投影(pixel projection)下使用 Zoomify 数据源,同时也支持带 JTL 扩展的互联网图像协议(IIP)。

main.js
js
import Map from 'ol/Map.js';
import View from 'ol/View.js';
import TileLayer from 'ol/layer/Tile.js';
import Zoomify from 'ol/source/Zoomify.js';

const imgWidth = 4000;
const imgHeight = 3000;

const zoomifyUrl = 'https://ol-zoomify.surge.sh/zoomify/';

const source = new Zoomify({
  url: zoomifyUrl,
  size: [imgWidth, imgHeight],
  crossOrigin: 'anonymous',
  zDirection: -1, // 确保我们获得与屏幕分辨率相同或更高的瓦片
});
const extent = source.getTileGrid().getExtent();

const retinaPixelRatio = 2;
const retinaSource = new Zoomify({
  url: zoomifyUrl,
  size: [imgWidth, imgHeight],
  crossOrigin: 'anonymous',
  zDirection: -1, // 确保我们获得与屏幕分辨率相同或更高的瓦片
  tilePixelRatio: retinaPixelRatio, // 显示 retina 瓦片
  tileSize: 256 / retinaPixelRatio, // 来自更高的缩放级别
});

const layer = new TileLayer({
  source: source,
});

const map = new Map({
  layers: [layer],
  target: 'map',
  view: new View({
    // 将缩放级别调整为数据源提供的级别
    resolutions: layer.getSource().getTileGrid().getResolutions(),
    // 约束中心点:中心不能设置在此范围之外
    extent: extent,
    constrainOnlyCenter: true,
  }),
});
map.getView().fit(extent);

const control = document.getElementById('zoomifyProtocol');
control.addEventListener('change', function (event) {
  const value = event.currentTarget.value;
  if (value === 'zoomify') {
    layer.setSource(source);
  } else if (value === 'zoomifyretina') {
    layer.setSource(retinaSource);
  }
});
index.html
html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Zoomify</title>
    <link rel="stylesheet" href="node_modules/ol/ol.css">
    <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="zoomifyretina">Zoomify Retina</option>
      </select>
    </div>

    <script type="module" src="main.js"></script>
  </body>
</html>
package.json
json
{
  "name": "zoomify",
  "dependencies": {
    "ol": "10.11.0"
  },
  "devDependencies": {
    "vite": "^8.1.5"
  },
  "scripts": {
    "start": "vite",
    "build": "vite build"
  }
}