9

My scenario: I'm displaying a leaflet map. A map has several tiles, each tile might contain one or more icons. Here is how a tile might look like:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" pointer-events="none" width="256" height="256" viewBox="0 0 256 256" class="leaflet-tile leaflet-tile-loaded" style="width: 256px; height: 256px; transform: translate3d(455px, -4px, 0px); opacity: 1;">
    <g></g>
    <image x="213.9375" y="252.875" width="19px" height="19px" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAOxAAADsQBlSsOGwAAA/1JREFUWIXll21olWUYx3/Py9nZc8523uZyW+Z8gVXK3Dw2iJx0ilGGKVOnOIp0RJjRhyDWSAgJI4R9mA2hpohGVKizpQZGG4MWM5ZntnK1mQutdQz3ctzOzs778zx9sJ1tsJdzju5DdH26r+u+r+v/4+J57hf4v5swMcjLy9sVDAarBUFQF1JQ13XJZDId8ng8Z6YBOByOKzU1NWudTudC6uN2u6mtrXV7vd4SAHnKXMzpdFJWVpZYJV0j0N1I+EYbtk11CJIhoTRVVRFFMd5lea7Fs1n4Zhu+1veIDvx6NyCI2DfXp1IqOYDoYC++1oOEb3w7LR785QtkWz6ZG95cGADVf5uxtloCV0+Drs24Zqy9Dsm2FFPhjvsHoEfG8Xd8iP+HBvRocN5ioxerkSx5GPPXJwwgziJNoOtTbjeUMtZ+OCFxAF2LcafpFWLD1+8RQFMJ9pxDGx9MuFA8NeRj+PRLCefOCDB2qR7LM+8jLypIGgBAHe3H21iFHgulBhAbusbIuX04yj9CylicEkTk7y7unH991o92TgBdU4kO9DDacgB7xUmEtIyUIEK/fY2v9WDyABPU4ZvfEXAfx7HtKIKY0p6F//Ixxq+cTBJAmAwHuhuJ/NmB9bnalAAARpsPEOprSRzAsqEa0ZgZ98cufQBqNKWdDkA0ZqAFvYkDyNkPY992fNoBM/LNftJyizEVVSauLEiYnbvJqjyFYDAnDgBgzH8C26Y64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rome,Firefox (inspected via devtools):

enter image description here

In Safari however, the icons are not rendered. The element is there, but the picture is missing. Screenshot from browserstack for safari, ios6. The highlighted blue box is the element (inspected via devtools again), showing that the element is in position, with the correct dimensions, but no image is showing:

enter image description here

What I have tried:

  • Using absolute and relative url paths for the image resource instead of inline base64. Makes no difference. The image is also hosted on the same domain, no cross-domain issues apply.
  • Using various combinations of xlink:href and href (just xlink:href, just href, etc).
    • Modifying the image/svg tag. Added the appropriate namespaces and the xlink:href tag (default library only used href), as per this suggestion.

What I haven't tried:

  • Completely replacing the svg mechanism of leaflet with another (say...canvas). Much of the application relies on the svg renderer, so I'd rather not go there.

Are there any other suggestions I could try except replacing the svg renderer?

Minimum reproducible example: https://jsfiddle.net/tocxvxy3/3/

pkExec
  • 1,752
  • 1
  • 20
  • 39

1 Answers1

1

You could try to directly put the png file name, intead of embbeding it in svg, as in leaflet examples http://leafletjs.com/examples/custom-icons/ , maybe the ios support is better this way?

var map = L.map('map').setView([51.5, -0.09], 13);

 L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
 }).addTo(map);

 var LeafIcon = L.Icon.extend({
  options: {
   shadowUrl: 'leaf-shadow.png',
   iconSize:     [50, 50],
   shadowSize:   [50, 64],
   iconAnchor:   [22, 94],
   shadowAnchor: [4, 62],
   popupAnchor:  [-3, -76]
  }
 });

 var greenIcon = new LeafIcon({iconUrl: 'https://memegenerator.net/img/images/50x50/7452314.jpg', iconRetinaUrl: 'https://static01.nyt.com/images/2012/09/14/blogs/Fils-Aime/Fils-Aime-thumbLarge.jpg'});

 L.marker([51.5, -0.09], {icon: greenIcon}).addTo(map);
html, body {
  height: 100%;
  margin: 0;
}
#map {
  width: 600px;
  height: 400px;
}
<link href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css" rel="stylesheet"/>
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js"></script>
<div id='map'></div>

There's also an iconRetinaUrl option if you want to try

var greenIcon = new LeafIcon({
  iconUrl: 'https://memegenerator.net/img/images/50x50/7452314.jpg',
  iconRetinaUrl: 'https://static01.nyt.com/images/2012/09/14/blogs/Fils-Aime/Fils-Aime-thumbLarge.jpg'
});
Valentin
  • 76
  • 4
  • As I said in the question, I've already tried it: "Using absolute and relative url paths for the image resource instead of inline base64. Makes no difference. " – pkExec Apr 09 '18 at 03:40