Search results

User Interactions in JavaScript Maps control

22 Oct 2021 / 15 minutes to read

Zooming, panning, single and double click, highlight and selection are all options that allow for effective interaction with Map elements.

Zooming

The zooming feature is used to zoom in and out of Maps to show in-depth information. It is controlled by the zoomFactor property of the zoomSettings of the Maps. The zoomFactor is increased or decrease dynamically based on zoom in and out interaction.

Enable zooming

Zooming of Maps is enabled by setting the enable property of zoomSettings to true. To enable Zooming in Maps, the Zoom module must be injected into Maps using Maps.Inject(Zoom) method. The following code snippet demonstrates injecting the Zoom module into the Maps component.

Copied to clipboard
import { Maps, Zoom } from '@syncfusion/ej2-maps';
Maps.Inject(Zoom);
let map: Maps = new Maps({ });

Enable panning

To enable the panning feature, set the enablePanning property of zoomSettings to true.

Copied to clipboard
import { world_map } from './world-map.ts';
import { Maps, Zoom } from '@syncfusion/ej2-maps';
Maps.Inject(Zoom);
let map: Maps = new Maps({
    layers: [{
        shapeData: world_map,
    }],
    zoomSettings:{
        enable:true,
        enablePanning:true
    }
});
map.appendTo('#element');

Various type of zooming

Zooming can be performed in following types:

Zooming toolbar

By default, the toolbar is rendered with zoom-in, zoom-out, and reset options when it is set to true in the enable property of zoomSettings.

The following options are available in toolbar.

  1. Zoom - Provides rectangular zoom support.
  2. ZoomIn - Zoom in the Maps.
  3. ZoomOut - Zoom out the Maps.
  4. Pan - Switches to panning if rectangular zoom is activated.
  5. Reset - Restores the Maps to the default view.

The following properties are available in toolbars to customize the zooming toolbars.

  • color - Applies the color for toolbars in Maps.
  • highlightColor - Applies the color for the zooming toolbar when the mouse has hovered on the toolbar element in Maps.
  • horizontalAlignment - To customize the position type of toolbar when it is placed horizontally.
  • selectionColor - Applies the color for the zooming toolbar when clicking the zooming toolbar in Maps.
  • toolBarOrientation - To customize the orientation of the zooming toolbar.
  • toolbars - To customize the items that are to be shown in the zooming toolbar in Maps.
  • verticalAlignment - To customize the position type of toolbar when it is placed vertically.
Copied to clipboard
import { usmap } from 'usa.ts';
import { Maps, Zoom } from '@syncfusion/ej2-maps';
Maps.Inject(Zoom);
let map: Maps = new Maps({
zoomSettings: {
    enable: true,
    color: 'green',
    highlightColor: 'blue',
    selectionColor: 'orange',
    horizontalAlignment: 'Center',
    toolbars: ['ZoomIn', 'ZoomOut', 'Pan', 'Reset']
},
layers: [{
    shapeData: usmap,
}]
});
map.appendTo('#element');

Pinch zooming

To enable or disable the pinch zooming, use the pinchZooming property in zoomSettings.

Copied to clipboard
import { usmap } from 'usa.ts';
import { Maps, Zoom } from '@syncfusion/ej2-maps';
Maps.Inject(Zoom);
let map: Maps = new Maps({
zoomSettings: {
    enable: true,
    pinchZooming: true
},
layers: [{
    shapeData: usmap,
}]
});
map.appendTo('#element');

Single-click zooming

To enable or disable the single-click zooming, use the zoomOnClick property in zoomSettings.

Copied to clipboard
import { usmap } from 'usa.ts';
import { Maps, Zoom } from '@syncfusion/ej2-maps';
Maps.Inject(Zoom);
let map: Maps = new Maps({
zoomSettings: {
    enable: true,
    zoomOnClick: true
},
layers: [{
    shapeData: usmap,
}]
});
map.appendTo('#element');

Double-click zooming

To enable or disable the double-click zooming, use the doubleClickZoom property in zoomSettings.

Copied to clipboard
import { usmap } from 'usa.ts';
import { Maps, Zoom } from '@syncfusion/ej2-maps';
Maps.Inject(Zoom);
let map: Maps = new Maps({
zoomSettings: {
    enable: true,
    doubleClickZoom: true
},
layers: [{
    shapeData: usmap,
}]
});
map.appendTo('#element');

Mouse wheel zooming

To enable or disable mouse wheel zooming, use the mouseWheelZoom property in zoomSettings.

Copied to clipboard
import { usmap } from 'usa.ts';
import { Maps, Zoom } from '@syncfusion/ej2-maps';
Maps.Inject(Zoom);
let map: Maps = new Maps({
zoomSettings: {
    enable: true,
    mouseWheelZoom: true
},
layers: [{
    shapeData: usmap,
}]
});
map.appendTo('#element');

Selection zooming

To enable or disable selection zooming, use the enableSelectionZooming property in zoomSettings. The enablePanning property must be set to false to enable the selection zooming in Maps.

Copied to clipboard
import { usmap } from 'usa.ts';
import { Maps, Zoom } from '@syncfusion/ej2-maps';
Maps.Inject(Zoom);
let map: Maps = new Maps({
zoomSettings: {
    enable: true,
    enableSelectionZooming: true,
    enablePanning: false
},
layers: [{
    shapeData: usmap,
}]
});
map.appendTo('#element');

Minimum and maximum zooming

The zooming range can be adjusted using the minZoom and maxZoom properties in zoomSettings. The minZoom value is set to 1 by default, and the maxZoom value is set to 10.

Copied to clipboard
import { usmap } from 'usa.ts';
import { Maps, Zoom } from '@syncfusion/ej2-maps';
Maps.Inject(Zoom);
let map: Maps = new Maps({
zoomSettings: {
    enable: true,
    minZoom: 2,
    maxZoom: 12
},
layers: [{
    shapeData: usmap,
}]
});
map.appendTo('#element');

Zooming with animation

To zoom in or zoom out the Maps with animation, use the animationDuration property in layers.

Copied to clipboard
import { usmap } from 'usa.ts';
import { Maps, Zoom } from '@syncfusion/ej2-maps';
Maps.Inject(Zoom);
let map: Maps = new Maps({
zoomSettings: {
    enable: true,
},
layers: [{
    shapeData: usmap,
    animationDuration: 500
}]
});
map.appendTo('#element');

Selection

Each shape in the Maps can be selected and deselected during interaction with the shapes. Selection is enabled by setting the enable property of selectionSettings to true. To enable selection in Maps, the Selection module must be injected into the Maps using Maps.Inject(Selection) method.

Copied to clipboard
import { Maps, Selection } from '@syncfusion/ej2-maps';
Maps.Inject(Selection);
let map: Maps = new Maps({ });

The following properties are available to customize the selection of Map elements such as shapes, bubbles, markers and legends.

  • border - To customize the color, width and opacity of the border of which element is selected in Maps.
  • fill - Applies the color for the element that is selected.
  • opacity - To customize the transparency for the element that is selected.
  • enableMultiSelect - To enable or disable the selection for multiple shapes or markers or bubbles in the Maps.

By tapping on the specific legend, the shapes which are bounded to the selected legend is also selected and vice versa.

Source
Preview
index.ts
index.html
Copied to clipboard
import { world_map } from './world-map.ts';
import { Maps, Selection, Legend } from '@syncfusion/ej2-maps';
Maps.Inject(Selection, Legend);
let map: Maps = new Maps({
layers: [
    {
        shapeData: world_map,
        dataSource: [{  "Country": "China", "Membership": "Permanent"},
        {"Country": "France","Membership": "Permanent" },
        { "Country": "Russia","Membership": "Permanent"},
        {"Country": "Kazakhstan","Membership": "Non-Permanent"},
        { "Country": "Poland","Membership": "Non-Permanent"},
        {"Country": "Sweden","Membership": "Non-Permanent"}],
        shapePropertyPath: 'name',
        shapeDataPath: 'Country',
        selectionSettings: {
           enable: true,
           fill: 'blue',
           border: { color: 'white', width: 2}
        },
        shapeSettings: {
            colorValuePath: 'Membership',
            colorMapping: [
            {
                value: 'Permanent', color: '#D84444'
            },
            {
                value: 'Non-Permanent', color: '#316DB5'
            }]

        }
    }
],
legendSettings: {
    visible: true
}
});
map.appendTo('#element');
Copied to clipboard
<!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="world-map.js"></script>
    <script src="usa.js"></script>
    <script src="data.js"></script>
    <script src="california.js"></script>
    <script src="texas.js"></script>
    <script src="africa_continent.js"></script>
    <script src="africa.js"></script>
    <script src="cluster.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container' style="height: 500px; width: 700px">
        <div id='element'></div>
    </div>
    <svg height="150" width="400">
        <defs>
            <linearGradient id="grad1" x1="0%" y1="0%" x2="0%" y2="100%">
                <stop offset="0%" style="stop-color:#C5494B;stop-opacity:1" />
                <stop offset="100%" style="stop-color:#4C134F;stop-opacity:1" />
            </linearGradient>
        </defs>
    </svg>
    <!-- annotation content -->
    <div id="maps-annotation" style="display: none;">
        <div id="annotation">
            <div>
                <p style="margin-left:10px;font-size:13px;font-weight:500">Facts about Africa</p>
            </div>
            <hr style="margin-top:-3px;margin-bottom:10px;border:0.5px solid #DDDDDD">
            <div>
                <ul style="list-style-type:disc; margin-left:-20px;margin-bottom:2px; font-weight:400">
                    <li>Africa is the second largest and second most populated continent in the world.</li>
                    <li style="padding-top:5px;">Africa has 54 sovereign states and 10 non-sovereign territories.</li>
                    <li style="padding-top:5px;">Algeria is the largest country in Africa, where as Mayotte is the smallest.</li>
                </ul>
            </div>
        </div>
    </div>
    <div id="compass-maps" style="display: none;">
        <img src="templates/maps/how-to/annotation/compass.png" height="75px" width="75px">
    </div>
    <style>
        #annotation {
            color: #DDDDDD;
            font-size: 12px;
            font-family: Roboto;
            background: #3E464C;
            margin: 20px;
            padding: 10px;
            -webkit-border-radius: 2px;
            -moz-border-radius: 2px;
            border-radius: 2px;
            width: 300px;
            -moz-box-shadow: 0px 2px 5px #666;
            -webkit-box-shadow: 0px 2px 5px #666;
            box-shadow: 0px 2px 5px #666;
        }
        .country-label {
            color: white;
            font-size: 25px;
        }
    </style>
</body>

</html>

Enable selection for bubbles

To enable the selection for bubbles in Maps, set the selectionSettings in bubbleSettings and set the enable property of selectionSettings as true.

Note: To use the bubble feature, the Bubble module must be injected.

Source
Preview
index.ts
index.html
Copied to clipboard
import { world_map } from './world-map.ts';
import { Maps, Bubble, Selection } from '@syncfusion/ej2-maps';
Maps.Inject(Selection, Bubble);
let map: Maps = new Maps({
layers: [{
    shapeData: world_map,
    shapeDataPath: 'name',
    shapePropertyPath: 'name',
    bubbleSettings: [{
        visible: true,
        dataSource: [
            { name: 'India', population: '38332521' },
            { name: 'South Africa', population: '19651127' },
            { name: 'Pakistan', population: '3090416' }
        ],
        selectionSettings: {
            enable: true,
            fill: 'green',
            border: { color: 'white', width: 2}
        },
        valuePath: 'population'
    }]
}]
});
map.appendTo('#element');
Copied to clipboard
<!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="world-map.js"></script>
    <script src="usa.js"></script>
    <script src="data.js"></script>
    <script src="california.js"></script>
    <script src="texas.js"></script>
    <script src="africa_continent.js"></script>
    <script src="africa.js"></script>
    <script src="cluster.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container' style="height: 500px; width: 700px">
        <div id='element'></div>
    </div>
    <svg height="150" width="400">
        <defs>
            <linearGradient id="grad1" x1="0%" y1="0%" x2="0%" y2="100%">
                <stop offset="0%" style="stop-color:#C5494B;stop-opacity:1" />
                <stop offset="100%" style="stop-color:#4C134F;stop-opacity:1" />
            </linearGradient>
        </defs>
    </svg>
    <!-- annotation content -->
    <div id="maps-annotation" style="display: none;">
        <div id="annotation">
            <div>
                <p style="margin-left:10px;font-size:13px;font-weight:500">Facts about Africa</p>
            </div>
            <hr style="margin-top:-3px;margin-bottom:10px;border:0.5px solid #DDDDDD">
            <div>
                <ul style="list-style-type:disc; margin-left:-20px;margin-bottom:2px; font-weight:400">
                    <li>Africa is the second largest and second most populated continent in the world.</li>
                    <li style="padding-top:5px;">Africa has 54 sovereign states and 10 non-sovereign territories.</li>
                    <li style="padding-top:5px;">Algeria is the largest country in Africa, where as Mayotte is the smallest.</li>
                </ul>
            </div>
        </div>
    </div>
    <div id="compass-maps" style="display: none;">
        <img src="templates/maps/how-to/annotation/compass.png" height="75px" width="75px">
    </div>
    <style>
        #annotation {
            color: #DDDDDD;
            font-size: 12px;
            font-family: Roboto;
            background: #3E464C;
            margin: 20px;
            padding: 10px;
            -webkit-border-radius: 2px;
            -moz-border-radius: 2px;
            border-radius: 2px;
            width: 300px;
            -moz-box-shadow: 0px 2px 5px #666;
            -webkit-box-shadow: 0px 2px 5px #666;
            box-shadow: 0px 2px 5px #666;
        }
        .country-label {
            color: white;
            font-size: 25px;
        }
    </style>
</body>

</html>

Enable selection for markers

To enable the selection for markers in Maps, set the selectionSettings in the markerSettings and set the enable property of the selectionSettings as true.

To use the marker feature, the Marker module must be injected.

Source
Preview
index.ts
index.html
Copied to clipboard
import { world_map } from './world-map.ts';
import { Maps, Marker, Selection } from '@syncfusion/ej2-maps';
Maps.Inject(Selection, Marker);
let map: Maps = new Maps({
layers: [{
    shapeData: world_map,
    markerSettings: [{
        visible: true,
        height: 20,
        width: 20,
        fill: 'green',
        shape:'Balloon',
        selectionSettings: {
            enable: true,
            fill: 'blue',
            border: { color: 'white', width: 2}
        },
        dataSource: [
            { latitude: 49.95121990866204, longitude: 18.468749999999998, name:'Europe' },
            { latitude: 59.88893689676585, longitude: -109.3359375, name:'North America'},
            { latitude: -6.64607562172573, longitude: -55.54687499999999, name:'South America'}
        ]
    }],
}]
});
map.appendTo('#element');
Copied to clipboard
<!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="world-map.js"></script>
    <script src="usa.js"></script>
    <script src="data.js"></script>
    <script src="california.js"></script>
    <script src="texas.js"></script>
    <script src="africa_continent.js"></script>
    <script src="africa.js"></script>
    <script src="cluster.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container' style="height: 500px; width: 700px">
        <div id='element'></div>
    </div>
    <svg height="150" width="400">
        <defs>
            <linearGradient id="grad1" x1="0%" y1="0%" x2="0%" y2="100%">
                <stop offset="0%" style="stop-color:#C5494B;stop-opacity:1" />
                <stop offset="100%" style="stop-color:#4C134F;stop-opacity:1" />
            </linearGradient>
        </defs>
    </svg>
    <!-- annotation content -->
    <div id="maps-annotation" style="display: none;">
        <div id="annotation">
            <div>
                <p style="margin-left:10px;font-size:13px;font-weight:500">Facts about Africa</p>
            </div>
            <hr style="margin-top:-3px;margin-bottom:10px;border:0.5px solid #DDDDDD">
            <div>
                <ul style="list-style-type:disc; margin-left:-20px;margin-bottom:2px; font-weight:400">
                    <li>Africa is the second largest and second most populated continent in the world.</li>
                    <li style="padding-top:5px;">Africa has 54 sovereign states and 10 non-sovereign territories.</li>
                    <li style="padding-top:5px;">Algeria is the largest country in Africa, where as Mayotte is the smallest.</li>
                </ul>
            </div>
        </div>
    </div>
    <div id="compass-maps" style="display: none;">
        <img src="templates/maps/how-to/annotation/compass.png" height="75px" width="75px">
    </div>
    <style>
        #annotation {
            color: #DDDDDD;
            font-size: 12px;
            font-family: Roboto;
            background: #3E464C;
            margin: 20px;
            padding: 10px;
            -webkit-border-radius: 2px;
            -moz-border-radius: 2px;
            border-radius: 2px;
            width: 300px;
            -moz-box-shadow: 0px 2px 5px #666;
            -webkit-box-shadow: 0px 2px 5px #666;
            box-shadow: 0px 2px 5px #666;
        }
        .country-label {
            color: white;
            font-size: 25px;
        }
    </style>
</body>

</html>

Public method for the shape selection

The shapeSelection method can be used to select each shape in the Maps. LayerIndex, propertyName, country name, and selected value as a boolean state(true / false) are the input parameters for this method.

Source
Preview
index.ts
index.html
Copied to clipboard
import { world_map } from '../default-map-cs1/world-map.ts';
import { Maps, Selection } from '@syncfusion/ej2-maps';
Maps.Inject(Selection);
let map: Maps = new Maps({
layers: [{
    shapeData: world_map,
    selectionSettings: {
        enable: true,
        fill: 'green',
        border: { color: 'white', width: 2}
    }
}]
});
map.appendTo('#element');
document.getElementById('selection').onclick = () => {
map.shapeSelection(0, "continent", "Asia", true);
};
document.getElementById('unselection').onclick = () => {
map.shapeSelection(0, "continent", "Asia", false);
};
Copied to clipboard
<!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= "selection" type="button" width ='15%'>Select</button>
		<button id= "unselection" type="button" width ='15%'>UnSelect</button>
    </div>
</body>

</html>

Initial shape selection

The shape is initially selected using the initialShapeSelection property, and the values are mapped to the shapePath and shapeValue.

initialShapeSelection is an Array property.

Source
Preview
index.ts
index.html
Copied to clipboard
import { world_map } from './world-map.ts';
import { Maps, Selection } from '@syncfusion/ej2-maps';
Maps.Inject(Selection);
let map: Maps = new Maps({
layers: [{
    shapeData: world_map,
    initialShapeSelection: [
        { shapePath: 'continent', shapeValue: 'Africa' },
        { shapePath: 'name', shapeValue: 'India' }
    ],
    selectionSettings: {
        enable: true,
        fill: 'green',
        border: { color: 'white', width: 2}
    }
}]
});
map.appendTo('#element');
Copied to clipboard
<!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="world-map.js"></script>
    <script src="usa.js"></script>
    <script src="data.js"></script>
    <script src="california.js"></script>
    <script src="texas.js"></script>
    <script src="africa_continent.js"></script>
    <script src="africa.js"></script>
    <script src="cluster.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container' style="height: 500px; width: 700px">
        <div id='element'></div>
    </div>
    <svg height="150" width="400">
        <defs>
            <linearGradient id="grad1" x1="0%" y1="0%" x2="0%" y2="100%">
                <stop offset="0%" style="stop-color:#C5494B;stop-opacity:1" />
                <stop offset="100%" style="stop-color:#4C134F;stop-opacity:1" />
            </linearGradient>
        </defs>
    </svg>
    <!-- annotation content -->
    <div id="maps-annotation" style="display: none;">
        <div id="annotation">
            <div>
                <p style="margin-left:10px;font-size:13px;font-weight:500">Facts about Africa</p>
            </div>
            <hr style="margin-top:-3px;margin-bottom:10px;border:0.5px solid #DDDDDD">
            <div>
                <ul style="list-style-type:disc; margin-left:-20px;margin-bottom:2px; font-weight:400">
                    <li>Africa is the second largest and second most populated continent in the world.</li>
                    <li style="padding-top:5px;">Africa has 54 sovereign states and 10 non-sovereign territories.</li>
                    <li style="padding-top:5px;">Algeria is the largest country in Africa, where as Mayotte is the smallest.</li>
                </ul>
            </div>
        </div>
    </div>
    <div id="compass-maps" style="display: none;">
        <img src="templates/maps/how-to/annotation/compass.png" height="75px" width="75px">
    </div>
    <style>
        #annotation {
            color: #DDDDDD;
            font-size: 12px;
            font-family: Roboto;
            background: #3E464C;
            margin: 20px;
            padding: 10px;
            -webkit-border-radius: 2px;
            -moz-border-radius: 2px;
            border-radius: 2px;
            width: 300px;
            -moz-box-shadow: 0px 2px 5px #666;
            -webkit-box-shadow: 0px 2px 5px #666;
            box-shadow: 0px 2px 5px #666;
        }
        .country-label {
            color: white;
            font-size: 25px;
        }
    </style>
</body>

</html>

Initial marker selection

Using the initialMarkerSelection property, the marker shape can be selected initially. Markers render based on the latitude and longitude values.

initialMarkerSelection is an Array property.

Source
Preview
index.ts
index.html
Copied to clipboard
import { world_map } from './world-map.ts';
import { Maps, Marker, Selection } from '@syncfusion/ej2-maps';
Maps.Inject(Selection, Marker);
let map: Maps = new Maps({
layers: [{
    shapeData: world_map,
    markerSettings: [{
        visible: true,
        height: 20,
        width: 20,
        fill: 'green',
        shape:'Balloon',
        initialMarkerSelection: [{
           latitude: -6.64607562172573, longitude: -55.54687499999999
        }],
        selectionSettings: {
            enable: true,
            fill: 'blue',
            border: { color: 'white', width: 2}
        },
        dataSource: [
            { latitude: 49.95121990866204, longitude: 18.468749999999998, name:'Europe' },
            { latitude: 59.88893689676585, longitude: -109.3359375, name:'North America'},
            { latitude: -6.64607562172573, longitude: -55.54687499999999, name:'South America'}
        ]
    }],
}]
});
map.appendTo('#element');
Copied to clipboard
<!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="world-map.js"></script>
    <script src="usa.js"></script>
    <script src="data.js"></script>
    <script src="california.js"></script>
    <script src="texas.js"></script>
    <script src="africa_continent.js"></script>
    <script src="africa.js"></script>
    <script src="cluster.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container' style="height: 500px; width: 700px">
        <div id='element'></div>
    </div>
    <svg height="150" width="400">
        <defs>
            <linearGradient id="grad1" x1="0%" y1="0%" x2="0%" y2="100%">
                <stop offset="0%" style="stop-color:#C5494B;stop-opacity:1" />
                <stop offset="100%" style="stop-color:#4C134F;stop-opacity:1" />
            </linearGradient>
        </defs>
    </svg>
    <!-- annotation content -->
    <div id="maps-annotation" style="display: none;">
        <div id="annotation">
            <div>
                <p style="margin-left:10px;font-size:13px;font-weight:500">Facts about Africa</p>
            </div>
            <hr style="margin-top:-3px;margin-bottom:10px;border:0.5px solid #DDDDDD">
            <div>
                <ul style="list-style-type:disc; margin-left:-20px;margin-bottom:2px; font-weight:400">
                    <li>Africa is the second largest and second most populated continent in the world.</li>
                    <li style="padding-top:5px;">Africa has 54 sovereign states and 10 non-sovereign territories.</li>
                    <li style="padding-top:5px;">Algeria is the largest country in Africa, where as Mayotte is the smallest.</li>
                </ul>
            </div>
        </div>
    </div>
    <div id="compass-maps" style="display: none;">
        <img src="templates/maps/how-to/annotation/compass.png" height="75px" width="75px">
    </div>
    <style>
        #annotation {
            color: #DDDDDD;
            font-size: 12px;
            font-family: Roboto;
            background: #3E464C;
            margin: 20px;
            padding: 10px;
            -webkit-border-radius: 2px;
            -moz-border-radius: 2px;
            border-radius: 2px;
            width: 300px;
            -moz-box-shadow: 0px 2px 5px #666;
            -webkit-box-shadow: 0px 2px 5px #666;
            box-shadow: 0px 2px 5px #666;
        }
        .country-label {
            color: white;
            font-size: 25px;
        }
    </style>
</body>

</html>

Highlight

Each shape in the Map can be highlighted during mouse hover on the Map elements such as shapes, bubbles, markers and legends. Highlight is enabled by setting the enable property of highlightSettings to true. To enable highlight in Maps, the Highlight module must be injected into Maps using Maps.Inject(Highlight) method.

Copied to clipboard
import { Maps, Highlight } from '@syncfusion/ej2-maps';
Maps.Inject(Highlight);
let map: Maps = new Maps({ });

The following properties are available to customize the highlight of Map elements such as shapes, bubbles, markers and legends.

  • border - To customize the color, width and opacity of the border of which element is highlighted in Maps.
  • fill - Applies the color for the element that is highlighted.
  • opacity - To customize the transparency for the element that is highlighted.

Hovering on the specific legend, the shapes which are bounded to the selected legend is also highlighted and vice versa.

Source
Preview
index.ts
index.html
Copied to clipboard
import { world_map } from './world-map.ts';
import { Maps, Highlight, Legend } from '@syncfusion/ej2-maps';
Maps.Inject(Highlight, Legend);
let map: Maps = new Maps({
layers: [
    {
        shapeData: world_map,
        dataSource: [
            { "Country": "China", "Membership": "Permanent"},
            { "Country": "France", "Membership": "Permanent" },
            { "Country": "Russia", "Membership": "Permanent"},
            { "Country": "Kazakhstan", "Membership": "Non-Permanent"},
            { "Country": "Poland", "Membership": "Non-Permanent"},
            { "Country": "Sweden", "Membership": "Non-Permanent"}
        ],
        shapePropertyPath: 'name',
        shapeDataPath: 'Country',
        highlightSettings: {
           enable: true,
           fill: 'blue',
           border: { color: 'white', width: 2}
        },
        shapeSettings: {
            colorValuePath: 'Membership',
            colorMapping: [
            {
                value: 'Permanent', color: '#D84444'
            },
            {
                value: 'Non-Permanent', color: '#316DB5'
            }]
        }
    }
],
legendSettings: {
    visible: true
}
});
map.appendTo('#element');
Copied to clipboard
<!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="world-map.js"></script>
    <script src="usa.js"></script>
    <script src="data.js"></script>
    <script src="california.js"></script>
    <script src="texas.js"></script>
    <script src="africa_continent.js"></script>
    <script src="africa.js"></script>
    <script src="cluster.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container' style="height: 500px; width: 700px">
        <div id='element'></div>
    </div>
    <svg height="150" width="400">
        <defs>
            <linearGradient id="grad1" x1="0%" y1="0%" x2="0%" y2="100%">
                <stop offset="0%" style="stop-color:#C5494B;stop-opacity:1" />
                <stop offset="100%" style="stop-color:#4C134F;stop-opacity:1" />
            </linearGradient>
        </defs>
    </svg>
    <!-- annotation content -->
    <div id="maps-annotation" style="display: none;">
        <div id="annotation">
            <div>
                <p style="margin-left:10px;font-size:13px;font-weight:500">Facts about Africa</p>
            </div>
            <hr style="margin-top:-3px;margin-bottom:10px;border:0.5px solid #DDDDDD">
            <div>
                <ul style="list-style-type:disc; margin-left:-20px;margin-bottom:2px; font-weight:400">
                    <li>Africa is the second largest and second most populated continent in the world.</li>
                    <li style="padding-top:5px;">Africa has 54 sovereign states and 10 non-sovereign territories.</li>
                    <li style="padding-top:5px;">Algeria is the largest country in Africa, where as Mayotte is the smallest.</li>
                </ul>
            </div>
        </div>
    </div>
    <div id="compass-maps" style="display: none;">
        <img src="templates/maps/how-to/annotation/compass.png" height="75px" width="75px">
    </div>
    <style>
        #annotation {
            color: #DDDDDD;
            font-size: 12px;
            font-family: Roboto;
            background: #3E464C;
            margin: 20px;
            padding: 10px;
            -webkit-border-radius: 2px;
            -moz-border-radius: 2px;
            border-radius: 2px;
            width: 300px;
            -moz-box-shadow: 0px 2px 5px #666;
            -webkit-box-shadow: 0px 2px 5px #666;
            box-shadow: 0px 2px 5px #666;
        }
        .country-label {
            color: white;
            font-size: 25px;
        }
    </style>
</body>

</html>

Enable highlight for bubbles

To enable the highlight for bubbles in Maps, set the highlightSettings in bubbleSettings and set the enable property of highlightSettings as true.

To use the bubble feature, the Bubble module must be injected.

Source
Preview
index.ts
index.html
Copied to clipboard
import { world_map } from './world-map.ts';
import { Maps, Bubble, Highlight } from '@syncfusion/ej2-maps';
Maps.Inject(Highlight, Bubble);
let map: Maps = new Maps({
   layers: [{
    shapeData: world_map,
    shapeDataPath: 'name',
    shapePropertyPath: 'name',
    bubbleSettings: [{
        visible: true,
        dataSource: [
            { name: 'India', population: '38332521' },
            { name: 'South Africa', population: '19651127' },
            { name: 'Pakistan', population: '3090416' }
        ],
        highlightSettings: {
            enable: true,
            fill: 'green',
            border: { color: 'white', width: 2}
        },
        valuePath: 'population'
    }]
}]
});
map.appendTo('#element');
Copied to clipboard
<!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="world-map.js"></script>
    <script src="usa.js"></script>
    <script src="data.js"></script>
    <script src="california.js"></script>
    <script src="texas.js"></script>
    <script src="africa_continent.js"></script>
    <script src="africa.js"></script>
    <script src="cluster.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container' style="height: 500px; width: 700px">
        <div id='element'></div>
    </div>
    <svg height="150" width="400">
        <defs>
            <linearGradient id="grad1" x1="0%" y1="0%" x2="0%" y2="100%">
                <stop offset="0%" style="stop-color:#C5494B;stop-opacity:1" />
                <stop offset="100%" style="stop-color:#4C134F;stop-opacity:1" />
            </linearGradient>
        </defs>
    </svg>
    <!-- annotation content -->
    <div id="maps-annotation" style="display: none;">
        <div id="annotation">
            <div>
                <p style="margin-left:10px;font-size:13px;font-weight:500">Facts about Africa</p>
            </div>
            <hr style="margin-top:-3px;margin-bottom:10px;border:0.5px solid #DDDDDD">
            <div>
                <ul style="list-style-type:disc; margin-left:-20px;margin-bottom:2px; font-weight:400">
                    <li>Africa is the second largest and second most populated continent in the world.</li>
                    <li style="padding-top:5px;">Africa has 54 sovereign states and 10 non-sovereign territories.</li>
                    <li style="padding-top:5px;">Algeria is the largest country in Africa, where as Mayotte is the smallest.</li>
                </ul>
            </div>
        </div>
    </div>
    <div id="compass-maps" style="display: none;">
        <img src="templates/maps/how-to/annotation/compass.png" height="75px" width="75px">
    </div>
    <style>
        #annotation {
            color: #DDDDDD;
            font-size: 12px;
            font-family: Roboto;
            background: #3E464C;
            margin: 20px;
            padding: 10px;
            -webkit-border-radius: 2px;
            -moz-border-radius: 2px;
            border-radius: 2px;
            width: 300px;
            -moz-box-shadow: 0px 2px 5px #666;
            -webkit-box-shadow: 0px 2px 5px #666;
            box-shadow: 0px 2px 5px #666;
        }
        .country-label {
            color: white;
            font-size: 25px;
        }
    </style>
</body>

</html>

Enable highlight for markers

To enable the highlight for markers in Maps, set the highlightSettings in markerSettings and set the enable property of highlightSettings as true.

To use the marker feature, the Marker module must be injected.

Source
Preview
index.ts
index.html
Copied to clipboard
import { world_map } from './world-map.ts';
import { Maps, Marker, Highlight } from '@syncfusion/ej2-maps';
Maps.Inject(Highlight, Marker);
let map: Maps = new Maps({
  layers: [{
    shapeData: world_map,
    markerSettings: [{
        visible: true,
        height: 20,
        width: 20,
        fill: 'green',
        shape:'Balloon',
        highlightSettings: {
            enable: true,
            fill: 'blue',
            border: { color: 'white', width: 2}
        },
        dataSource: [
            { latitude: 49.95121990866204, longitude: 18.468749999999998, name:'Europe' },
            { latitude: 59.88893689676585, longitude: -109.3359375, name:'North America'},
            { latitude: -6.64607562172573, longitude: -55.54687499999999, name:'South America'}
        ]
    }],
}]
});
map.appendTo('#element');
Copied to clipboard
<!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="world-map.js"></script>
    <script src="usa.js"></script>
    <script src="data.js"></script>
    <script src="california.js"></script>
    <script src="texas.js"></script>
    <script src="africa_continent.js"></script>
    <script src="africa.js"></script>
    <script src="cluster.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container' style="height: 500px; width: 700px">
        <div id='element'></div>
    </div>
    <svg height="150" width="400">
        <defs>
            <linearGradient id="grad1" x1="0%" y1="0%" x2="0%" y2="100%">
                <stop offset="0%" style="stop-color:#C5494B;stop-opacity:1" />
                <stop offset="100%" style="stop-color:#4C134F;stop-opacity:1" />
            </linearGradient>
        </defs>
    </svg>
    <!-- annotation content -->
    <div id="maps-annotation" style="display: none;">
        <div id="annotation">
            <div>
                <p style="margin-left:10px;font-size:13px;font-weight:500">Facts about Africa</p>
            </div>
            <hr style="margin-top:-3px;margin-bottom:10px;border:0.5px solid #DDDDDD">
            <div>
                <ul style="list-style-type:disc; margin-left:-20px;margin-bottom:2px; font-weight:400">
                    <li>Africa is the second largest and second most populated continent in the world.</li>
                    <li style="padding-top:5px;">Africa has 54 sovereign states and 10 non-sovereign territories.</li>
                    <li style="padding-top:5px;">Algeria is the largest country in Africa, where as Mayotte is the smallest.</li>
                </ul>
            </div>
        </div>
    </div>
    <div id="compass-maps" style="display: none;">
        <img src="templates/maps/how-to/annotation/compass.png" height="75px" width="75px">
    </div>
    <style>
        #annotation {
            color: #DDDDDD;
            font-size: 12px;
            font-family: Roboto;
            background: #3E464C;
            margin: 20px;
            padding: 10px;
            -webkit-border-radius: 2px;
            -moz-border-radius: 2px;
            border-radius: 2px;
            width: 300px;
            -moz-box-shadow: 0px 2px 5px #666;
            -webkit-box-shadow: 0px 2px 5px #666;
            box-shadow: 0px 2px 5px #666;
        }
        .country-label {
            color: white;
            font-size: 25px;
        }
    </style>
</body>

</html>

Tooltip

On mouse over or touch end event, the tooltip is used to get more information about the layer, bubble, or marker. To enable tooltip in Maps, the Tooltip module must be injected into Maps using Maps.Inject(Tooltip) method. It can be enabled separately for layer or bubble or marker by using the visible property of tooltipSettings as true. The valuePath property in the tooltip takes the field name that presents in dataSource and displays that value as tooltip text. The tooltipDisplayMode property is used to change the display mode of the tooltip in Maps. Following display modes of tooltip are available in the Maps component. By default, tooltipDisplayMode is set to MouseMove.

  • MouseMove
  • Click
  • DoubleClick
Source
Preview
index.ts
index.html
Copied to clipboard
import { world_map } from './world-map.ts';
import { Maps, MapsTooltip } from '@syncfusion/ej2-maps';
Maps.Inject(MapsTooltip);
let map: Maps = new Maps({
layers: [{
    shapeData: world_map,
    tooltipSettings: {
        visible: true,
        valuePath: 'name'
    }
}]
});
map.appendTo('#element');
Copied to clipboard
<!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="world-map.js"></script>
    <script src="usa.js"></script>
    <script src="data.js"></script>
    <script src="california.js"></script>
    <script src="texas.js"></script>
    <script src="africa_continent.js"></script>
    <script src="africa.js"></script>
    <script src="cluster.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container' style="height: 500px; width: 700px">
        <div id='element'></div>
    </div>
    <svg height="150" width="400">
        <defs>
            <linearGradient id="grad1" x1="0%" y1="0%" x2="0%" y2="100%">
                <stop offset="0%" style="stop-color:#C5494B;stop-opacity:1" />
                <stop offset="100%" style="stop-color:#4C134F;stop-opacity:1" />
            </linearGradient>
        </defs>
    </svg>
    <!-- annotation content -->
    <div id="maps-annotation" style="display: none;">
        <div id="annotation">
            <div>
                <p style="margin-left:10px;font-size:13px;font-weight:500">Facts about Africa</p>
            </div>
            <hr style="margin-top:-3px;margin-bottom:10px;border:0.5px solid #DDDDDD">
            <div>
                <ul style="list-style-type:disc; margin-left:-20px;margin-bottom:2px; font-weight:400">
                    <li>Africa is the second largest and second most populated continent in the world.</li>
                    <li style="padding-top:5px;">Africa has 54 sovereign states and 10 non-sovereign territories.</li>
                    <li style="padding-top:5px;">Algeria is the largest country in Africa, where as Mayotte is the smallest.</li>
                </ul>
            </div>
        </div>
    </div>
    <div id="compass-maps" style="display: none;">
        <img src="templates/maps/how-to/annotation/compass.png" height="75px" width="75px">
    </div>
    <style>
        #annotation {
            color: #DDDDDD;
            font-size: 12px;
            font-family: Roboto;
            background: #3E464C;
            margin: 20px;
            padding: 10px;
            -webkit-border-radius: 2px;
            -moz-border-radius: 2px;
            border-radius: 2px;
            width: 300px;
            -moz-box-shadow: 0px 2px 5px #666;
            -webkit-box-shadow: 0px 2px 5px #666;
            box-shadow: 0px 2px 5px #666;
        }
        .country-label {
            color: white;
            font-size: 25px;
        }
    </style>
</body>

</html>

Customization

The following properties are available in the tooltipSettings to customize the tooltip of the Maps component.

  • border - To customize the color, width and opacity of the border of the tooltip in layers, markers, and bubbles of Maps.
  • fill - Applies the color of the tooltip in layers, markers, and bubbles of Maps.
  • format - To customize the format of the tooltip in layers, markers, and bubbles of Maps
  • textStyle - To customize the style of the text in the tooltip for layers, markers, and bubbles of Maps.
Source
Preview
index.ts
index.html
Copied to clipboard
import { world_map } from './world-map.ts';
import { Maps, MapsTooltip, ITooltipRenderEventArgs } from '@syncfusion/ej2-maps';
Maps.Inject(MapsTooltip);
let map: Maps = new Maps({
tooltipRender: (args: ITooltipRenderEventArgs) => {
    if (!args.options['data']) {
        args.cancel = true;
    }
    },
layers: [{
    shapeData: world_map,
    shapePropertyPath: 'name',
    shapeDataPath: 'name',
    shapeSettings: {
        fill: '#E5E5E5',
        colorMapping: [
            { color: '#b3daff', value: '1' },
            { color: '#80c1ff', value: '2' },
            { color: '#1a90ff', value: '3' },
            { color: '#005cb3', value: '7' }
        ],
        colorValuePath: 'value1'
    },
    dataSource: [
        { "name": "India", "value1": "3", "value1": "2", "country": "India" },
        { "name": "Dominican Rep.", "value1": "3", "value2": "2", "country": "West Indies" },
        { "name": "Cuba", "value1": "3", "value2": "2", "country": "West Indies" },
        { "name": "Jamaica", "value1": "3", "value2": "2", "country": "West Indies" },
        { "name": "Haiti", "value1": "3", "value2": "2", "country": "West Indies" },
        { "name": "Guyana", "value1": "3", "value2": "2", "country": "West Indies" },
        { "name": "Suriname", "value1": "3", "value2": "2", "country": "West Indies"},
        { "name": "Trinidad and Tobago", "value1": "3", "value2": "2", "country": "West Indies" },
        { "name": "Sri Lanka", "value1": "3", "value2": "1", "country": "Sri Lanka" },
        { "name": "United Kingdom", "value1": "3", "value2": "0", "country": "England" },
        { "name": "Pakistan", "value1": "2", "value2": "1", "country": "Pakistan" },
        { "name": "New Zealand", "value1": "1", "value2": "0", "country": "New Zealand" },
        { "name": "Australia", "value1": "7", "value2": "5", "country": "Australia" }
    ],
    tooltipSettings: {
        visible: true,
        valuePath: 'name',
        format: '${name}: ${value1}',
        fill: '#D0D0D0',
        textStyle: {
            color: 'green',
            fontFamily: 'Times New Roman',
            fontStyle: 'Sans-serif'
        }
    }
}]
});
map.appendTo('#element');
Copied to clipboard
<!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="world-map.js"></script>
    <script src="usa.js"></script>
    <script src="data.js"></script>
    <script src="california.js"></script>
    <script src="texas.js"></script>
    <script src="africa_continent.js"></script>
    <script src="africa.js"></script>
    <script src="cluster.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container' style="height: 500px; width: 700px">
        <div id='element'></div>
    </div>
    <svg height="150" width="400">
        <defs>
            <linearGradient id="grad1" x1="0%" y1="0%" x2="0%" y2="100%">
                <stop offset="0%" style="stop-color:#C5494B;stop-opacity:1" />
                <stop offset="100%" style="stop-color:#4C134F;stop-opacity:1" />
            </linearGradient>
        </defs>
    </svg>
    <!-- annotation content -->
    <div id="maps-annotation" style="display: none;">
        <div id="annotation">
            <div>
                <p style="margin-left:10px;font-size:13px;font-weight:500">Facts about Africa</p>
            </div>
            <hr style="margin-top:-3px;margin-bottom:10px;border:0.5px solid #DDDDDD">
            <div>
                <ul style="list-style-type:disc; margin-left:-20px;margin-bottom:2px; font-weight:400">
                    <li>Africa is the second largest and second most populated continent in the world.</li>
                    <li style="padding-top:5px;">Africa has 54 sovereign states and 10 non-sovereign territories.</li>
                    <li style="padding-top:5px;">Algeria is the largest country in Africa, where as Mayotte is the smallest.</li>
                </ul>
            </div>
        </div>
    </div>
    <div id="compass-maps" style="display: none;">
        <img src="templates/maps/how-to/annotation/compass.png" height="75px" width="75px">
    </div>
    <style>
        #annotation {
            color: #DDDDDD;
            font-size: 12px;
            font-family: Roboto;
            background: #3E464C;
            margin: 20px;
            padding: 10px;
            -webkit-border-radius: 2px;
            -moz-border-radius: 2px;
            border-radius: 2px;
            width: 300px;
            -moz-box-shadow: 0px 2px 5px #666;
            -webkit-box-shadow: 0px 2px 5px #666;
            box-shadow: 0px 2px 5px #666;
        }
        .country-label {
            color: white;
            font-size: 25px;
        }
    </style>
</body>

</html>

Tooltip template

The HTML element can be rendered in the tooltip of the Maps using the template property of the tooltipSettings. In the following example, ${value1} and ${value2} are the place holders in the HTML element to display the value1 and value2 values of the corresponding shape.

Source
Preview
index.ts
index.html
Copied to clipboard
import { Maps, MapsTooltip, Legend, ITooltipRenderEventArgs, ILoadEventArgs, MapsTheme, MapAjax } from '@syncfusion/ej2-maps';
import { world_map } from './world-map.ts';
import { tooltipData } from './tooltip-datasource.ts';
Maps.Inject(MapsTooltip, Legend);
let maps: Maps = new Maps({
tooltipRender: (args: ITooltipRenderEventArgs) => {
    if (!args.options['data']) {
        args.cancel = true;
    }
},
legendSettings: {
    visible: true,
    mode: 'Interactive',
    position: 'Left',
    orientation: 'Vertical',
    height: '70%',
    width: '10'
},
layers: [{
    shapeData: world_map,
    shapePropertyPath: 'name',
    shapeDataPath: 'name',
    dataSource: tooltipData,
    tooltipSettings: {
        visible: true,
        valuePath: 'name',
        template: '#template'
    },
    shapeSettings: {
        fill: '#E5E5E5',
        colorMapping: [
            { color: '#b3daff', value: '1' },
            { color: '#80c1ff', value: '2' },
            { color: '#1a90ff', value: '3' },
            { color: '#005cb3', value: '7' }
        ],
        colorValuePath: 'value1'
    }
}]
});
maps.appendTo('#container');
Copied to clipboard
<!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>
    <script src="world-map.js"></script>
</head>

<body>
    <div id='loader'>Loading....</div>
    <div id='container' style="margin-top: 125px">
        <div id='element'></div>
    </div>
    <div id="template" style="display:none">
        <div class="toolback">
            <div class="listing2">
                <center>
                    ${country}                                            
                </center>
            </div>
            <hr style="margin-top: 2px;margin-bottom:5px;border:0.5px solid #DDDDDD">
            <div>
                <span class="listing1">Finalist : </span><span class="listing2">${value1}</span>
            </div> 
            <div>
                <span class="listing1">Win : </span><span class="listing2">${value2}</span>
            </div>
        </div>
    </div>
</body>
<style>
    .toolback {
     border-radius: 4px;
     border: 1px #abb9c6;
     opacity: 90%;
     background: rgba(53, 63, 76, 0.90);
     box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.40);
     padding-bottom: 5px;
     padding-top: 10px;
     padding-left: 10px;
     padding-right: 10px;
     width: 90px;
 }
 .listing1 {
      font-size:13px;
      color:#cccccc
 }
 .listing2 {
      font-size:13px;
      color:#ffffff;
      font-weight: 500;
 }
</style>
</html>

See Also