0

我们有 gwt webapplication,显示地图,用 gwt-openlayers 实现。

我想实现一个函数来将当前地图导出为图像(例如 png)。

我从 openlayers 知道这个例子,但我很难用 gwt 完成它。

https://openlayers.org/en/latest/examples/export-map.html

帮助将不胜感激

4

1 回答 1

0

经过更多的试验和错误,我发现这个解决方案部分解决了我的问题: https ://stackoverflow.com/a/25486443/6919820

但是,在关闭打印对话框后,打印的布局仍然作为某种覆盖在我之前的窗口上。所以我的方法是创建一张新地图并从原始地图中复制所有相关数据。然后打印新地图并在之后将其销毁。

buttonPrint.addClickHandler(event -> {
    // mapPrintLayout contains my new MapWidget
    print(mapPrintLayout.getElement().getInnerHTML());

    mapPrintLayout.destroy(); 
});

public static final native void print(String html) /*-{
    top.consoleRef=$wnd.open('','_blank', "", false);
    top.consoleRef.document.write(html);
    top.consoleRef.print();
    top.consoleRef.close();
}-*/;

它有效,但我不相信我的方法。也许有更好的方法来做到这一点。

于 2018-12-06T07:05:05.557 回答