From 66059ea84008ad6ba3ac401fed92ab58aa8bac78 Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Sun, 15 Mar 2020 01:11:23 +0100 Subject: [PATCH] :sparkles: (account) add a new tab with all locations in a map --- src/components/EarthMap.vue | 40 +++++++++++++++++----- src/utils/icons.ts | 6 ++-- src/views/accounts/AccountItem.vue | 23 +++++++++++++ src/views/transactions/TransactionItem.vue | 6 +--- 4 files changed, 60 insertions(+), 15 deletions(-) diff --git a/src/components/EarthMap.vue b/src/components/EarthMap.vue index 863dc6c..5f29e83 100644 --- a/src/components/EarthMap.vue +++ b/src/components/EarthMap.vue @@ -6,26 +6,49 @@ import { Component, Prop, Vue } from 'vue-property-decorator' import mapboxgl from 'mapbox-gl/dist/mapbox-gl' +interface Location { + name?: string + lat: number + lon: number +} + @Component export default class EarthMap extends Vue { - @Prop({ type: Number, required: true }) - private lat!: number - @Prop({ type: Number, required: true }) - private lon!: number + @Prop({ type: Array, default: () => [] }) + private locations!: Location[] private mounted() { - const center = [this.lon, this.lat] mapboxgl.accessToken = process.env.VUE_APP_MAPBOX_KEY + const markers = this.locations.map((location) => [ + location.lon, + location.lat + ]) + const latitudes = this.locations.map((location: Location) => location.lat) + const longitudes = this.locations.map((location: Location) => location.lon) + const minLat = Math.min(...latitudes) + const maxLat = Math.min(...latitudes) + const minLon = Math.min(...longitudes) + const maxLon = Math.min(...longitudes) + const earth = new mapboxgl.Map({ container: 'earth', style: 'mapbox://styles/mapbox/streets-v11', - center, - zoom: 12 + bounds: [ + [minLon, minLat], + [maxLon, maxLat] + ], + fitBoundsOptions: { + padding: 15, + maxZoom: 12 + } }) earth.addControl(new mapboxgl.NavigationControl()) - new mapboxgl.Marker().setLngLat(center).addTo(earth) + + markers.forEach((marker) => { + new mapboxgl.Marker().setLngLat(marker).addTo(earth) + }) } } @@ -35,5 +58,6 @@ export default class EarthMap extends Vue { .earth-container { min-height: 50vh; + height: 100%; } \ No newline at end of file diff --git a/src/utils/icons.ts b/src/utils/icons.ts index 0aa7184..deb01c6 100644 --- a/src/utils/icons.ts +++ b/src/utils/icons.ts @@ -15,9 +15,10 @@ import { faGift, faDollarSign, faEuroSign, - faExchangeAlt, faInbox, + faExchangeAlt, faEquals, + faGlobeEurope, faMinus, faInfinity, faHandHoldingUsd, @@ -54,8 +55,9 @@ library.add( faDollarSign, faEuroSign, faExchangeAlt, - faInbox, faEquals, + faGlobeEurope, + faInbox, faMinus, faInfinity, faHandHoldingUsd, diff --git a/src/views/accounts/AccountItem.vue b/src/views/accounts/AccountItem.vue index 26f0608..bb1e08e 100644 --- a/src/views/accounts/AccountItem.vue +++ b/src/views/accounts/AccountItem.vue @@ -58,6 +58,15 @@ +
  • + + + +
  • +
    + +
    import('@/components/AccountShare.vue'), 'account-transaction-list': () => import('@/components/AccountTransactionList.vue'), + 'earth-map': () => import('@/components/EarthMap.vue'), 'tag-list': () => import('@/components/TagList.vue'), 'chart-balance': () => import('@/components/ChartBalance.vue'), 'online-view': () => import('@/components/OnlineView.vue'), @@ -359,6 +376,12 @@ export default class AccountItem extends BaseAccount { }) } + public get locations() { + return this.transactions + .filter((transaction) => transaction.location) + .map((transaction) => transaction.location) + } + public get myTotalCost(): number { if (!this.account) { return 0 diff --git a/src/views/transactions/TransactionItem.vue b/src/views/transactions/TransactionItem.vue index 15811a7..91b976f 100644 --- a/src/views/transactions/TransactionItem.vue +++ b/src/views/transactions/TransactionItem.vue @@ -129,11 +129,7 @@ Le taux d'échange n'a pas pu être récupéré.
    - +