Hello,
I would like to create a PDF report with a leaflet map (as well as other sections with text and tables).
The map should display the same view that the user had set in a screen (vector layers, raster layers, bounding box, zoom, etc.).
I’ve tried to use the vaadin “Html2Canvas Screenshot” addon (https://vaadin.com/directory/component/html2canvas-screenshot), in order to transform the map div into an image and insert it into the report, but when I try to take the screenshot doesn’t seem to have any effect.
I followed the guide “3.5.17.4.1. Using a Third-party Vaadin Component” (Using a Third-party Vaadin Component - CUBA Platform. Developer’s Manual) and tried to associate this code with the click of a button:
final Screenshot screenshot = Screenshot.newBuilder()
.withMimeType(ScreenshotMimeType.PNG)
.build();
screenshot.setTargetComponent(boxSwitch3.unwrap(Layout.class));
screenshot.addScreenshotListener(image -> {
final Image img = uiComponents.create(Image.class);
img.setSizeFull();
img.setScaleMode(Image.ScaleMode.FILL);
try {
img.setSource(StreamResource.class)
.setStreamSupplier(() -> new ByteArrayInputStream(image.getImageData()))
.setBufferSize(1024);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
CmcUtils.showFotoScreen(img,"Screenshot");
});
screenshot.takeScreenshot();
The listener never seems to get called.
Am I using a wrong approach?
I’ve also seen that there is a leaflet plugin to print a map (https://github.com/rowanwins/leaflet-easyPrint) but I don’t know how to implement it on Cuba Platform.
Do you have any ideas about it?
Thank in advance.
Best Regards,
Paolo