Custom markers only display on Safari

I’m having an issue with custom markers only displaying on Safari. I can open developer tools in firefox or chrome and see where the marker image is found, but it does not display on the map. Here’s my code.

let element = document.createElement('div')
                            element.className = 'marker'
                   = '20px'
                   = 'no-repeat'
                   = 'center'
                   = 'visible'
                            if(value.isActive == 'disconnected'){
                       = 'url(/img/red_dot.png)'

                        let popupdiv = document.createElement('div')
                            popupdiv.innerHTML = value.siteName

                        let popup = new tt.Popup({
                            closeButton: false,
                            offset: 30,
                            anchor: 'bottom'

                       var marker = new tt.Marker({element: element})
                       // var marker = new tt.Marker()
				            .setLngLat([value.longitude, value.latitude])

and the relevant css

.marker {
background-image: url(‘/img/green_dot.png’);
background-size: cover;

Any thoughts?

When inspecting the marker - does it have css properties applied? Can you open the image in a new tab?

I can open the image in a new tab. The background-size property is not being loaded, but that’s probably because I’m overwriting it in my js. When inspecting from the debug tools, it does show that the marker class is added to the div right before the mapbox-g1-marker class.

Thanks for pointing me in the right direction. Because of your response, I started digging a little more and noticed that while safari was displaying it correctly, for some reason other browsers were giving the marker div 0x0 size. I gave it an explicit width and height in my css and it is now displaying correctly.

1 Like