pull/221/head
Varun Patil 2022-11-07 16:26:56 -08:00
parent 660f7e3f5b
commit 0b4ee8348b
2 changed files with 60 additions and 9 deletions

View File

@ -97,6 +97,7 @@ class PageController extends Controller
// Allow nominatim for metadata // Allow nominatim for metadata
$policy->addAllowedConnectDomain('nominatim.openstreetmap.org'); $policy->addAllowedConnectDomain('nominatim.openstreetmap.org');
$policy->addAllowedFrameDomain('www.openstreetmap.org');
$response = new TemplateResponse($this->appName, 'main'); $response = new TemplateResponse($this->appName, 'main');
$response->setContentSecurityPolicy($policy); $response->setContentSecurityPolicy($policy);

View File

@ -5,14 +5,29 @@
<component :is="field.icon" :size="24" /> <component :is="field.icon" :size="24" />
</div> </div>
<div class="text"> <div class="text">
{{ field.title }} <br /> <template v-if="field.href">
<span class="subtitle"> <a :href="field.href" target="_blank" rel="noopener noreferrer">
<span class="part" v-for="part in field.subtitle" :key="part"> {{ field.title }}
{{ part }} </a>
</template>
<template v-else>
{{ field.title }}
</template>
<template v-if="field.subtitle.length">
<br />
<span class="subtitle">
<span class="part" v-for="part in field.subtitle" :key="part">
{{ part }}
</span>
</span> </span>
</span> </template>
</div> </div>
</div> </div>
<div v-if="lat && lon" class="map">
<iframe class="fill-block" :src="mapUrl" />
</div>
</div> </div>
</template> </template>
@ -47,6 +62,7 @@ export default class Metadata extends Mixins(GlobalMixin) {
this.state = Math.random(); this.state = Math.random();
this.fileInfo = fileInfo; this.fileInfo = fileInfo;
this.exif = {}; this.exif = {};
this.nominatim = null;
let state = this.state; let state = this.state;
const res = await axios.get<any>( const res = await axios.get<any>(
@ -66,6 +82,7 @@ export default class Metadata extends Mixins(GlobalMixin) {
title: string; title: string;
subtitle: string[]; subtitle: string[];
icon: any; icon: any;
href?: string;
}[] = []; }[] = [];
if (this.dateOriginal) { if (this.dateOriginal) {
@ -92,11 +109,12 @@ export default class Metadata extends Mixins(GlobalMixin) {
}); });
} }
if (this.nominatim) { if (this.address) {
list.push({ list.push({
title: this.address, title: this.address,
subtitle: [], subtitle: [],
icon: LocationIcon, icon: LocationIcon,
href: this.mapFullUrl,
}); });
} }
@ -196,7 +214,10 @@ export default class Metadata extends Mixins(GlobalMixin) {
} }
get address() { get address() {
if (!this.nominatim) return null; if (!this.lat || !this.lon) return null;
if (!this.nominatim) return this.t("memories", "Loading …");
const n = this.nominatim; const n = this.nominatim;
const country = n.address.country_code?.toUpperCase(); const country = n.address.country_code?.toUpperCase();
@ -211,9 +232,33 @@ export default class Metadata extends Mixins(GlobalMixin) {
} }
} }
get lat() {
return this.exif["GPSLatitude"];
}
get lon() {
return this.exif["GPSLongitude"];
}
get mapUrl() {
const boxSize = 0.007;
const bbox = [
this.lon - boxSize,
this.lat - boxSize,
this.lon + boxSize,
this.lat + boxSize,
];
const m = `${this.lat},${this.lon}`;
return `https://www.openstreetmap.org/export/embed.html?bbox=${bbox.join()}&marker=${m}`;
}
get mapFullUrl() {
return `https://www.openstreetmap.org/?mlat=${this.lat}&mlon=${this.lon}#map=18/${this.lat}/${this.lon}`;
}
async getNominatim() { async getNominatim() {
const lat = this.exif["GPSLatitude"]; const lat = this.lat;
const lon = this.exif["GPSLongitude"]; const lon = this.lon;
if (!lat || !lon) return null; if (!lat || !lon) return null;
const state = this.state; const state = this.state;
@ -249,4 +294,9 @@ export default class Metadata extends Mixins(GlobalMixin) {
} }
} }
} }
.map {
width: 100%;
height: 200px;
}
</style> </style>