Search code examples
javascriptsvghere-api

Fontawesome Icon SVG Not shown in Firefox for Heremap Marker


I have a Here Map, within a Vue application, that shows a marker at a specific lat/lng. The marker uses an SVG from FontAwesome (with appropriately displayed attribution) In Chrome, IE and Safari the marker displays perfectly. However, in Firefox (65.0.1 (64-bit) on MacOS) it doesn't show at all.

There are no errors thrown, it just silently refuses to display.

The code looks like this:

let img = document.createElement('img');
img.src = require('../assets/img/home-solid.svg');
const icon = new H.map.Icon(img, {
  size: {
    w: 55,
    h: 55
  }
});
const actMarker = new H.map.Marker(
  { lat: newVal.latitude, lng: newVal.longitude },
  { icon: icon }
);
this.markerGroup.addObject(actMarker);
this.map.setViewBounds(this.markerGroup.getBounds());

The SVG looks like this:

<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="home" class="svg-inline--fa fa-home fa-w-18" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512">
  <path fill="currentColor" d="M280.37 148.26L96 300.11V464a16 16 0 0 0 16 16l112.06-.29a16 16 0 0 0 15.92-16V368a16 16 0 0 1 16-16h64a16 16 0 0 1 16 16v95.64a16 16 0 0 0 16 16.05L464 480a16 16 0 0 0 16-16V300L295.67 148.26a12.19 12.19 0 0 0-15.3 0zM571.6 251.47L488 182.56V44.05a12 12 0 0 0-12-12h-56a12 12 0 0 0-12 12v72.61L318.47 43a48 48 0 0 0-61 0L4.34 251.47a12 12 0 0 0-1.6 16.9l25.5 31A12 12 0 0 0 45.15 301l235.22-193.74a12.19 12.19 0 0 1 15.3 0L530.9 301a12 12 0 0 0 16.9-1.6l25.5-31a12 12 0 0 0-1.7-16.93z">
  </path>
</svg>

As I mentioned, the same code loaded in Chrome works fine.

I've looked at some answers on SO regarding Firefox and SVG but none of what I've read seem to help - e.g. ensuring the CSS class is loaded (that's coming in from the FA CDN)

  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr"
    crossorigin="anonymous">

Does anyone know what's going on here?

As an aside - using a PNG works fine in all browsers so this definitely seems to be SVG related.


Solution

  • Firefox requires that SVG documents used as images and then converted to canvas have a defined width and height.

    Adding width="576px" height="512px" to your SVG document's root element will fix it.