mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-08-31 23:53:25 +00:00
improve bounds logic
This commit is contained in:
@@ -44,7 +44,7 @@
|
||||
let newMap = new mapboxgl.Map({
|
||||
container: 'map',
|
||||
style: { version: 8, sources: {}, layers: [] },
|
||||
projection: { name: 'mercator' },
|
||||
zoom: 0,
|
||||
hash: hash,
|
||||
language: get(locale),
|
||||
attributionControl: false,
|
||||
|
@@ -68,16 +68,17 @@ gpxStatistics.subscribe(() => {
|
||||
|
||||
const targetMapBounds = writable({
|
||||
bounds: new mapboxgl.LngLatBounds([180, 90, -180, -90]),
|
||||
initial: true
|
||||
count: 0
|
||||
});
|
||||
|
||||
targetMapBounds.subscribe((bounds) => {
|
||||
if (bounds.initial) {
|
||||
if (bounds.count === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -102,7 +103,7 @@ export function initTargetMapBounds(first: boolean) {
|
||||
}
|
||||
targetMapBounds.set({
|
||||
bounds: bounds,
|
||||
initial: true
|
||||
count: 0
|
||||
});
|
||||
}
|
||||
|
||||
@@ -117,7 +118,7 @@ export function updateTargetMapBounds(bounds: {
|
||||
targetMapBounds.update((target) => {
|
||||
target.bounds.extend(bounds.southWest);
|
||||
target.bounds.extend(bounds.northEast);
|
||||
target.initial = false;
|
||||
target.count += 1;
|
||||
return target;
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user