From 2a2b212ada8902f0eba547dd0c7f5817a9e311ef Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Sun, 27 May 2018 12:04:35 -0400 Subject: [PATCH] improving map --- .../lightbox.map.gallery.component.html | 6 +-- .../lightbox.map.gallery.component.ts | 46 +++++++++++++++---- .../app/gallery/map/map.gallery.component.css | 9 +++- .../gallery/map/map.gallery.component.html | 8 ++-- .../app/gallery/map/map.gallery.component.ts | 42 ++++++++++++++--- 5 files changed, 88 insertions(+), 23 deletions(-) diff --git a/frontend/app/gallery/map/lightbox/lightbox.map.gallery.component.html b/frontend/app/gallery/map/lightbox/lightbox.map.gallery.component.html index b0ba910a..8ad5fb8e 100644 --- a/frontend/app/gallery/map/lightbox/lightbox.map.gallery.component.html +++ b/frontend/app/gallery/map/lightbox/lightbox.map.gallery.component.html @@ -9,9 +9,7 @@ + [fitBounds]="latlngBounds"> -
+
; private startPosition = null; public lightboxDimension: Dimension = {top: 0, left: 0, width: 0, height: 0}; public mapDimension: Dimension = {top: 0, left: 0, width: 0, height: 0}; public visible = false; + public controllersVisible = false; public opacity = 1.0; mapPhotos: MapPhoto[] = []; mapCenter = {latitude: 0, longitude: 0}; @@ -27,13 +29,14 @@ export class GalleryMapLightboxComponent implements OnChanges { @ViewChild('root') elementRef: ElementRef; @ViewChild(AgmMap) map: AgmMap; + public latlngBounds: LatLngBounds; constructor(public fullScreenService: FullScreenService, - private thumbnailService: ThumbnailManagerService) { + private thumbnailService: ThumbnailManagerService, + private mapsAPILoader: MapsAPILoader) { } - // TODO: fix zooming ngOnChanges() { if (this.visible === false) { return; @@ -41,6 +44,10 @@ export class GalleryMapLightboxComponent implements OnChanges { this.showImages(); } + ngAfterViewInit() { + + } + public show(position: Dimension) { this.hideImages(); this.visible = true; @@ -54,7 +61,9 @@ export class GalleryMapLightboxComponent implements OnChanges { width: this.getScreenWidth(), height: this.getScreenHeight() }; - this.map.triggerResize(); + this.map.triggerResize().then(() => { + this.controllersVisible = true; + }); PageHelper.hideScrollY(); @@ -71,6 +80,7 @@ export class GalleryMapLightboxComponent implements OnChanges { public hide() { this.fullScreenService.exitFullScreen(); + this.controllersVisible = false; const to = this.startPosition; // iff target image out of screen -> scroll to there @@ -92,7 +102,9 @@ export class GalleryMapLightboxComponent implements OnChanges { this.hideImages(); this.mapPhotos = this.photos.filter(p => { - return p.metadata && p.metadata.positionData && p.metadata.positionData.GPSData; + return p.metadata && p.metadata.positionData && p.metadata.positionData.GPSData + && p.metadata.positionData.GPSData.latitude + && p.metadata.positionData.GPSData.longitude; }).map(p => { let width = 500; let height = 500; @@ -124,9 +136,25 @@ export class GalleryMapLightboxComponent implements OnChanges { return obj; }); - if (this.mapPhotos.length > 0) { - this.mapCenter = this.mapPhotos[0]; + this.findPhotosBounds().catch(console.error); + } + + + 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)); + } + 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)); + } diff --git a/frontend/app/gallery/map/map.gallery.component.css b/frontend/app/gallery/map/map.gallery.component.css index f8a548e1..716da1ff 100644 --- a/frontend/app/gallery/map/map.gallery.component.css +++ b/frontend/app/gallery/map/map.gallery.component.css @@ -4,7 +4,14 @@ } #map { - width: 100%; height: 100%; } + +.overlay { + width: 100%; + height: 100%; + background-color: transparent; + opacity: 0.8; + cursor: pointer; +} diff --git a/frontend/app/gallery/map/map.gallery.component.html b/frontend/app/gallery/map/map.gallery.component.html index 0bb0b390..9ecfd2f2 100644 --- a/frontend/app/gallery/map/map.gallery.component.html +++ b/frontend/app/gallery/map/map.gallery.component.html @@ -2,20 +2,22 @@
+ [fitBounds]="latlngBounds"> +
+
diff --git a/frontend/app/gallery/map/map.gallery.component.ts b/frontend/app/gallery/map/map.gallery.component.ts index 72619cda..08a8af1f 100644 --- a/frontend/app/gallery/map/map.gallery.component.ts +++ b/frontend/app/gallery/map/map.gallery.component.ts @@ -1,23 +1,30 @@ -import {Component, ElementRef, Input, OnChanges, ViewChild} from '@angular/core'; +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 {ThumbnailManagerService} from '../thumnailManager.service'; +import {FullScreenService} from '../fullscreen.service'; +import {LatLngBounds, MapsAPILoader} from '@agm/core'; @Component({ selector: 'app-gallery-map', templateUrl: './map.gallery.component.html', styleUrls: ['./map.gallery.component.css'] }) -export class GalleryMapComponent implements OnChanges, IRenderable { +export class GalleryMapComponent implements OnChanges, IRenderable, AfterViewInit { @Input() photos: Array; @ViewChild(GalleryMapLightboxComponent) mapLightbox: GalleryMapLightboxComponent; mapPhotos: Array<{ latitude: number, longitude: number }> = []; - mapCenter = {latitude: 0, longitude: 0}; + public latlngBounds: LatLngBounds; @ViewChild('map') map: ElementRef; + height = null; + + + constructor(private mapsAPILoader: MapsAPILoader) { + } - // TODO: fix zooming ngOnChanges() { this.mapPhotos = this.photos.filter(p => { return p.metadata && p.metadata.positionData && p.metadata.positionData.GPSData && @@ -29,9 +36,32 @@ export class GalleryMapComponent implements OnChanges, IRenderable { }; }); - if (this.mapPhotos.length > 0) { - this.mapCenter = this.mapPhotos[0]; + + this.findPhotosBounds().catch(console.error); + + } + + ngAfterViewInit() { + setTimeout(() => { + this.height = this.map.nativeElement.clientHeight; + console.log(this.height); + }, 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)); + } + 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)); }