forked from lovasoa/dezoomify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seadragon.js
53 lines (49 loc) · 1.58 KB
/
seadragon.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var seadragon = (function () { //Code isolation
return {
"name" : "Seadragon (Deep Zoom Image)",
"findFile" : function getDZIFile (baseUrl, callback) {
if (baseUrl.match(/\.xml|\.dzi/i)) {
return callback(baseUrl);
}
ZoomManager.getFile(baseUrl, "text", function (text, xhr) {
// Any url ending with .xml or .dzi
var matchPath = text.match(
/[\w\/]+\.(?:(?:xml)|(?:dzi))/i
);
if (matchPath) {
return callback(matchPath[0]);
}
return callback(baseUrl);
});
},
"open" : function (url) {
ZoomManager.getFile(url, "xml", function (xml, xhr) {
var infos = xml.getElementsByTagName("Image")[0];
if (!infos) {
ZoomManager.error();
console.log(xml);
}
var size = xml.getElementsByTagName("Size")[0];
var data = {};
//replace extension by _files
data.origin = url.replace(/\.[^.\/]*$/,'') + "_files/";
data.tileSize = parseInt(infos.getAttribute("TileSize"));
data.overlap = parseInt(infos.getAttribute("Overlap"));
data.format = infos.getAttribute("Format");
data.width = parseInt(size.getAttribute("Width"));
data.height = parseInt(size.getAttribute("Height"));
//Zooming factor between two consecutive zoom levels
data.zoomFactor = 2;
// 2^maxzoom = max(w,h) (the first tile is 1x1)
data.maxZoomLevel = Math.ceil(
Math.log2(Math.max(data.width, data.height))
);
ZoomManager.readyToRender(data);
});
},
"getTileURL" : function (col, row, zoom, data) {
return zoom + "/" + col + "_" + row + "." + data.format;
}
};
})();
ZoomManager.addDezoomer(seadragon);