TransWikia.com

React leaflet map print

Geographic Information Systems Asked by Sashini Hettiarachchi on May 25, 2021

I want to print a leaflet map in PDF/Image formats and It will be contained,

  • WMS layers
  • Polygon, Markers, Polylines etc

I’m using a leaflet map with React Typescript. Related versions are,

  • react-leaflet – 2.7.0
  • react – 16.13.1
  • leaflet – 1.6.0

I tried https://leafletjs.com/plugins.html#printexport leaflet-easyprint and leaflet.browser.print but didn’t get a promising result.

  1. https://www.npmjs.com/package/react-leaflet-easyprint
import { Map, withLeaflet} from "react-leaflet";

import PrintControlDefault from 'react-leaflet-easyprint';

const PrintControl = withLeaflet(PrintControlDefault as any);

 <Map>
    <PrintControl ref={printMapRef} 
     position="topleft" 
     sizeModes={['Current', 'A4Portrait', 'A4Landscape']} 
     hideControlContainer={false} />
 </Map>

Typescript Error:

Type ‘{ ref: MutableRefObject; position: string; sizeModes: string[]; hideControlContainer: boolean; }’ is not assignable to type ‘IntrinsicAttributes & Omit<ContextProps, "leaflet"> & { children?: ReactNode; }’.
Property ‘ref’ does not exist on type ‘IntrinsicAttributes & Omit<ContextProps, "leaflet"> & { children?: ReactNode; }’.

  1. https://github.com/Igor-Vladyka/leaflet.browser.print
importLfrom"leaflet";
import {​​​​​ useLeaflet }​​​​​ from"react-leaflet";
const {​​​​​ map }​​​​​ = useLeaflet();

(L as any).control.browserPrint({​​​​​
position:'topright'
}​​​​​).addTo(map);

This works fine, but cannot print WMS layers.

Does anyone have an idea about any plugin or library which is match with above-mentioned conditions?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP