mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-12-02 18:12:11 +00:00
bounds management
This commit is contained in:
@@ -14,9 +14,11 @@ export class GPXLayerCollection {
|
||||
return;
|
||||
}
|
||||
this._fileStateCollectionObserver = new GPXFileStateCollectionObserver(
|
||||
(fileId, fileState) => {
|
||||
const layer = new GPXLayer(fileId, fileState);
|
||||
this._layers.set(fileId, layer);
|
||||
(newFiles) => {
|
||||
newFiles.forEach((fileState, fileId) => {
|
||||
const layer = new GPXLayer(fileId, fileState);
|
||||
this._layers.set(fileId, layer);
|
||||
});
|
||||
},
|
||||
(fileId) => {
|
||||
const layer = this._layers.get(fileId);
|
||||
|
||||
@@ -221,105 +221,3 @@ export class MapboxGLMap {
|
||||
}
|
||||
|
||||
export const map = new MapboxGLMap();
|
||||
|
||||
// const targetMapBounds: {
|
||||
// bounds: mapboxgl.LngLatBounds;
|
||||
// ids: string[];
|
||||
// total: number;
|
||||
// } = $state({
|
||||
// bounds: new mapboxgl.LngLatBounds([180, 90, -180, -90]),
|
||||
// ids: [],
|
||||
// total: 0,
|
||||
// });
|
||||
|
||||
// $effect(() => {
|
||||
// if (
|
||||
// map.current === null ||
|
||||
// targetMapBounds.ids.length > 0 ||
|
||||
// (targetMapBounds.bounds.getSouth() === 90 &&
|
||||
// targetMapBounds.bounds.getWest() === 180 &&
|
||||
// targetMapBounds.bounds.getNorth() === -90 &&
|
||||
// targetMapBounds.bounds.getEast() === -180)
|
||||
// ) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// let currentZoom = map.current.getZoom();
|
||||
// let currentBounds = map.current.getBounds();
|
||||
// if (
|
||||
// targetMapBounds.total !== get(fileObservers).size &&
|
||||
// currentBounds &&
|
||||
// currentZoom > 2 // Extend current bounds only if the map is zoomed in
|
||||
// ) {
|
||||
// // There are other files on the map
|
||||
// if (
|
||||
// currentBounds.contains(targetMapBounds.bounds.getSouthEast()) &&
|
||||
// currentBounds.contains(targetMapBounds.bounds.getNorthWest())
|
||||
// ) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// targetMapBounds.bounds.extend(currentBounds.getSouthWest());
|
||||
// targetMapBounds.bounds.extend(currentBounds.getNorthEast());
|
||||
// }
|
||||
|
||||
// map.current.fitBounds(targetMapBounds.bounds, { padding: 80, linear: true, easing: () => 1 });
|
||||
// });
|
||||
|
||||
// export function initTargetMapBounds(ids: string[]) {
|
||||
// targetMapBounds.bounds = new mapboxgl.LngLatBounds([180, 90, -180, -90]);
|
||||
// targetMapBounds.ids = ids;
|
||||
// targetMapBounds.total = ids.length;
|
||||
// }
|
||||
|
||||
// export function updateTargetMapBounds(
|
||||
// id: string,
|
||||
// bounds: { southWest: Coordinates; northEast: Coordinates }
|
||||
// ) {
|
||||
// if (targetMapBounds.ids.indexOf(id) === -1) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// if (
|
||||
// bounds.southWest.lat !== 90 ||
|
||||
// bounds.southWest.lon !== 180 ||
|
||||
// bounds.northEast.lat !== -90 ||
|
||||
// bounds.northEast.lon !== -180
|
||||
// ) {
|
||||
// // Avoid update for empty (new) files
|
||||
// targetMapBounds.ids = targetMapBounds.ids.filter((x) => x !== id);
|
||||
// targetMapBounds.bounds.extend(bounds.southWest);
|
||||
// targetMapBounds.bounds.extend(bounds.northEast);
|
||||
// }
|
||||
// }
|
||||
|
||||
// export function centerMapOnSelection() {
|
||||
// let selected = get(selection).getSelected();
|
||||
// let bounds = new mapboxgl.LngLatBounds();
|
||||
|
||||
// if (selected.find((item) => item instanceof ListWaypointItem)) {
|
||||
// applyToOrderedSelectedItemsFromFile((fileId, level, items) => {
|
||||
// let file = getFile(fileId);
|
||||
// if (file) {
|
||||
// items.forEach((item) => {
|
||||
// if (item instanceof ListWaypointItem) {
|
||||
// let waypoint = file.wpt[item.getWaypointIndex()];
|
||||
// if (waypoint) {
|
||||
// bounds.extend([waypoint.getLongitude(), waypoint.getLatitude()]);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// } else {
|
||||
// let selectionBounds = get(gpxStatistics).global.bounds;
|
||||
// bounds.setNorthEast(selectionBounds.northEast);
|
||||
// bounds.setSouthWest(selectionBounds.southWest);
|
||||
// }
|
||||
|
||||
// get(map)?.fitBounds(bounds, {
|
||||
// padding: 80,
|
||||
// easing: () => 1,
|
||||
// maxZoom: 15,
|
||||
// });
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user