mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-09-02 16:52:31 +00:00
improve bounds logic
This commit is contained in:
@@ -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;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user