【发布时间】:2020-02-27 01:57:38
【问题描述】:
我有一系列动态生成的 SVG 图标用作传单地图上的标记。
图标采用r 编号并将其插入图像中;当图标被浏览器直接引用时,这非常有效,但是,当图标放置在 Leaflet 系统中时,图标背景图像不会显示;但我不知道为什么会这样:
SVG:
/***
* Create an SVG file using the Bronze image and apply a text as given by PHP GET clause.
***/
$rank = (int)$_GET['r'];
if($rank < 1 ) {
$rank = null;
}
header("content-type: image/svg+xml");
?>
<?xml version='1.0' encoding='utf-8'?>
<svg version='1.1' baseProfile='full' xmlns='http://www.w3.org/2000/svg' xmlns:svg='http://www.w3.org/2000/svg'
xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 20 25' xml:space='preserve' height='25' width='20'>
<image xlink:href='https://domain.co.uk/images/map_icons/bronze5_20.png' x='0' y='0' width='20' height='25' />
<text id='svgtext' x='50%' y='40%' dominant-baseline='middle' text-anchor='middle' fill='black' font-size='11px'><?php print $rank;?></text>
</svg>
传单(v1.6 当前):
var Brnz4 = L.icon({
iconUrl: '/images/map_icons/bronze.php?r=4',
iconSize: [20, 25], // size of the icon
iconAnchor: [0, 25], // point of the icon which will correspond to marker's location
popupAnchor: [0, -20] // point from which the popup should open relative to the iconAnchor
});
和
L.marker([56.224800000000000,-2.703890000000000], {icon:Brnz4} ).addTo(map)
但实际显示的只是没有背景图像的文本编号 (4)。
直接调用时背景图像加载正常。
当浏览器直接调用 SVG (PHP) 时,它会正确加载。
文本显示在正确的位置,这意味着正在读取 SVG。
我尝试了什么?
- 为
<svg>/<xml>标签添加了各种标题,如上图所示(例如视图框等)。 - 绝对网址
- 阅读this post
- 在 SVG 中使用单
'和双"引号,以防 XML 是特定于引号类型的。
图片:
标记如何与浏览器中的直接 URL 一起显示。这应该是它在地图上的显示方式。
似乎没有通过 Leaflet 加载 SVG 背景图像。为什么?
【问题讨论】:
-
你检查过
https://domain.co.uk/images/map_icons/bronze5_20.png是否有网络请求吗?我不确定嵌入在 SVG 图像中的光栅图像在这种特殊情况下应该如何工作。 -
@IvanSanchez 检查后,没有似乎没有引用外部 PNG 文件。