1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/frontend/app/gallery/map/map.gallery.component.ts
2018-12-07 22:06:13 +01:00

72 lines
2.2 KiB
TypeScript

import {Component, ElementRef, Input, OnChanges, ViewChild, AfterViewInit} from '@angular/core';
import {PhotoDTO} from '../../../../common/entities/PhotoDTO';
import {Dimension, IRenderable} from '../../model/IRenderable';
import {GalleryMapLightboxComponent} from './lightbox/lightbox.map.gallery.component';
import {FileDTO} from '../../../../common/entities/FileDTO';
import {MapService} from './map.service';
import {MapComponent} from '@yaga/leaflet-ng2';
@Component({
selector: 'app-gallery-map',
templateUrl: './map.gallery.component.html',
styleUrls: ['./map.gallery.component.css']
})
export class GalleryMapComponent implements OnChanges, IRenderable, AfterViewInit {
@Input() photos: PhotoDTO[];
@Input() metaFiles: FileDTO[];
@ViewChild(GalleryMapLightboxComponent) mapLightbox: GalleryMapLightboxComponent;
mapPhotos: Array<{ lat: number, lng: number }> = [];
@ViewChild('map') mapElement: ElementRef;
@ViewChild('yagaMap') yagaMap: MapComponent;
height: number = null;
constructor(public mapService: MapService) {
}
ngOnChanges() {
this.mapPhotos = this.photos.filter(p => {
return p.metadata && p.metadata.positionData && p.metadata.positionData.GPSData &&
p.metadata.positionData.GPSData.latitude && p.metadata.positionData.GPSData.longitude;
}).map(p => {
return {
lat: p.metadata.positionData.GPSData.latitude,
lng: p.metadata.positionData.GPSData.longitude
};
});
if (this.yagaMap) {
this.yagaMap.setView(this.mapPhotos[0], 0);
this.yagaMap.fitBounds(<any>this.mapPhotos);
this.yagaMap.zoom = 0;
}
}
ngAfterViewInit() {
setTimeout(() => {
this.height = this.mapElement.nativeElement.clientHeight;
this.yagaMap.setView(this.mapPhotos[0], 0);
this.yagaMap.fitBounds(<any>this.mapPhotos);
this.yagaMap.zoom = 0;
}, 0);
}
click() {
this.mapLightbox.show(this.getDimension());
}
public getDimension(): Dimension {
return <Dimension>{
top: this.mapElement.nativeElement.offsetTop,
left: this.mapElement.nativeElement.offsetLeft,
width: this.mapElement.nativeElement.offsetWidth,
height: this.mapElement.nativeElement.offsetHeight
};
}
}