-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtilelive-local.js
56 lines (46 loc) · 1.24 KB
/
tilelive-local.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
54
55
56
var fs = require("fs");
var path = require("path");
var tiletype = require("tiletype");
function Local(uri, callback) {
this.pathname = uri.pathname;
this.hostname = uri.hostname;
callback(null, this);
//return undefined;
}
Local.registerProtocols = function(tilelive) {
tilelive.protocols['local:'] = Local;
};
Local.list = function(filepath, callback) {
var result = {};
filepath = path.resolve(filepath);
fs.readdir(filepath, function(err, files) {
files.forEach(function(file) {
result[file] = "local://" + filepath + "\\" + file;
});
return callback(null, result);
})
}
Local.prototype.getTile = function(z, x, y, callback) {
var filepath = this.hostname + ":" + this.pathname + "/" + z + "/" + x + "/" + y + ".png";
filepath = path.resolve(filepath);
fs.readFile(filepath, function(err, file) {
if (err) {
console.log(err);
return callback(err);
}
return callback(null, file, {
'Content-Type': 'img/png'
});
})
};
Local.prototype.getInfo = function(callback) {
var metapath = this.hostname + ":" + this.pathname + "/meta.json";
metapath = path.resolve(metapath);
try{
var meta = require(metapath);//直接require元数据文件
callback(null, meta);
}catch(e){
callback(e);
}
}
module.exports = Local;