1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/frontend/app/gallery/map/lightbox/lightbox.map.gallery.component.ts

158 lines
4.2 KiB
TypeScript
Raw Normal View History

import {Component, ElementRef, HostListener, Input, OnChanges, ViewChild} from "@angular/core";
2017-02-06 00:27:58 +08:00
import {PhotoDTO} from "../../../../../common/entities/PhotoDTO";
import {Dimension} from "../../../model/IRenderable";
import {FullScreenService} from "../../fullscreen.service";
2017-05-27 16:15:57 +08:00
import {AgmMap} from "@agm/core";
import {IconThumbnail, ThumbnailManagerService} from "../../thumnailManager.service";
import {IconPhoto} from "../../IconPhoto";
2017-02-06 00:27:58 +08:00
@Component({
selector: 'gallery-map-lightbox',
styleUrls: ['./lightbox.map.gallery.component.css'],
templateUrl: './lightbox.map.gallery.component.html',
2017-02-06 00:27:58 +08:00
})
export class GalleryMapLightboxComponent implements OnChanges {
@Input() photos: Array<PhotoDTO>;
private startPosition = null;
public lightboxDimension: Dimension = <Dimension>{top: 0, left: 0, width: 0, height: 0};
public mapDimension: Dimension = <Dimension>{top: 0, left: 0, width: 0, height: 0};
public visible = false;
public opacity = 1.0;
mapPhotos: Array<{ latitude: number, longitude: number, iconUrl?: string, thumbnail: IconThumbnail }> = [];
mapCenter = {latitude: 0, longitude: 0};
2017-02-06 00:27:58 +08:00
@ViewChild("root") elementRef: ElementRef;
2017-02-06 00:27:58 +08:00
@ViewChild(AgmMap) map: AgmMap;
2017-02-06 00:27:58 +08:00
constructor(public fullScreenService: FullScreenService, private thumbnailService: ThumbnailManagerService) {
2017-02-06 00:27:58 +08:00
}
2017-02-06 00:27:58 +08:00
//TODO: fix zooming
ngOnChanges() {
if (this.visible == false) {
return;
2017-02-06 00:27:58 +08:00
}
this.showImages();
}
public show(position: Dimension) {
this.visible = true;
this.opacity = 1.0;
this.startPosition = position;
this.lightboxDimension = position;
this.lightboxDimension.top -= this.getBodyScrollTop();
this.mapDimension = <Dimension>{
top: 0,
left: 0,
width: this.getScreenWidth(),
height: this.getScreenHeight()
};
this.map.triggerResize();
document.getElementsByTagName('body')[0].style.overflow = 'hidden';
this.showImages();
2017-06-11 04:56:23 +08:00
setTimeout(() => {
this.lightboxDimension = <Dimension>{
top: 0,
left: 0,
width: this.getScreenWidth(),
height: this.getScreenHeight()
};
2017-06-11 04:56:23 +08:00
}, 0);
}
public hide() {
this.fullScreenService.exitFullScreen();
let to = this.startPosition;
//iff target image out of screen -> scroll to there
if (this.getBodyScrollTop() > to.top || this.getBodyScrollTop() + this.getScreenHeight() < to.top) {
this.setBodyScrollTop(to.top);
2017-02-06 00:27:58 +08:00
}
this.lightboxDimension = this.startPosition;
this.lightboxDimension.top -= this.getBodyScrollTop();
document.getElementsByTagName('body')[0].style.overflow = 'scroll';
this.opacity = 0.0;
setTimeout(() => {
this.visible = false;
this.hideImages();
}, 500);
}
showImages() {
this.hideImages();
this.mapPhotos = this.photos.filter(p => {
return p.metadata && p.metadata.positionData && p.metadata.positionData.GPSData;
}).map(p => {
let th = this.thumbnailService.getIcon(new IconPhoto(p));
let obj: { latitude: number, longitude: number, iconUrl?: string, thumbnail: IconThumbnail } = {
latitude: p.metadata.positionData.GPSData.latitude,
longitude: p.metadata.positionData.GPSData.longitude,
thumbnail: th
};
if (th.Available == true) {
obj.iconUrl = th.Src;
} else {
th.OnLoad = () => {
obj.iconUrl = th.Src;
};
}
return obj;
});
2017-02-06 00:27:58 +08:00
if (this.mapPhotos.length > 0) {
this.mapCenter = this.mapPhotos[0];
2017-02-06 00:27:58 +08:00
}
}
2017-02-06 00:27:58 +08:00
hideImages() {
this.mapPhotos.forEach(mp => mp.thumbnail.destroy());
this.mapPhotos = [];
}
2017-03-20 07:01:41 +08:00
private getBodyScrollTop(): number {
return window.scrollY;
}
2017-02-06 00:27:58 +08:00
private setBodyScrollTop(value: number) {
window.scrollTo(window.scrollX, value);
}
2017-02-06 00:27:58 +08:00
private getScreenWidth() {
return window.innerWidth;
}
2017-02-06 00:27:58 +08:00
private getScreenHeight() {
return window.innerHeight;
}
2017-02-06 00:27:58 +08:00
//noinspection JSUnusedGlobalSymbols
@HostListener('window:keydown', ['$event'])
onKeyPress(e: KeyboardEvent) {
if (this.visible != true) {
return;
2017-02-06 00:27:58 +08:00
}
let event: KeyboardEvent = window.event ? <any>window.event : e;
switch (event.keyCode) {
case 27: //escape
this.hide();
break;
}
}
2017-02-06 00:27:58 +08:00
}