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

72 lines
2.2 KiB
TypeScript
Raw Normal View History

2018-05-28 00:04:35 +08:00
import {Component, ElementRef, Input, OnChanges, ViewChild, AfterViewInit} from '@angular/core';
2018-03-31 03:30:30 +08:00
import {PhotoDTO} from '../../../../common/entities/PhotoDTO';
import {Dimension, IRenderable} from '../../model/IRenderable';
import {GalleryMapLightboxComponent} from './lightbox/lightbox.map.gallery.component';
2018-11-26 07:26:29 +08:00
import {FileDTO} from '../../../../common/entities/FileDTO';
import {MapService} from './map.service';
import {MapComponent} from '@yaga/leaflet-ng2';
2018-03-31 03:30:30 +08:00
@Component({
2018-05-04 07:17:08 +08:00
selector: 'app-gallery-map',
templateUrl: './map.gallery.component.html',
styleUrls: ['./map.gallery.component.css']
})
2018-05-28 00:04:35 +08:00
export class GalleryMapComponent implements OnChanges, IRenderable, AfterViewInit {
2018-11-26 07:26:29 +08:00
@Input() photos: PhotoDTO[];
@Input() metaFiles: FileDTO[];
@ViewChild(GalleryMapLightboxComponent) mapLightbox: GalleryMapLightboxComponent;
mapPhotos: Array<{ lat: number, lng: number }> = [];
@ViewChild('map') mapElement: ElementRef;
@ViewChild('yagaMap') yagaMap: MapComponent;
2018-11-29 06:49:33 +08:00
height: number = null;
2018-05-28 00:04:35 +08:00
constructor(public mapService: MapService) {
2018-05-28 00:04:35 +08:00
}
ngOnChanges() {
this.mapPhotos = this.photos.filter(p => {
2017-06-22 03:16:04 +08:00
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;
}
2018-05-28 00:04:35 +08:00
}
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;
2018-05-28 00:04:35 +08:00
}, 0);
}
click() {
this.mapLightbox.show(this.getDimension());
}
2017-02-06 00:27:58 +08:00
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
};
}
}