Basic prototype.
This commit is contained in:
parent
a5a8ae1e95
commit
e103c4f777
1 changed files with 49 additions and 4 deletions
|
|
@ -115,7 +115,7 @@ function start(opts) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let addStyle = (id, item, allowMoreData, reportFonts) => {
|
const addStyle = (id, item, allowMoreData, reportFonts) => {
|
||||||
let success = true;
|
let success = true;
|
||||||
if (item.serve_data !== false) {
|
if (item.serve_data !== false) {
|
||||||
success = serve_style.add(options, serving.styles, item, id, opts.publicUrl,
|
success = serve_style.add(options, serving.styles, item, id, opts.publicUrl,
|
||||||
|
|
@ -188,6 +188,12 @@ function start(opts) {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const addData = (id, item) => {
|
||||||
|
startupPromises.push(
|
||||||
|
serve_data.add(options, serving.data, item, id, opts.publicUrl)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
for (const id of Object.keys(data)) {
|
for (const id of Object.keys(data)) {
|
||||||
const item = data[id];
|
const item = data[id];
|
||||||
if (!item.mbtiles || item.mbtiles.length === 0) {
|
if (!item.mbtiles || item.mbtiles.length === 0) {
|
||||||
|
|
@ -195,9 +201,48 @@ function start(opts) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
startupPromises.push(
|
addData(id, item);
|
||||||
serve_data.add(options, serving.data, item, id, opts.publicUrl)
|
}
|
||||||
);
|
|
||||||
|
if (options.serveAllData) {
|
||||||
|
fs.readdir(options.paths.mbtiles, {withFileTypes: true}, (err, files) => {
|
||||||
|
if (err) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (const file of files) {
|
||||||
|
if (file.isFile() &&
|
||||||
|
path.extname(file.name).toLowerCase() == '.mbtiles') {
|
||||||
|
let id = path.basename(file.name, '.mbtiles');
|
||||||
|
let item = {
|
||||||
|
mbtiles: file.name
|
||||||
|
};
|
||||||
|
addData(id, item, false, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const watcher = chokidar.watch(path.join(options.paths.styles, '*.mbtiles'),
|
||||||
|
{
|
||||||
|
});
|
||||||
|
watcher.on('all',
|
||||||
|
(eventType, filename) => {
|
||||||
|
if (filename) {
|
||||||
|
let id = path.basename(filename, '.mbtiles');
|
||||||
|
console.log(`Data "${id}" changed, updating...`);
|
||||||
|
|
||||||
|
serve_style.remove(serving.styles, id);
|
||||||
|
if (serve_rendered) {
|
||||||
|
serve_rendered.remove(serving.rendered, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eventType == "add" || eventType == "change") {
|
||||||
|
let item = {
|
||||||
|
mbtiles: filename
|
||||||
|
};
|
||||||
|
addData(id, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.serveAllStyles) {
|
if (options.serveAllStyles) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue