Wait for marker image load
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
**mapbox-gl-js version**: latest
### Question
Hi there !
i'm currently trying to get custom marker images to work in Svelte. It seems that sometimes (on refresh) the marker icons shows up and sometimes not, which is why i guess it could be loading issue.
This is my CustomMarker Component:
```
import { onMount } from "svelte";
import mapboxgl from "mapbox-gl";
export let marker: any;
export let map: any;
onMount(() => {
const markerElement = document.createElement("div");
markerElement.className = "custom-marker";
new mapboxgl.Marker(markerElement)
.setLngLat(marker.geometry.coordinates)
.setPopup(
new mapboxgl.Popup({ offset: 25 }).setHTML(
`<h3>${marker.properties.message}</h3><p>Test description</p>`
)
)
.addTo(map);
});
.custom-marker {
background-image: 'url("https://aqhnreobugwxvsogdiox.supabase.co/storage/v1/object/public/Images/example.png")';
background-size: cover;
cursor: pointer;
width: 30px;
height: 30px;
}
```
And this is how i add the markers on the map page:
```
{#each markers.features as marker}
{#if marker.geometry.type === "Point"}
{/if}
{/each}
```
When i remove the markerElement from the new mapboxgl.Marker the default marker can be shown and clicked.
### Links to related documentation
I used this as an starting point:
https://docs.mapbox.com/help/tutorials/use-mapbox-gl-js-with-svelte/
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The relevant entry points are the CustomMarker component and the map page's marker loop shown in the report; first reproduce the refresh-dependent behavior and compare the setup with the linked Mapbox Svelte tutorial. Done means the custom image marker is consistently rendered and clickable after refresh, with the cause and any required project change documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100