mirror of
https://github.com/xuthus83/pigallery2.git
synced 2025-01-14 14:43:17 +08:00
improving map
This commit is contained in:
parent
9a7f40ac99
commit
2a2b212ada
@ -9,9 +9,7 @@
|
|||||||
<agm-map
|
<agm-map
|
||||||
[style.width.px]="mapDimension.width"
|
[style.width.px]="mapDimension.width"
|
||||||
[style.height.px]="mapDimension.height"
|
[style.height.px]="mapDimension.height"
|
||||||
[zoom]="5"
|
[fitBounds]="latlngBounds">
|
||||||
[latitude]="mapCenter.latitude"
|
|
||||||
[longitude]="mapCenter.longitude">
|
|
||||||
<agm-marker
|
<agm-marker
|
||||||
*ngFor="let photo of mapPhotos"
|
*ngFor="let photo of mapPhotos"
|
||||||
[latitude]="photo.latitude"
|
[latitude]="photo.latitude"
|
||||||
@ -38,7 +36,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div id="controllers-container" *ngIf="visible">
|
<div id="controllers-container" *ngIf="controllersVisible">
|
||||||
<div id="controls">
|
<div id="controls">
|
||||||
<span>
|
<span>
|
||||||
<span class="oi oi-fullscreen-exit highlight"
|
<span class="oi oi-fullscreen-exit highlight"
|
||||||
|
@ -1,25 +1,27 @@
|
|||||||
import {Component, ElementRef, HostListener, Input, OnChanges, ViewChild} from '@angular/core';
|
import {Component, ElementRef, HostListener, Input, OnChanges, ViewChild, AfterViewInit} from '@angular/core';
|
||||||
import {PhotoDTO} from '../../../../../common/entities/PhotoDTO';
|
import {PhotoDTO} from '../../../../../common/entities/PhotoDTO';
|
||||||
import {Dimension} from '../../../model/IRenderable';
|
import {Dimension} from '../../../model/IRenderable';
|
||||||
import {FullScreenService} from '../../fullscreen.service';
|
import {FullScreenService} from '../../fullscreen.service';
|
||||||
import {AgmMap} from '@agm/core';
|
import {AgmMap, LatLngBounds, MapsAPILoader} from '@agm/core';
|
||||||
import {IconThumbnail, Thumbnail, ThumbnailManagerService} from '../../thumnailManager.service';
|
import {IconThumbnail, Thumbnail, ThumbnailManagerService} from '../../thumnailManager.service';
|
||||||
import {IconPhoto} from '../../IconPhoto';
|
import {IconPhoto} from '../../IconPhoto';
|
||||||
import {Photo} from '../../Photo';
|
import {Photo} from '../../Photo';
|
||||||
import {PageHelper} from '../../../model/page.helper';
|
import {PageHelper} from '../../../model/page.helper';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-gallery-map-lightbox',
|
selector: 'app-gallery-map-lightbox',
|
||||||
styleUrls: ['./lightbox.map.gallery.component.css'],
|
styleUrls: ['./lightbox.map.gallery.component.css'],
|
||||||
templateUrl: './lightbox.map.gallery.component.html',
|
templateUrl: './lightbox.map.gallery.component.html',
|
||||||
})
|
})
|
||||||
export class GalleryMapLightboxComponent implements OnChanges {
|
export class GalleryMapLightboxComponent implements OnChanges, AfterViewInit {
|
||||||
|
|
||||||
@Input() photos: Array<PhotoDTO>;
|
@Input() photos: Array<PhotoDTO>;
|
||||||
private startPosition = null;
|
private startPosition = null;
|
||||||
public lightboxDimension: Dimension = <Dimension>{top: 0, left: 0, width: 0, height: 0};
|
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 mapDimension: Dimension = <Dimension>{top: 0, left: 0, width: 0, height: 0};
|
||||||
public visible = false;
|
public visible = false;
|
||||||
|
public controllersVisible = false;
|
||||||
public opacity = 1.0;
|
public opacity = 1.0;
|
||||||
mapPhotos: MapPhoto[] = [];
|
mapPhotos: MapPhoto[] = [];
|
||||||
mapCenter = {latitude: 0, longitude: 0};
|
mapCenter = {latitude: 0, longitude: 0};
|
||||||
@ -27,13 +29,14 @@ export class GalleryMapLightboxComponent implements OnChanges {
|
|||||||
@ViewChild('root') elementRef: ElementRef;
|
@ViewChild('root') elementRef: ElementRef;
|
||||||
|
|
||||||
@ViewChild(AgmMap) map: AgmMap;
|
@ViewChild(AgmMap) map: AgmMap;
|
||||||
|
public latlngBounds: LatLngBounds;
|
||||||
|
|
||||||
|
|
||||||
constructor(public fullScreenService: FullScreenService,
|
constructor(public fullScreenService: FullScreenService,
|
||||||
private thumbnailService: ThumbnailManagerService) {
|
private thumbnailService: ThumbnailManagerService,
|
||||||
|
private mapsAPILoader: MapsAPILoader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: fix zooming
|
|
||||||
ngOnChanges() {
|
ngOnChanges() {
|
||||||
if (this.visible === false) {
|
if (this.visible === false) {
|
||||||
return;
|
return;
|
||||||
@ -41,6 +44,10 @@ export class GalleryMapLightboxComponent implements OnChanges {
|
|||||||
this.showImages();
|
this.showImages();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngAfterViewInit() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public show(position: Dimension) {
|
public show(position: Dimension) {
|
||||||
this.hideImages();
|
this.hideImages();
|
||||||
this.visible = true;
|
this.visible = true;
|
||||||
@ -54,7 +61,9 @@ export class GalleryMapLightboxComponent implements OnChanges {
|
|||||||
width: this.getScreenWidth(),
|
width: this.getScreenWidth(),
|
||||||
height: this.getScreenHeight()
|
height: this.getScreenHeight()
|
||||||
};
|
};
|
||||||
this.map.triggerResize();
|
this.map.triggerResize().then(() => {
|
||||||
|
this.controllersVisible = true;
|
||||||
|
});
|
||||||
|
|
||||||
PageHelper.hideScrollY();
|
PageHelper.hideScrollY();
|
||||||
|
|
||||||
@ -71,6 +80,7 @@ export class GalleryMapLightboxComponent implements OnChanges {
|
|||||||
|
|
||||||
public hide() {
|
public hide() {
|
||||||
this.fullScreenService.exitFullScreen();
|
this.fullScreenService.exitFullScreen();
|
||||||
|
this.controllersVisible = false;
|
||||||
const to = this.startPosition;
|
const to = this.startPosition;
|
||||||
|
|
||||||
// iff target image out of screen -> scroll to there
|
// iff target image out of screen -> scroll to there
|
||||||
@ -92,7 +102,9 @@ export class GalleryMapLightboxComponent implements OnChanges {
|
|||||||
this.hideImages();
|
this.hideImages();
|
||||||
|
|
||||||
this.mapPhotos = this.photos.filter(p => {
|
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 => {
|
}).map(p => {
|
||||||
let width = 500;
|
let width = 500;
|
||||||
let height = 500;
|
let height = 500;
|
||||||
@ -124,9 +136,25 @@ export class GalleryMapLightboxComponent implements OnChanges {
|
|||||||
return obj;
|
return obj;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.mapPhotos.length > 0) {
|
this.findPhotosBounds().catch(console.error);
|
||||||
this.mapCenter = this.mapPhotos[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));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,7 +4,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#map {
|
#map {
|
||||||
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.overlay {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background-color: transparent;
|
||||||
|
opacity: 0.8;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
@ -2,20 +2,22 @@
|
|||||||
<app-gallery-map-lightbox [photos]="photos"></app-gallery-map-lightbox>
|
<app-gallery-map-lightbox [photos]="photos"></app-gallery-map-lightbox>
|
||||||
<div id="map" #map>
|
<div id="map" #map>
|
||||||
<agm-map
|
<agm-map
|
||||||
(click)="click()"
|
|
||||||
[disableDefaultUI]="true"
|
[disableDefaultUI]="true"
|
||||||
[zoomControl]="false"
|
[zoomControl]="false"
|
||||||
[streetViewControl]="false"
|
[streetViewControl]="false"
|
||||||
[usePanning]="false"
|
[usePanning]="false"
|
||||||
[draggable]="false"
|
[draggable]="false"
|
||||||
[zoom]="0"
|
[zoom]="0"
|
||||||
[latitude]="mapCenter.latitude"
|
[fitBounds]="latlngBounds">
|
||||||
[longitude]="mapCenter.longitude">
|
|
||||||
<agm-marker
|
<agm-marker
|
||||||
*ngFor="let photo of mapPhotos"
|
*ngFor="let photo of mapPhotos"
|
||||||
[latitude]="photo.latitude"
|
[latitude]="photo.latitude"
|
||||||
[longitude]="photo.longitude">
|
[longitude]="photo.longitude">
|
||||||
</agm-marker>
|
</agm-marker>
|
||||||
</agm-map>
|
</agm-map>
|
||||||
|
<div class="overlay" (click)="click()"
|
||||||
|
[style.margin-top.px]="-height"
|
||||||
|
[style.height.px]="height">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
@ -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 {PhotoDTO} from '../../../../common/entities/PhotoDTO';
|
||||||
import {Dimension, IRenderable} from '../../model/IRenderable';
|
import {Dimension, IRenderable} from '../../model/IRenderable';
|
||||||
import {GalleryMapLightboxComponent} from './lightbox/lightbox.map.gallery.component';
|
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({
|
@Component({
|
||||||
selector: 'app-gallery-map',
|
selector: 'app-gallery-map',
|
||||||
templateUrl: './map.gallery.component.html',
|
templateUrl: './map.gallery.component.html',
|
||||||
styleUrls: ['./map.gallery.component.css']
|
styleUrls: ['./map.gallery.component.css']
|
||||||
})
|
})
|
||||||
export class GalleryMapComponent implements OnChanges, IRenderable {
|
export class GalleryMapComponent implements OnChanges, IRenderable, AfterViewInit {
|
||||||
|
|
||||||
@Input() photos: Array<PhotoDTO>;
|
@Input() photos: Array<PhotoDTO>;
|
||||||
@ViewChild(GalleryMapLightboxComponent) mapLightbox: GalleryMapLightboxComponent;
|
@ViewChild(GalleryMapLightboxComponent) mapLightbox: GalleryMapLightboxComponent;
|
||||||
|
|
||||||
mapPhotos: Array<{ latitude: number, longitude: number }> = [];
|
mapPhotos: Array<{ latitude: number, longitude: number }> = [];
|
||||||
mapCenter = {latitude: 0, longitude: 0};
|
public latlngBounds: LatLngBounds;
|
||||||
@ViewChild('map') map: ElementRef;
|
@ViewChild('map') map: ElementRef;
|
||||||
|
height = null;
|
||||||
|
|
||||||
|
|
||||||
|
constructor(private mapsAPILoader: MapsAPILoader) {
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: fix zooming
|
|
||||||
ngOnChanges() {
|
ngOnChanges() {
|
||||||
this.mapPhotos = this.photos.filter(p => {
|
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 &&
|
||||||
@ -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));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user