improve bounds logic
This commit is contained in:
parent
e389e219b2
commit
d09d2ced04
2 changed files with 7 additions and 6 deletions
|
@ -44,7 +44,7 @@
|
||||||
let newMap = new mapboxgl.Map({
|
let newMap = new mapboxgl.Map({
|
||||||
container: 'map',
|
container: 'map',
|
||||||
style: { version: 8, sources: {}, layers: [] },
|
style: { version: 8, sources: {}, layers: [] },
|
||||||
projection: { name: 'mercator' },
|
zoom: 0,
|
||||||
hash: hash,
|
hash: hash,
|
||||||
language: get(locale),
|
language: get(locale),
|
||||||
attributionControl: false,
|
attributionControl: false,
|
||||||
|
|
|
@ -68,16 +68,17 @@ gpxStatistics.subscribe(() => {
|
||||||
|
|
||||||
const targetMapBounds = writable({
|
const targetMapBounds = writable({
|
||||||
bounds: new mapboxgl.LngLatBounds([180, 90, -180, -90]),
|
bounds: new mapboxgl.LngLatBounds([180, 90, -180, -90]),
|
||||||
initial: true
|
count: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
targetMapBounds.subscribe((bounds) => {
|
targetMapBounds.subscribe((bounds) => {
|
||||||
if (bounds.initial) {
|
if (bounds.count === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let currentBounds = get(map)?.getBounds();
|
let currentBounds = get(map)?.getBounds();
|
||||||
if (currentBounds && currentBounds.contains(bounds.bounds.getSouthEast()) && currentBounds.contains(bounds.bounds.getNorthWest())) {
|
if (bounds.count !== get(fileObservers).size &&
|
||||||
|
currentBounds && currentBounds.contains(bounds.bounds.getSouthEast()) && currentBounds.contains(bounds.bounds.getNorthWest())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +103,7 @@ export function initTargetMapBounds(first: boolean) {
|
||||||
}
|
}
|
||||||
targetMapBounds.set({
|
targetMapBounds.set({
|
||||||
bounds: bounds,
|
bounds: bounds,
|
||||||
initial: true
|
count: 0
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +118,7 @@ export function updateTargetMapBounds(bounds: {
|
||||||
targetMapBounds.update((target) => {
|
targetMapBounds.update((target) => {
|
||||||
target.bounds.extend(bounds.southWest);
|
target.bounds.extend(bounds.southWest);
|
||||||
target.bounds.extend(bounds.northEast);
|
target.bounds.extend(bounds.northEast);
|
||||||
target.initial = false;
|
target.count += 1;
|
||||||
return target;
|
return target;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue