如何从url中加载gwt小部件中的svg [英] how to load a svg in gwt widget from an url
问题描述
我有一个提供png和svg图像的servlet。使用png我没有问题:
$ p $ Image image = new Image(GWT.getHostPageBaseURL()+ token);
但是如何让svg工作?我已经将lib-gwt-svg添加到了我的依赖项中。有一个SVGImage类:
SVGImage svg = new SVGImage(OMSVGParser.parse(???));
解析需要一个字符串。有没有一种方法可以从URL加载原始字符串?
或者如何让它工作(有或没有lib-gwt-svg)? p>
更新:
thx给Andrei Volgin:他指出它应该与Image一起使用,它确实(我只需要将mime类型更正为image / svg + xml)。但是svg-image中的脚本不能以这种方式工作(它看起来就像是一个普通的位图图像)。
我需要将图像呈现为svg(带脚本)。
我找到了一个无需任何外部库(像安德烈的解决方案),但也保持嵌入式脚本的工作。我使用了这里的信息 - 我使用了一个HTMLPanel并通过RequestBuilder加载图片:
$ b $ pre $ String $ url = GWT.getHostPageBaseURL() + link.getToken();
RequestBuilder rB =新的RequestBuilder(RequestBuilder.GET,url);
rB.setCallback(new RequestCallback(){
@Override
public void onResponseReceived(Request request,Response response){
// create Widget
chartImage = new HTMLPanel(response.getText());
//添加到布局
layout.add(chartImage);
}
@覆盖
public void onError(请求请求,Throwable异常){
// TODO自动生成的方法存根
}
});
I have a servlet that delivers png and svg images. With png i have no problem:
Image image = new Image(GWT.getHostPageBaseURL() + token);
But how to get svg to work? I already added "lib-gwt-svg" to my dependencies. There is a SVGImage class:
SVGImage svg = new SVGImage(OMSVGParser.parse(???));
The parse takes a string. Is there a way to load a raw String from an URL?
Or how to get it to work (with or without "lib-gwt-svg")?
Update: thx to Andrei Volgin: he pointed out that it should work with "Image" and it does (i just had to correct the mime type to "image/svg+xml"). But the scripts within svg-image don't work this way (it looks like the images is rendered as a normal bitmap image). I need the image rendered as svg (with scripts).
I found a solution that works without any external library (like Andrei's Solution) but keeps also the embedded scripts working. I used the info from here - i used a HTMLPanel and loaded the image via "RequestBuilder":
String url = GWT.getHostPageBaseURL() + link.getToken();
RequestBuilder rB = new RequestBuilder(RequestBuilder.GET, url);
rB.setCallback(new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
//create Widget
chartImage = new HTMLPanel(response.getText());
//add to layout
layout.add(chartImage);
}
@Override
public void onError(Request request, Throwable exception) {
// TODO Auto-generated method stub
}
});
这篇关于如何从url中加载gwt小部件中的svg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!