我有一个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.
更多推荐
发布评论