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