only center map on files on page load and on file import, closes #36
This commit is contained in:
parent
87e75f967f
commit
f8dea2a7f1
2 changed files with 9 additions and 3 deletions
|
@ -282,7 +282,14 @@ const fileState: Map<string, GPXFile> = new Map(); // Used to generate patches
|
||||||
|
|
||||||
// Observe the file ids in the database, and maintain a map of file observers for the corresponding files
|
// Observe the file ids in the database, and maintain a map of file observers for the corresponding files
|
||||||
export function observeFilesFromDatabase() {
|
export function observeFilesFromDatabase() {
|
||||||
|
let initialize = true;
|
||||||
liveQuery(() => db.fileids.toArray()).subscribe(dbFileIds => {
|
liveQuery(() => db.fileids.toArray()).subscribe(dbFileIds => {
|
||||||
|
if (initialize) {
|
||||||
|
if (dbFileIds.length > 0) {
|
||||||
|
initTargetMapBounds(dbFileIds.length);
|
||||||
|
}
|
||||||
|
initialize = false;
|
||||||
|
}
|
||||||
// Find new files to observe
|
// Find new files to observe
|
||||||
let newFiles = dbFileIds.filter(id => !get(fileObservers).has(id)).sort((a, b) => parseInt(a.split('-')[1]) - parseInt(b.split('-')[1]));
|
let newFiles = dbFileIds.filter(id => !get(fileObservers).has(id)).sort((a, b) => parseInt(a.split('-')[1]) - parseInt(b.split('-')[1]));
|
||||||
// Find deleted files to stop observing
|
// Find deleted files to stop observing
|
||||||
|
@ -291,9 +298,6 @@ export function observeFilesFromDatabase() {
|
||||||
// Update the store
|
// Update the store
|
||||||
if (newFiles.length > 0 || deletedFiles.length > 0) {
|
if (newFiles.length > 0 || deletedFiles.length > 0) {
|
||||||
fileObservers.update($files => {
|
fileObservers.update($files => {
|
||||||
if (newFiles.length > 0 && get(currentTool) !== Tool.SCISSORS) { // Reset the target map bounds when new files are added
|
|
||||||
initTargetMapBounds(newFiles.length);
|
|
||||||
}
|
|
||||||
newFiles.forEach(id => {
|
newFiles.forEach(id => {
|
||||||
$files.set(id, dexieGPXFileStore(id));
|
$files.set(id, dexieGPXFileStore(id));
|
||||||
});
|
});
|
||||||
|
|
|
@ -195,6 +195,8 @@ export async function loadFiles(list: FileList | File[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initTargetMapBounds(list.length);
|
||||||
|
|
||||||
dbUtils.addMultiple(files);
|
dbUtils.addMultiple(files);
|
||||||
|
|
||||||
selectFileWhenLoaded(files[0]._data.id);
|
selectFileWhenLoaded(files[0]._data.id);
|
||||||
|
|
Loading…
Reference in a new issue