Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding background image to markers in jvectormap
    primarykey
    data
    text
    <p>Found a couple of solutions here about adding SVG patterns dynamically but it doesn't seem to work with jvectormap. I think the problem may be that there is no <code>XMLNS</code> attribute defined on the <code>&lt;SVG&gt;</code> tag by jvectormap but my attempt to add these attributes does not work.</p> <p>I also tried changing all of the <code>setAttribute</code> to <code>setAttributeNS</code> for <code>pattern</code> and <code>image</code>. But no dice.</p> <p>Here is my attempt (based on this solution: <a href="https://stackoverflow.com/questions/13378797/how-to-dynamically-change-the-image-pattern-in-svg-using-javascript">How to dynamically change the image pattern in SVG using Javascript</a>):</p> <pre><code>// Set namespace for SVG elements. var svgMap = $('.jvectormap-container &gt; svg').get(0); var svgNS = 'http://www.w3.org/2000/svg'; var svgNSXLink = 'http://www.w3.org/1999/xlink'; svgMap.setAttribute('xmlns', svgNS); svgMap.setAttribute('xmlns:link', svgNSXLink); svgMap.setAttribute('xmlns:ev', 'http://www.w3.org/2001/xml-events'); // Create pattern for markers. var pattern = document.createElementNS(svgNS, 'pattern'); pattern.setAttribute('id', 'markeryellow'); pattern.setAttribute('patternUnits', 'userSpaceOnUse'); pattern.setAttribute('width', '38'); pattern.setAttribute('height', '38'); // Create image for pattern. var image = document.createElementNS(svgNS, 'image'); image.setAttribute('x', '0'); image.setAttribute('y', '0'); image.setAttribute('width', '38'); image.setAttribute('height', '38'); image.setAttributeNS(svgNSXLink, 'xlink:href', '/path/to/image.png'); // Put it together pattern.appendChild(image); var defs = svgMap.querySelector('defs') || svgMap.insertBefore(document.createElementNS(svgNS, 'defs'), svgMap.firstChild); defs.appendChild(pattern); var $markers = $(svgMap).find('.jvectormap-marker'); $.each($markers, function(i, elem) { $(elem) .attr({ 'fill': 'url(#markeryellow)' }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload