1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

Fixing map bounds for gps tracks only. fixes #718

This commit is contained in:
Patrik J. Braun 2023-10-08 20:32:10 +02:00
parent 7efcaed733
commit 43424526ee

View File

@ -15,12 +15,12 @@ import {
Control,
DivIcon,
divIcon,
featureGroup,
FeatureGroup,
icon,
latLng,
latLngBounds,
LatLngBounds,
LatLngLiteral,
layerGroup,
LayerGroup,
Map,
MapOptions,
Marker,
@ -83,7 +83,7 @@ export class GalleryMapLightboxComponent implements OnChanges, OnDestroy {
private mapLayersControlOption: LeafletControlLayersConfig & {
overlays: {
Photos: MarkerClusterGroup;
[name: string]: LayerGroup;
[name: string]: FeatureGroup;
};
} = {
baseLayers: {},
@ -117,7 +117,7 @@ export class GalleryMapLightboxComponent implements OnChanges, OnDestroy {
// ordered list
private pathLayersConfigOrdered: {
name: string,
layer: LayerGroup,
layer: FeatureGroup,
themes?: {
matchers?: RegExp[],
theme?: { color: string, dashArray: string },
@ -184,7 +184,7 @@ export class GalleryMapLightboxComponent implements OnChanges, OnDestroy {
}
const pl = {
name: nameI18n,
layer: layerGroup([]),
layer: featureGroup([]),
themes: conf.matchers.map(ths => {
return {
matchers: ths.matchers.map(s => new RegExp(s, 'i')),
@ -202,7 +202,7 @@ export class GalleryMapLightboxComponent implements OnChanges, OnDestroy {
});
if (this.pathLayersConfigOrdered.length === 0) {
this.pathLayersConfigOrdered.push({name: $localize`Other paths`, layer: layerGroup([])});
this.pathLayersConfigOrdered.push({name: $localize`Other paths`, layer: featureGroup([])});
}
this.pathLayersConfigOrdered.forEach(pl => {
@ -509,16 +509,22 @@ export class GalleryMapLightboxComponent implements OnChanges, OnDestroy {
}
private centerMap(): void {
if (this.mapLayersControlOption.overlays.Photos.getLayers().length === 0) {
let bounds: LatLngBounds = null;
for (const k of Object.keys(this.mapLayersControlOption.overlays)) {
const b = this.mapLayersControlOption?.overlays?.[k]?.getBounds();
if (!b) {
continue;
}
if (!bounds) {
bounds = b;
continue;
}
bounds.extend(b);
}
if (!bounds) {
return;
}
this.leafletMap.fitBounds(
latLngBounds(
(
this.mapLayersControlOption.overlays.Photos.getLayers() as Marker[]
).map((m) => m.getLatLng())
)
);
this.leafletMap.fitBounds(bounds);
}
private addArchForLongDistancePaths(path: LatLngLiteral[]) {
@ -616,7 +622,7 @@ export class GalleryMapLightboxComponent implements OnChanges, OnDestroy {
const loadAFile = async (file: FileDTO) => {
const parsedGPX = await this.mapService.getMapCoordinates(file);
let pathLayer: { layer: LayerGroup, icon?: DivIcon, theme?: { color?: string, dashArray?: string } };
let pathLayer: { layer: FeatureGroup, icon?: DivIcon, theme?: { color?: string, dashArray?: string } };
for (const pl of this.pathLayersConfigOrdered) {
pathLayer = {layer: pl.layer, icon: MarkerFactory.defIcon};
if (!pl.themes || pl.themes.length === 0) {
@ -686,7 +692,10 @@ export class GalleryMapLightboxComponent implements OnChanges, OnDestroy {
this.leafletMap.addLayer(pl.layer);
}
});
// center map on paths if no photos to center map on
if (!this.photos?.length) {
this.centerMap();
}
}
}