Search results

Print and Export in JavaScript Maps control

Print

The rendered map can be printed directly from the browser by calling the public method print. ID of the map div element must be passed as argument to that method.

Source
Preview
index.ts
index.html
import { Maps, MapsTooltip, DataLabel} from '@syncfusion/ej2-maps';
import { usa_map } from '../default-map-cs1/usa.ts';
Maps.Inject(MapsTooltip, DataLabel);

    let maps: Maps = new Maps({
        layers: [
            {
                dataLabelSettings: {
                    visible: true,
                    labelPath: 'name',
                    smartLabelMode: 'Trim'
                },
                shapeData: usa_map,
                shapeSettings: {
                    autofill: true
                },
                tooltipSettings: {
                    visible: true,
                    valuePath: 'name'
                },
            }
        ]
    });
    maps.appendTo('#element');
    document.getElementById('export').onclick = () => {
        maps.print();
    };
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Maps</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
    <script src="usa.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container' style="margin-top: 125px">
        <div id='element'></div>
        
        <button id= "print" type="button" width ='15%' style="float: right">Print</button>
    </div>
    
</body>

</html>
        <div class="content-wrapper">
            <div id="container"></div>
        </div>
            <div>
              <button id="togglebtn">Print</button>
            </div>

Export

The rendered map can be exported to jpeg or png format by using export method in map. Input parameters for this method are Export Type for format and fileName of result.

Source
Preview
index.ts
index.html
import { Maps, MapsTooltip, DataLabel} from '@syncfusion/ej2-maps';
import { usa_map } from '../default-map-cs1/usa.ts';
Maps.Inject(MapsTooltip, DataLabel);

    let maps: Maps = new Maps({
        layers: [
            {
                dataLabelSettings: {
                    visible: true,
                    labelPath: 'name',
                    smartLabelMode: 'Trim'
                },
                shapeData: usa_map,
                shapeSettings: {
                    autofill: true
                },
                tooltipSettings: {
                    visible: true,
                    valuePath: 'name'
                },
            }
        ]
    });
    maps.appendTo('#element');
    document.getElementById('export').onclick = () => {
        maps.export('PNG', 'Maps');
    };
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Maps</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
    <script src="usa.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container' style="margin-top: 125px">
        <div id='element'></div>
        <button id= "export" type="button" width ='15%' style="float: right">Export</button>
    </div>
</body>

</html>
        <div class="content-wrapper">
            <div id="container"></div>
        </div>
            <div>
              <button id="togglebtn">Export</button>
            </div>
Contents
Contents