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-05-28 00:04:35 +08:00
|
|
|
import {ThumbnailManagerService} from '../thumnailManager.service';
|
|
|
|
import {FullScreenService} from '../fullscreen.service';
|
|
|
|
import {LatLngBounds, MapsAPILoader} from '@agm/core';
|
2018-03-31 03:30:30 +08:00
|
|
|
|
2017-01-23 05:31:29 +08:00
|
|
|
@Component({
|
2018-05-04 07:17:08 +08:00
|
|
|
selector: 'app-gallery-map',
|
2017-06-11 04:32:56 +08:00
|
|
|
templateUrl: './map.gallery.component.html',
|
|
|
|
styleUrls: ['./map.gallery.component.css']
|
2017-01-23 05:31:29 +08:00
|
|
|
})
|
2018-05-28 00:04:35 +08:00
|
|
|
export class GalleryMapComponent implements OnChanges, IRenderable, AfterViewInit {
|
2017-01-23 05:31:29 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
@Input() photos: Array<PhotoDTO>;
|
|
|
|
@ViewChild(GalleryMapLightboxComponent) mapLightbox: GalleryMapLightboxComponent;
|
|
|
|
|
|
|
|
mapPhotos: Array<{ latitude: number, longitude: number }> = [];
|
2018-05-28 00:04:35 +08:00
|
|
|
public latlngBounds: LatLngBounds;
|
2018-03-31 03:30:30 +08:00
|
|
|
@ViewChild('map') map: ElementRef;
|
2018-05-28 00:04:35 +08:00
|
|
|
height = null;
|
|
|
|
|
|
|
|
|
|
|
|
constructor(private mapsAPILoader: MapsAPILoader) {
|
|
|
|
}
|
2017-06-11 04:32:56 +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;
|
2017-06-11 04:32:56 +08:00
|
|
|
}).map(p => {
|
|
|
|
return {
|
|
|
|
latitude: p.metadata.positionData.GPSData.latitude,
|
|
|
|
longitude: p.metadata.positionData.GPSData.longitude
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2018-05-28 00:04:35 +08:00
|
|
|
|
|
|
|
this.findPhotosBounds().catch(console.error);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ngAfterViewInit() {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.height = this.map.nativeElement.clientHeight;
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private async findPhotosBounds() {
|
|
|
|
await this.mapsAPILoader.load();
|
|
|
|
if (!window['google']) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.latlngBounds = new window['google'].maps.LatLngBounds();
|
|
|
|
|
|
|
|
for (const photo of this.mapPhotos) {
|
|
|
|
this.latlngBounds.extend(new window['google'].maps.LatLng(photo.latitude, photo.longitude));
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2018-05-28 00:04:35 +08:00
|
|
|
const clat = this.latlngBounds.getCenter().lat();
|
|
|
|
const clng = this.latlngBounds.getCenter().lng();
|
|
|
|
this.latlngBounds.extend(new window['google'].maps.LatLng(clat + 0.5, clng + 0.5));
|
|
|
|
this.latlngBounds.extend(new window['google'].maps.LatLng(clat - 0.5, clng - 0.5));
|
2017-01-23 05:31:29 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2017-01-23 05:31:29 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
click() {
|
|
|
|
this.mapLightbox.show(this.getDimension());
|
|
|
|
}
|
2017-02-06 00:27:58 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
public getDimension(): Dimension {
|
|
|
|
return <Dimension>{
|
|
|
|
top: this.map.nativeElement.offsetTop,
|
|
|
|
left: this.map.nativeElement.offsetLeft,
|
|
|
|
width: this.map.nativeElement.offsetWidth,
|
|
|
|
height: this.map.nativeElement.offsetHeight
|
|
|
|
};
|
|
|
|
}
|
2017-01-23 05:31:29 +08:00
|
|
|
}
|
|
|
|
|