question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use leaflet-easyPrint in Typescript app

See original GitHub issue

I tried to import the plugin into a Typescript app and also added the code into the typings file to extend L.control from leaflet but got Uncaught TypeError: L.control.easyPrint is not a function error.

This is the code from typings file:

import 'leaflet';

declare module 'leaflet' {
    
    namespace Map {
        export interface MapOptions {
            
            easyPrintControl? : boolean;
        }
    }

    export interface ControlStatic {
        
        EasyPrint: Control.EasyPrintStatic;
    }

    namespace Control {

     
        export interface EasyPrintStatic {
            new (options?: IEasyPrintConstructorOptions): EasyPrint;
            
        }

 
        
        export interface IEasyPrintConstructorOptions {
            title: string;
            position: string;
    
        }

        export interface EasyPrint extends L.Control {
            
        }
        
    }

    export namespace control {
            export function easyPrint (options?: Control.IEasyPrintConstructorOptions): Control.EasyPrint;
    }
}

For some reason, my IDE interpretor accepts easyPrint function on L.control but my browser throws the error…

Not really sure where to go from here to be able to use the plugin

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:17 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
martinhouryforscommented, Mar 26, 2019

Hi, I think you can use easyPrint like this : First install easyPrint with npm npm install leaflet-easyprint --save

Then, use it in your typescript file.

import * as Leaflet from 'leaflet';
import 'leaflet-easyprint';
...
map : Leaflet.Map;
...
drawMap() {
        //initialize the map
        this.map = Leaflet.map('map',
            {
                center: [...],
                zoomDelta: 1,
                zoom: 14
            });       
        (Leaflet as any).easyPrint({
            title: 'My awesome print button',
            position: 'bottomleft',
            sizeModes: ['A4Portrait', 'A4Landscape']
        }).addTo(this.map);
}
...

@ialixandroae

And you should see the easyPrint control the the map

1reaction
ialixandroaecommented, Dec 10, 2019

Hi @jlaverdure-talis ,

Unfortunatelly no and I haven’t tried since. At the moment I’m not sure if this is something in the core of the library or something with my Typescript configuration (something wrong or missing?)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using leaflet-easyPrint with Typescript app
I can make it work. I did this: In my typings.d.ts // Import Leaflet into L in case you want to reference Leaflet...
Read more >
leaflet-easyprint
A simple leaflet plugin which adds an icon to print or export a map. Features. Supports resizing to prefined sizes (A4 Landscape &...
Read more >
react-leaflet-easyprint - npm package
React wrapper of leaflet-easyPrint. A simple leaflet plugin which adds an icon to print or export a map. Visit Snyk Advisor to see...
Read more >
Adding print/download option for react leaflet maps - YouTube
This video explains how to print / download a leaflet map in react.Demo + Source :https://react-component-depot.netlify. app / leaflet / print - ...
Read more >
leaflet-easyprint examples
Learn how to use leaflet-easyprint by viewing and forking leaflet-easyprint example apps on CodeSandbox.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found