Skip to content

Commit

Permalink
Fix Leaflet bug (with Vue) that not including the marker icon in prod…
Browse files Browse the repository at this point in the history
…uction build
  • Loading branch information
massijay committed Sep 12, 2022
1 parent bf9f633 commit cc7b543
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions TripRecorder-vue/src/composables/tripMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import {ref} from "vue";
import {DateTime} from "luxon";
import {useRoute} from "vue-router/dist/vue-router";
import router from "../router";
import markerX2Icon from 'leaflet/dist/images/marker-icon-2x.png'
import markerIcon from 'leaflet/dist/images/marker-icon.png'
import markerShadow from 'leaflet/dist/images/marker-shadow.png'

export function useTripMap() {

Expand All @@ -21,6 +24,16 @@ export function useTripMap() {
});

function initMap(enableMapClick = false) {
// Fix leaflet bug with Vue not displaying marker icon in production build
// https://stackoverflow.com/a/58254190/11583146
// https://vitejs.dev/guide/features.html#static-assets
delete L.Icon.Default.prototype._getIconUrl;
L.Icon.Default.mergeOptions({
iconRetinaUrl: markerX2Icon,
iconUrl: markerIcon,
shadowUrl: markerShadow
});

map = L.map('map').setView([45.659695, 13.794748], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
Expand Down
2 changes: 1 addition & 1 deletion TripRecorder-vue/src/views/TripsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<p class="mb-1 text-center text-muted">Caricamento...</p>
</a>
</div>
<p class="mb-1 text-center text-muted mt-3" v-if="!isLoading && !dateFilter.value && trips.length">
<p class="mb-1 text-center text-muted mt-3" v-if="!isLoading && !dateFilter && trips.length">
<InformationCircleIcon style="width: 1rem;" class="me-1 mb-1"></InformationCircleIcon>
Stai visualizzando gli utlimi 10 viaggi, seleziona una data per filtrarli
</p>
Expand Down

0 comments on commit cc7b543

Please sign in to comment.