2018-05-27 12:04:35 -04:00
|
|
|
import {Component, ElementRef, Input, OnChanges, ViewChild, AfterViewInit} from '@angular/core';
|
2019-03-03 10:30:12 +01:00
|
|
|
import {PhotoDTO} from '../../../../../common/entities/PhotoDTO';
|
|
|
|
import {Dimension, IRenderable} from '../../../model/IRenderable';
|
2018-03-30 15:30:30 -04:00
|
|
|
import {GalleryMapLightboxComponent} from './lightbox/lightbox.map.gallery.component';
|
2019-03-03 10:30:12 +01:00
|
|
|
import {FileDTO} from '../../../../../common/entities/FileDTO';
|
2018-12-07 22:06:13 +01:00
|
|
|
import {MapService} from './map.service';
|
|
|
|
import {MapComponent} from '@yaga/leaflet-ng2';
|
2018-03-30 15:30:30 -04:00
|
|
|
|
2017-01-22 22:31:29 +01:00
|
|
|
@Component({
|
2018-05-03 19:17:08 -04:00
|
|
|
selector: 'app-gallery-map',
|
2017-06-10 22:32:56 +02:00
|
|
|
templateUrl: './map.gallery.component.html',
|
|
|
|
styleUrls: ['./map.gallery.component.css']
|
2017-01-22 22:31:29 +01:00
|
|
|
})
|
2018-05-27 12:04:35 -04:00
|
|
|
export class GalleryMapComponent implements OnChanges, IRenderable, AfterViewInit {
|
2017-01-22 22:31:29 +01:00
|
|
|
|
2018-11-26 00:26:29 +01:00
|
|
|
@Input() photos: PhotoDTO[];
|
|
|
|
@Input() metaFiles: FileDTO[];
|
2019-07-19 00:12:22 +02:00
|
|
|
@ViewChild(GalleryMapLightboxComponent, {static: false}) mapLightbox: GalleryMapLightboxComponent;
|
2017-06-10 22:32:56 +02:00
|
|
|
|
2018-12-07 22:06:13 +01:00
|
|
|
mapPhotos: Array<{ lat: number, lng: number }> = [];
|
2019-07-19 00:12:22 +02:00
|
|
|
@ViewChild('map', {static: false}) mapElement: ElementRef;
|
|
|
|
@ViewChild('yagaMap', {static: false}) yagaMap: MapComponent;
|
2018-11-28 23:49:33 +01:00
|
|
|
height: number = null;
|
2018-05-27 12:04:35 -04:00
|
|
|
|
|
|
|
|
2018-12-07 22:06:13 +01:00
|
|
|
constructor(public mapService: MapService) {
|
2018-05-27 12:04:35 -04:00
|
|
|
}
|
2017-06-10 22:32:56 +02:00
|
|
|
|
|
|
|
ngOnChanges() {
|
|
|
|
this.mapPhotos = this.photos.filter(p => {
|
2017-06-21 21:16:04 +02:00
|
|
|
return p.metadata && p.metadata.positionData && p.metadata.positionData.GPSData &&
|
|
|
|
p.metadata.positionData.GPSData.latitude && p.metadata.positionData.GPSData.longitude;
|
2017-06-10 22:32:56 +02:00
|
|
|
}).map(p => {
|
|
|
|
return {
|
2018-12-07 22:06:13 +01:00
|
|
|
lat: p.metadata.positionData.GPSData.latitude,
|
|
|
|
lng: p.metadata.positionData.GPSData.longitude
|
2017-06-10 22:32:56 +02:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2018-12-07 22:06:13 +01:00
|
|
|
if (this.yagaMap) {
|
2018-12-08 11:28:56 +01:00
|
|
|
this.yagaMap.setView(this.mapPhotos[0], 99);
|
|
|
|
this.yagaMap.fitBounds(this.mapPhotos.map(mp => <[number, number]>[mp.lat, mp.lng]));
|
2018-12-07 22:06:13 +01:00
|
|
|
this.yagaMap.zoom = 0;
|
|
|
|
}
|
2018-05-27 12:04:35 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ngAfterViewInit() {
|
|
|
|
setTimeout(() => {
|
2018-10-22 00:24:17 +02:00
|
|
|
this.height = this.mapElement.nativeElement.clientHeight;
|
2018-12-08 11:28:56 +01:00
|
|
|
this.yagaMap.setView(this.mapPhotos[0], 99);
|
|
|
|
this.yagaMap.fitBounds(this.mapPhotos.map(mp => <[number, number]>[mp.lat, mp.lng]));
|
2018-12-07 22:06:13 +01:00
|
|
|
this.yagaMap.zoom = 0;
|
2018-05-27 12:04:35 -04:00
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
|
2017-01-22 22:31:29 +01:00
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
click() {
|
|
|
|
this.mapLightbox.show(this.getDimension());
|
|
|
|
}
|
2017-02-05 17:27:58 +01:00
|
|
|
|
2017-06-10 22:32:56 +02:00
|
|
|
public getDimension(): Dimension {
|
|
|
|
return <Dimension>{
|
2018-10-22 00:24:17 +02:00
|
|
|
top: this.mapElement.nativeElement.offsetTop,
|
|
|
|
left: this.mapElement.nativeElement.offsetLeft,
|
|
|
|
width: this.mapElement.nativeElement.offsetWidth,
|
|
|
|
height: this.mapElement.nativeElement.offsetHeight
|
2017-06-10 22:32:56 +02:00
|
|
|
};
|
|
|
|
}
|
2017-01-22 22:31:29 +01:00
|
|
|
}
|
|
|
|
|