-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathfsi.js
More file actions
66 lines (65 loc) · 2.36 KB
/
Copy pathfsi.js
File metadata and controls
66 lines (65 loc) · 2.36 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
// FSI
var fsi = (function(){
return {
"name" : "FSI",
"description": "FSI Server, by Neptune Labs",
"urls" : [
/server\?.*(?:(?:type=|image=).*?){2}/,
],
"contents" : [
/server\?.*(?:(?:type=|image=).*?){2}/,
/<fsi-viewer/
],
"findFile" : function getInfoFile (baseUrl, callback) {
function try_url (url) {
var fsiMatch = url.match(/server.*[?&]source=([^&]+)/);
if (!fsiMatch) return false;
var info_params = "server?type=info&source=" + fsiMatch[1];
var info_url = url.replace(/server\?.*$/, info_params);
callback(info_url);
return true;
}
if (try_url(baseUrl)) return;
// Inline references
ZoomManager.getFile(baseUrl, {type:"htmltext"}, function (text) {
var url_matches = text.match(/[^\s"']*\/server[^\s"']*/g);
if (url_matches) {
for (var i = 0; i < url_matches.length; i++) {
if (try_url(url_matches[i])) return;
}
}
throw new Error("No FSI URL found.");
});
},
"open" : function (url) {
ZoomManager.getFile(url, {type:"text"}, function (infotxt, xhr) {
var WIDTH_REG = /width\s+value=["']?(\d+)/i;
var HEIGHT_REG = /height\s+value=["']?(\d+)/i;
var returned_data = {
"origin": url.replace(/\/server\?.*/, '/server'),
"source": url.match(/source=([^&]+)/)[1],
"width" : parseInt(infotxt.match(WIDTH_REG)[1]),
"height" : parseInt(infotxt.match(HEIGHT_REG)[1]),
"tileSize" : 512,
};
ZoomManager.readyToRender(returned_data);
});
},
"getTileURL" : function (x, y, zoom, data) {
var coords = [x, y].map(function (position, i) {
var pos = position*data.tileSize;
var size = Math.min(data.tileSize, data[i===0? "width":"height"] - pos);
return {pos:pos, size:size};
});
return data.origin +
"?type=image&source=" + data.source +
"&width=" + coords[0].size +
"&height=" + coords[1].size +
"&rect=" + coords[0].pos / data.width + "," +
+ coords[1].pos / data.height + "," +
+ coords[0].size / data.width + "," +
+ coords[1].size / data.height;
}
};
})();
ZoomManager.addDezoomer(fsi);