How do I deepzoom into OpenLayers images using Zoomify?
Taking cues from the answer How to display high resolution image in browser using openlayers, I was able to implement the zooming function but the maxZoom does not work here and I am unable zoom further into the image.
DZI image parser
function loadUrl(url, opt_options) {
const options = opt_options || {};
const crossOrigin =
options.crossOrigin === undefined ? 'anonymous' : options.crossOrigin;
const layer = new ol.layer.Tile();
const last = url.lastIndexOf('.');
const path = url.slice(0, last);
const xhr = new XMLHttpRequest();
let width;
let height;
xhr.open('GET', url);
xhr.onload = function() {
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(xhr.responseText, 'text/xml');
const elements = xmlDoc.getElementsByTagName('Image');
const tileSize = Number(elements[0].getAttribute('TileSize'));
const format = elements[0].getAttribute('Format');
width = Number(
elements[0].getElementsByTagName('Size')[0].getAttribute('Width')
);
height = Number(
elements[0].getElementsByTagName('Size')[0].getAttribute('Height')
);
const url = `${path}_files/{z}/{x}_{y}.${format}`;
const source = new ol.source.Zoomify({
url,
size: [width, height],
tileSize,
crossOrigin
});
const offset = Math.ceil(Math.log(tileSize) / Math.LN2);
source.setTileUrlFunction(function(tileCoord) {
return url
.replace('{z}', tileCoord[0] + offset)
.replace('{x}', tileCoord[1])
.replace('{y}', -(tileCoord[2] + 1));
});
layer.setExtent([0, -height, width, 0]);
layer.setSource(source);
};
xhr.send();
return {
layer,
width,
height
};
}
Map Object
const map = new ol.Map({
target: 'map',
logo: false
});
const { layer } = loadUrl(
'https://openseadragon.github.io/example-images/duomo/duomo.dzi'
);
layer.on('change:source', function(evt) {
map.setView(
new ol.View({
resolutions: layer.getSource().getTileGrid().getResolutions(),
extent: layer.getExtent(),
zoom: 5,
maxZoom: 30
})
);
map.getView().fit(layer.getExtent(), { size: map.getSize() });
});
map.addLayer(layer);
How do I remove the zoom constraints?
I have figured it out.
Code for the same: