gpt4 book ai didi

svg - 如何使 svg 元素显示在 safari/ios 中

转载 作者:行者123 更新时间:2023-12-02 16:19:00 25 4
gpt4 key购买 nike

我的场景:我正在显示 leaflet map 。一张 map 有多个图 block ,每个图 block 可能包含一个或多个图标。下面是图 block 的外观:

<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/NmB9bnalAAARpsPEOprSR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m/KlPs52hUKh66qNhIUzTNElRlEMej+fsQur8d+wfq09oFkuvTdQAAAAASUVORK5CYII=" style="pointer-events: auto;"></image>
</svg>

Chrome、Firefox 中的结果(通过开发工具检查):

enter image description here

但是在 Safari 中,图标不会呈现。元素在那里,但图片丢失了。截图来自browserstack适用于 Safari、iOS6。突出显示的蓝色框是元素(再次通过开发工具检查),显示该元素已就位,尺寸正确,但没有显示图像:

enter image description here

已经尝试过:

  • 对图像资源使用绝对和相对 URL 路径,而不是内联 Base64。使没有不同。该图像也托管在同一域中,没有跨域问题适用。
  • 使用 xlink:href 和 href 的各种组合(仅xlink:href,只是 href 等)。
    • 修改 image/svg 标签。添加了适当的命名空间和 xlink:href 标记(默认库仅使用 href),按照 this建议。

没有尝试过:

  • 完全替换leaflet的svg机制(比如...canvas)。大部分应用程序都依赖于 svg渲染器,所以我不想去那里。

除了替换 svg 渲染器之外,我还有其他可以尝试的建议吗?

最小可重现示例: https://jsfiddle.net/tocxvxy3/3/

最佳答案

您可以尝试直接输入 png 文件名,而不是将其嵌入到 svg 中,如传单示例 http://leafletjs.com/examples/custom-icons/ 所示。 ,也许这样ios支持更好?

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>

如果您想尝试,还有一个 iconRetinaUrl 选项

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'
});

关于svg - 如何使 svg <image> 元素显示在 safari/ios 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49609351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com