Skip to content

Commit

Permalink
Make addresses clickable to highlight stores on map, add button to ge…
Browse files Browse the repository at this point in the history
…t directions GUI#138
  • Loading branch information
dominicrutk committed May 2, 2021
1 parent 8b4b742 commit e094fa2
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 7 deletions.
34 changes: 32 additions & 2 deletions website/components/LocationDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,18 @@
name: store.properties.provider_brand_name,
})
}}
<font-awesome-icon icon="arrow-alt-circle-right"
/></a>
<font-awesome-icon icon="arrow-alt-circle-right" />
</a>

<a
:href="directionsLink"
class="btn btn-primary"
target="_blank"
:rel="noopener"
>
{{ $t("Get Directions") }}
<font-awesome-icon icon="directions" />
</a>
</div>
<div v-else class="location-status">
<div v-if="store.properties.appointments_available === false">
Expand Down Expand Up @@ -105,6 +115,12 @@
<font-awesome-icon icon="external-link-alt"
/></a>
</p>
<p>
<a :href="directionsLink" target="_blank" :rel="noopener">
{{ $t("Get Directions") }}
<font-awesome-icon icon="external-link-alt" />
</a>
</p>
</div>

<p class="card-text text-secondary mt-2">
Expand Down Expand Up @@ -151,6 +167,20 @@ export default {
return rel;
},
directionsLink() {
return `https://www.google.com/maps/dir/?api=1&destination=${encodeURIComponent(
[
this.store.properties.address,
this.store.properties.city,
[this.store.properties.state, this.store.properties.postal_code]
.filter((value) => !!value)
.join(", "),
]
.filter((value) => !!value)
.join(", ")
)}`;
},
},
};
</script>
Expand Down
30 changes: 28 additions & 2 deletions website/components/LocationMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,12 @@ export default {
});
this.map.on("click", "locations", (e) => {
const coordinates = e.features[0].geometry.coordinates.slice();
const store = e.features[0];
const store = e.highlightLocationId
? e.features.find(
(feature) => feature.properties.id === e.highlightLocationId
)
: e.features[0];
const coordinates = store.geometry.coordinates.slice();
// Nested JSON data in the properties is represented as JSON strings
// (rather than actual objects) when fetching the object from the click
Expand Down Expand Up @@ -255,6 +259,28 @@ export default {
this.mapBoundsAnimate = true;
}
},
highlightLocation(store) {
const [lng, lat] = store.geometry.coordinates;
this.map.panTo(
{
lon: lng,
lat,
},
{
duration: 250,
}
);
setTimeout(() => {
this.map.fire("click", {
lngLat: {
lng,
lat,
},
highlightLocationId: store.properties.id,
});
}, 500);
},
},
};
</script>
Expand Down
9 changes: 7 additions & 2 deletions website/components/Store.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
<div class="card-header">
<div class="row">
<h5 class="col-sm mb-0">
{{ title }}
{{ title }} -
<a
href="javascript:void(0);"
@click="$emit('highlight-location', store)"
>
{{ fullAddress }}
</a>
</h5>
<div v-if="store.distance" class="col-sm-auto">
{{ $t("{distance} miles", { distance: store.distance }) }}
Expand Down Expand Up @@ -37,7 +43,6 @@ export default {
) {
title += ` - ${this.store.properties.name}`;
}
title += ` - ${this.fullAddress}`;
return title;
},
Expand Down
5 changes: 4 additions & 1 deletion website/pages/_state.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div class="container-fluid container-lg-no-padding">
<div class="row g-3 g-lg-0">
<div class="col-lg-6 col-map">
<location-map />
<location-map ref="locationMap" />
</div>
<div class="col-lg-6 col-list">
<div class="results-container">
Expand Down Expand Up @@ -58,6 +58,9 @@
v-for="store in filteredLocationsPage"
:key="store.properties.id"
:store="store"
@highlight-location="
$refs.locationMap.highlightLocation($event)
"
></store>

<location-pagination
Expand Down
2 changes: 2 additions & 0 deletions website/plugins/fontawesome.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
faCheckCircle,
faChevronLeft,
faChevronRight,
faDirections,
faExclamationTriangle,
faTimesCircle,
faExternalLinkAlt,
Expand All @@ -24,6 +25,7 @@ library.add(
faCheckCircle,
faChevronLeft,
faChevronRight,
faDirections,
faExclamationTriangle,
faTimesCircle,
faExternalLinkAlt,
Expand Down

0 comments on commit e094fa2

Please sign in to comment.