0

We have gwt webapplication, showing map, implemented with gwt-openlayers.

I would like to implement a function to export the current map as an image (for example png).

I'm aware of this example from openlayers, but I struggle getting it done with gwt.

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

Help would be appreciated

EricN
  • 1
  • 1

1 Answers1

0

After more trial & error I found this solution which partly solves my problem: https://stackoverflow.com/a/25486443/6919820

However, after closing the print dialog, the printed layout remains as some kind of overlay on my previous window. So my approach was to create a new map and copy all relevant data from the original one. Then print the new map and destroy it afterwards.

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();
}-*/;

It works, but I'm not convinced by my approach. Maybe there are better ways to do it.

EricN
  • 1
  • 1