在标记图标中使用带参数的svg(Using a svg with params in a marker icon)

编程入门 行业动态 更新时间:2024-10-26 07:30:55
在标记图标中使用带参数的svg(Using a svg with params in a marker icon)

我有一个svg文件接受参数来旋转自己,它使用html中的对象标签中的这种语法工作正常:

<object id="myicon" data="../static/images/icons/icon.svg?trans=rotate(75 16 16)" type="image/svg+xml"></object>

但是,如果我尝试像图标一样使用它,则不起作用,只显示默认图像标题。

markers[0].set("icon", "../static/images/icons/icon.svg?trans=rotate(75 16 16)")

要么

markers[0].setIcon("../static/images/icons/icon.svg?trans=rotate(75 16 16)")

要么

markers[0].setIcon("../static/images/icons/icon.svg?trans=rotate(75+16+16)")

这不是缓存问题,如果我检查生成的html代码,我可以看到指向图像的完整url:

<img src="../static/images/icons/icon.svg?trans=rotate(75 16 16)" draggable="false" style="position: absolute; left: 0px; top: 0px; -webkit-user-select: none; width: auto; height: auto; border: 0px; padding: 0px; margin: 0px;">

我错过了什么?我想在任何程度上干净地旋转图标。 谢谢。

PD:如果我在生成的代码中按照新的chrome选项卡中的图片链接,我可以看到具有正确标题的图像,并将url映射到:

/images/icons/icon.svg?trans=rotate(75%2016%2016)

但只能远离地图。

I have a svg file that accept parameters to rotate himself and it works fine using this syntax in an object tag in html:

<object id="myicon" data="../static/images/icons/icon.svg?trans=rotate(75 16 16)" type="image/svg+xml"></object>

But if I try to use it like an icon, doesn't work, showing only the default image heading.

markers[0].set("icon", "../static/images/icons/icon.svg?trans=rotate(75 16 16)")

or

markers[0].setIcon("../static/images/icons/icon.svg?trans=rotate(75 16 16)")

or

markers[0].setIcon("../static/images/icons/icon.svg?trans=rotate(75+16+16)")

It isn't a cache problem, if I inspect the html code generated I can see the complete url pointing to the image:

<img src="../static/images/icons/icon.svg?trans=rotate(75 16 16)" draggable="false" style="position: absolute; left: 0px; top: 0px; -webkit-user-select: none; width: auto; height: auto; border: 0px; padding: 0px; margin: 0px;">

What am I missing?, I want rotate the icon cleanly in any degree. Thanks.

PD: If I follow the image link in a new chrome tab from the generated code I can see the image with the right heading and the url is mapped to:

/images/icons/icon.svg?trans=rotate(75%2016%2016)

but works away of a map only.

最满意答案

出于隐私的原因,如果您使用SVG作为图像,即通过SVG <image>标记,HTML <img>标记或作为背景图像引用它,那么JavaScript将被禁用。

For privacy reasons if you use SVG as an image i.e. you reference it via an SVG <image> tag, an HTML <img> tag or as a background image then amongst other things, javascript will be disabled.

更多推荐

本文发布于:2023-07-29 18:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1318606.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图标   标记   参数   svg   marker

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!