外部加载的 SVG 在 IE 中损坏 (Raphael JS)
我使用 jQuery 加载外部 SVG(法国地图)并将其解析为带有以下代码的 raphaël.js 路径。但它在 IE 中没有做任何事情。有什么想法吗?
$(document).ready(function(){
var paper = Raphael("canvas", 450, 380);
var map = paper.set();
// load svgz map
$.ajax({
type: "GET",
url: "map-smllr.svgz",
dataType: "xml",
success: parseXml
});
// ... removed a few other variables
function parseXml(xml) {
var count = 0;
$(xml).find("g").children("path").each(function()
{
var deptNr = depts[count];
var path = $(this).attr("d");
var c = paper.path(path);
c.attr(attr).attr("title",deptNr);
map.push(c);
count++;
});
//startMap();
}
});
您可以在此处查看完整来源:http://ngjulie.com/map/raphael.html
我在 Chrome 中也遇到了一个奇怪的缓存问题,在用户将鼠标悬停在画布上之前,会显示一个空白点。
但最大的问题是这在 IE 中不起作用。 RaphaelJS 网站上的一般示例运行良好。所以它一定是我的代码中的东西。
有什么想法吗?
干杯, 朱莉
I am using jQuery to load an external SVG (a map of France) and parse it into paths with raphaël.js the following code. But it is not doing anything in IE. Any ideas?
$(document).ready(function(){
var paper = Raphael("canvas", 450, 380);
var map = paper.set();
// load svgz map
$.ajax({
type: "GET",
url: "map-smllr.svgz",
dataType: "xml",
success: parseXml
});
// ... removed a few other variables
function parseXml(xml) {
var count = 0;
$(xml).find("g").children("path").each(function()
{
var deptNr = depts[count];
var path = $(this).attr("d");
var c = paper.path(path);
c.attr(attr).attr("title",deptNr);
map.push(c);
count++;
});
//startMap();
}
});
You can view a full source here: http://ngjulie.com/map/raphael.html
I have a funky caching issue in Chrome too, where a blank spot is shown until the user hovers over the canvas.
But the biggest problem is that this is not working in IE. The general examples on the RaphaelJS website work fine. So it must be something in my code.
Any ideas?
Cheers,
Julie
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它似乎不起作用,因为 svgz 和 svg 图像正在使用 image/svg+xml mimetype 提供服务,这会导致 IE XML 解析器失败(如果在 $.ajax 调用中设置错误条件,您将看到这种情况发生了——无论如何,这是一个很好的做法)。同样,如果您导航到 http://ngjulie.com/map/map-smllr.svgz 或 http://ngjulie.com/map/map-smllr.svg 中在 IE 中,您会看到它尝试下载该文件,而不是使用 IE XML 解析器组件来解析该文件。
我认为如果您使用 text/xml 或 application/xml mimetype 提供文件,它可能应该可以工作。我通过将map-smllr.svgz重命名为map-smllr.xml来快速测试这一点,从而使我的Web服务器可以轻松地以正确的mime类型提供文件。如果您在 IE8 中导航到该文件,您将看到它被解析为 XML。同样,XHR GET 成功,并且能够解析文件。其他一切都会按预期工作。
It seems not to be working because the svgz and svg images are being served with an image/svg+xml mimetype, which is causing the IE XML parser to fail (if set an error condition in the $.ajax call, you'll see this happening - this good practice anyways). Likewise, if you navigate to http://ngjulie.com/map/map-smllr.svgz or http://ngjulie.com/map/map-smllr.svg in IE, you'll see it attempts to download the file, rather than parsing it with the IE XML parser component.
I think if you serve the files with a text/xml or application/xml mimetype it should probably work. I tested this quickly by renaming map-smllr.svgz to map-smllr.xml, thus making it easy for my web server to serve the file with the correct mimetype. If you navigate to that file in IE8, you'll see that it gets parsed as XML. Likewise, the XHR GET succeeds, and is able to parse the file. Everything else then works as expected.