-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathzoomify.js
More file actions
149 lines (139 loc) · 5.74 KB
/
Copy pathzoomify.js
File metadata and controls
149 lines (139 loc) · 5.74 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
var zoomify = (function () { //Code isolation
return {
"name": "Zoomify",
"description": "Most commmon zoomable image format",
"urls": [
/ImageProperties\.xml(\?.*)?$/,
/\/TileGroup\d+\/\d+-\d+-\d+.jpg$/,
/biblio\.unibe\.ch\/web-apps\/maps\/zoomify\.php/,
/bspe-p-pub\.paris\.fr\/MDBGED\/zoomify-BFS\.aspx/,
/ngv\.vic\.gov\.au\/explore\/collection\/work/,
/artandarchitecture\.org\.uk\/images\/zoom/
],
"contents": [
/zoomifyImagePath=/,
/showImage\(/,
/accessnumber=/,
/ete-openlayers-src/,
/type['"]?\s*:\s*['"]zoomifytileservice/
],
"findFile": function getZoomifyPath(baseUrl, callback) {
if (baseUrl.match(/ImageProperties\.xml(\?.*)?$/)) {
return callback(baseUrl);
}
function foundZoomifyPath(zoomifyPath) {
var sep = zoomifyPath[zoomifyPath.length - 1] == '/' ? '' : '/';
return callback(zoomifyPath + sep + "ImageProperties.xml");
}
var tileUrlMatch = baseUrl.match(/.*(?=\/TileGroup\d+\/\d+-\d+-\d+.jpg$)/);
if (tileUrlMatch) return foundZoomifyPath(tileUrlMatch[0]);
ZoomManager.getFile(baseUrl, { type: "htmltext" }, function (text, xhr) {
var pageBaseUrl = baseUrl;
var baseMatch = text.match(/<base\s+[^>]*href\s*=\s*["']([^"']*)/i);
if (baseMatch) pageBaseUrl = ZoomManager.resolveRelative(baseMatch[1], baseUrl);
// for the zoomify flash player, the path is in the zoomifyImagePath
// attribute of a tag
// In the HTML5 zoomify player, the path is the second argument
// to a JS function called showImage
var zRegs = [
/zoomifyImagePath=([^\'"&]*)[\'"&]|showImage\([^),]*,\s*["']([^'"]*)/g,
/type['"]?\s*:\s*['"]zoomifytileservice[\s\S]*tilesUrl["']?\s*:\s*["']([^'"]+)/g
]
var matchPath;
var foundPaths = [];
for (var z = 0; z < zRegs.length; z++) {
while ((matchPath = zRegs[z].exec(text)) != null) {
for (var i = 1; i < matchPath.length; i++) {
var path = matchPath[i];
var resolvedPath = path && ZoomManager.resolveRelative(path, pageBaseUrl);
if (resolvedPath && foundPaths.indexOf(resolvedPath) === -1) {
foundPaths.push(resolvedPath);
}
}
}
}
if (foundPaths.length > 0) return foundZoomifyPath(foundPaths[0]);
// Fluid engage zoomify
var fluidMatch = text.match(/accessnumber=([^"&\s']+)/i);
if (fluidMatch) {
var xmlBrokerPath = "/scripts/XMLBroker.new.php" +
"?Lang=2&contentType=IMAGES&contentID=" +
fluidMatch[1];
var url = ZoomManager.resolveRelative(xmlBrokerPath, baseUrl);
return ZoomManager.getFile(url, { type: "xml" }, function (xml, xhr) {
var pathElem = xml.querySelector("imagefile[format=zoomify]");
return foundZoomifyPath(pathElem.firstChild.nodeValue);
});
}
// Universitätsbibliothek
var unibeMatch = text.match(/url = '([^']*)'/);
if (~baseUrl.indexOf("biblio.unibe.ch/web-apps/maps/zoomify.php") &&
unibeMatch) {
var url = ZoomManager.resolveRelative(unibeMatch[1], baseUrl);
return foundZoomifyPath(url);
}
// Openlayers
var olMatch = text.match(/<[^>]*class="ete-openlayers-src"[^>]*>(.*?)<\/.*>/);
if (olMatch) {
return foundZoomifyPath(olMatch[1]);
}
// National Gallery of Victoria (NGV)
var ngvMatch = text.match(/var url = '(.*?)'/);
if (~baseUrl.indexOf("ngv.vic.gov.au") && ngvMatch) {
return foundZoomifyPath(ngvMatch[1]);
}
// If nothing was found, but the page contains an iframe, follow the iframe
var iframeMatch = text.match(/<iframe[^>]*src=["']([^"']*)/);
if (iframeMatch) {
var url = ZoomManager.resolveRelative(iframeMatch[1], baseUrl);
return getZoomifyPath(url, callback);
}
var eteMatch = text.match(/<url>(.*)<\/url>/);
if (eteMatch) {
return foundZoomifyPath(eteMatch[1]);
}
// If no zoomify path was found in the page, then assume that
// the url that was given is the path itself
return foundZoomifyPath(baseUrl);
});
},
"open": function (url) {
ZoomManager.getFile(url, { type: "xml" }, function (xml, xhr) {
var infos = xml.getElementsByTagName("IMAGE_PROPERTIES")[0];
if (!infos) return ZoomManager.error("Invalid zoomify XML info file: " + url);
var data = {};
data.origin = url;
data.width = parseInt(infos.getAttribute("WIDTH"));
data.height = parseInt(infos.getAttribute("HEIGHT"));
data.tileSize = parseInt(infos.getAttribute("TILESIZE"));
data.numTiles = parseInt(infos.getAttribute("NUMTILES")); //Total number of tiles (for all zoom levels)
data.zoomFactor = 2; //Zooming factor between two consecutive zoom levels
var w = data.width, h = data.height,
ntiles = 0,
maxZoom = ZoomManager.findMaxZoom(data);
var fullResolutionTiles = Math.ceil(w / data.tileSize) * Math.ceil(h / data.tileSize);
data.numTilesIsFullResolutionOnly = data.numTiles === fullResolutionTiles;
for (var z = 0; z <= maxZoom; z++) {
ntiles += Math.ceil(w / data.tileSize) * Math.ceil(h / data.tileSize);
w /= 2; h /= 2;
}
if (ntiles !== data.numTiles) {
// The computed zoom level was incorrect.
// When zoomify generates the zoom levels, it MAY stop creating new zoom
// levels when a zoomlevel has one of its dimensions that rounds down to TILESIZE.
var size = Math.max(data.width, data.height);
data.maxZoomLevel = Math.ceil(Math.log(size / (data.tileSize + 1)) / Math.LN2);
}
ZoomManager.readyToRender(data);
});
},
"getTileURL": function (col, row, zoom, data) {
var totalTiles = data.nbrTilesX * data.nbrTilesY;
var tileGroup = data.numTilesIsFullResolutionOnly
? 0
: Math.floor((data.numTiles - totalTiles + col + row * data.nbrTilesX) / 256);
return "TileGroup" + tileGroup + "/" + zoom + "-" + col + "-" + row + ".jpg";
}
};
})();
ZoomManager.addDezoomer(zoomify);