Skip to content

Commit 91875a7

Browse files
authored
Merge pull request #2 from haexhub/fix/map-marker-tree-shaking
fix(map): pass explicit Icon to markers so URLs survive tree-shaking
2 parents 3f47ad8 + 7f2cd91 commit 91875a7

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

components/AuctionMap.client.vue

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@ import iconRetinaUrl from 'leaflet/dist/images/marker-icon-2x.png'
66
import shadowUrl from 'leaflet/dist/images/marker-shadow.png'
77
import type { GeoAuction } from '~/server/api/auctions-geo.get'
88
9-
// Leaflet's default Icon resolves marker images via `_getIconUrl`, which
10-
// assumes the PNGs live at the site root. With Vite the assets are bundled
11-
// under hashed URLs, so we override the default with the imported URLs.
12-
delete (L.Icon.Default.prototype as { _getIconUrl?: () => string })._getIconUrl
13-
L.Icon.Default.mergeOptions({ iconUrl, iconRetinaUrl, shadowUrl })
9+
// Pass an explicit Icon to every marker. Mutating L.Icon.Default at module
10+
// top level was tree-shaken by the production build, so the markers fell
11+
// back to relative filenames that 404 from the site root.
12+
const markerIcon = L.icon({
13+
iconUrl,
14+
iconRetinaUrl,
15+
shadowUrl,
16+
iconSize: [25, 41],
17+
iconAnchor: [12, 41],
18+
popupAnchor: [1, -34],
19+
tooltipAnchor: [16, -28],
20+
shadowSize: [41, 41],
21+
})
1422
1523
const props = defineProps<{
1624
auctions: GeoAuction[]
@@ -72,6 +80,7 @@ function refreshMarkers(): void {
7280
for (const a of props.auctions) {
7381
if (a.lat == null || a.lng == null) continue
7482
const marker = L.marker([a.lat, a.lng], {
83+
icon: markerIcon,
7584
title: `${a.objekt ?? ''} · ${a.adresse ?? ''}`,
7685
})
7786
marker.bindPopup(buildPopupHtml(a), { maxWidth: 300 })

0 commit comments

Comments
 (0)