Customization in EJ2 JavaScript Maps control

27 Apr 202324 minutes to read

Setting the size for Maps

The width and height of the Maps can be set using the width and height properties in the Maps control. Percentage or pixel values can be used for the height and width values.

var map = new ej.maps.Maps({
    height: '200px',
    width: '500px',
    layers: [{
        shapeData: world_map,
        shapeSettings: {
            autofill: true,
        }
    }]
});

map.appendTo('#element');
<!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="world-map.js"></script>


    <script src="https://cdn.syncfusion.com/ej2/25.1.35/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>

    <div id="container" style="height: 500px; width: 700px">
        <div id="element"></div>
    </div>

    <script>
        var ele = document.getElementById('container');
        if (ele) {
            ele.style.visibility = "visible";
        }   
    </script>
    <script src="index.js" type="text/javascript"></script>
</body>

</html>

Maps title

The title for the Maps can be set using the titleSettings. It can be customized using the following properties.

  • alignment - To customize the alignment for the text in the title for the Maps. The possible values are Center, Near and Far.
  • description - To set the description of the title in Maps.
  • text - To set the text for the title in Maps.
  • textStyle - To customize the text of the title in Maps.
  • subtitleSettings - To customize the subtitle for the Maps.
var map = new ej.maps.Maps({
    titleSettings: {
        text: 'Maps Control',
        textStyle: {
            color: 'red',
            fontStyle: 'italic',
            fontWeight: 'regular',
            fontFamily: 'arial',
            size: '14px'
        },
        alignment: 'Center'
    },
    layers: [{
        shapeData: world_map,
        shapeSettings: {
            autofill: true
        }
    }]
});

map.appendTo('#element');
<!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="world-map.js"></script>

    <script src="https://cdn.syncfusion.com/ej2/25.1.35/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>

    <div id="container" style="height: 500px; width: 700px">
        <div id="element"></div>
    </div>



    <script>
        var ele = document.getElementById('container');
        if (ele) {
            ele.style.visibility = "visible";
        }   
    </script>
    <script src="index.js" type="text/javascript"></script>
</body>

</html>

Setting theme

The Maps control supports following themes.

  • Material
  • Fabric
  • Bootstrap
  • Highcontrast
  • MaterialDark
  • FabricDark
  • BootstrapDark
  • Bootstrap4
  • HighContrastLight
  • Tailwind

By default, the Maps are rendered by the Material theme. The theme of the Maps component is changed using the theme property.

var maps = new ej.maps.Maps({
    layers: [{
        shapeData: world_map,
        shapeSettings: {
            autofill: true,
        }
    }] 
});
maps.appendTo('#container');
document.getElementById('theme').onchange = () => {
    var value = document.getElementById('theme').value;
    maps.theme= value; 
    maps.refresh();
}
<!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="world-map.js"></script>
<script src="https://cdn.syncfusion.com/ej2/25.1.35/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    
    <div class="col-lg-9 control-section">
        <div id="container" align="center"></div>
    </div>
    <div class="col-lg-3 property-section">
        <table id="property" title="Properties" style="width: 100%">
            <tbody><tr style="height: 50px">
                <td style="width: 60%">
                    <div>Projection Type</div>
                </td>
                <td style="width: 40%;">
                    <select name="theme" id="theme" style="margin-left: -25px">
                        <option value="Material">Material</option>
                        <option value="Fabric">Fabric</option>                    
                        <option value="Bootstrap">Bootstrap</option>
                        <option value="Highcontrast">Highcontrast</option>
                        <option value="MaterialDark">MaterialDark</option>
                        <option value="FabricDark">FabricDark</option>
                        <option value="BootstrapDark">BootstrapDark</option>                    
                        <option value="Bootstrap4">Bootstrap4</option>
                    </select>
                </td>
            </tr>
        </tbody></table>
    </div>


<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
      </script>
<script src="index.js" type="text/javascript"></script>
</body></html>

Customizing Maps container

The following properties are available to customize the container in the Maps.

  • background - To apply the background color to the container in the Maps.
  • border - To customize the color, width and opacity of the border of the Maps.
  • margin - To customize the margins of the Maps.
var map = new ej.maps.Maps({
    background: '#CCD1D1',
    border: {
        color: 'green',
        width: 2
    },
    margin: {
        bottom: 10,
        left: 20,
        right: 20,
        top: 10
    },
    layers: [{
        shapeData: world_map,
        shapeSettings: {
            autofill: true
        }
    }]
});

map.appendTo('#element');
<!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="world-map.js"></script>


    <script src="https://cdn.syncfusion.com/ej2/25.1.35/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>

    <div id="container" style="height: 500px; width: 700px">
        <div id="element"></div>
    </div>


    <script>
        var ele = document.getElementById('container');
        if (ele) {
            ele.style.visibility = "visible";
        }   
    </script>
    <script src="index.js" type="text/javascript"></script>
</body>

</html>

Customizing Maps area

By default, the background color of the shape maps is set as white. To modify the background color of the Maps area, the background property in the mapsArea is used. The border of the Maps area can be customized using the border property in the mapsArea.

var map = new ej.maps.Maps({
    mapsArea: {
        background: '#CCD1D1',
        border: {
            width: 2,
            color: 'green'
        }
    },
    layers: [{
        layerType: 'Geometry',
        shapeData: world_map,
        shapeSettings: {
            autofill: true,
        }
    }]
});

map.appendTo('#element');
<!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="world-map.js"></script>


    <script src="https://cdn.syncfusion.com/ej2/25.1.35/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>

    <div id="container" style="height: 500px; width: 700px">
        <div id="element"></div>
    </div>

    <script>
        var ele = document.getElementById('container');
        if (ele) {
            ele.style.visibility = "visible";
        }   
    </script>
    <script src="index.js" type="text/javascript"></script>
</body>

</html>

Customizing the shapes

The following properties are available in shapeSettings to customize the shapes of the Maps.

  • fill - To apply the fill color to the all the shapes.
  • autofill - To apply the palette colors to the shapes if it is set as true.
  • palette - To set the custom palette for the shapes.
  • border - To customize the color, width and opacity of the border of the shapes.
  • dashArray - To define the pattern of dashes and gaps that is applied to the outline of the shapes.
  • opacity - To customize the transparency for the shapes.
var map = new ej.maps.Maps({
    layers: [{
        shapeData: world_map,
        shapeSettings: {
            autofill: true,
            palette: ['#33CCFF', '#FF0000', '#800000', '#FFFF00', '#808000'],
            border: {
                color: 'green',
                width: 2
            },
            dashArray: '1',
            opacity: 0.9
        }
    }]
});
map.appendTo('#element');
<!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="world-map.js"></script>

    <script src="https://cdn.syncfusion.com/ej2/25.1.35/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>

    <div id="container" style="height: 500px; width: 700px">
        <div id="element"></div>
    </div>


    <script>
        var ele = document.getElementById('container');
        if (ele) {
            ele.style.visibility = "visible";
        }   
    </script>
    <script src="index.js" type="text/javascript"></script>
</body>

</html>

Setting color to the shapes from the data source

The color for each shape in the Maps can be set using the colorValuePath property of shapeSettings. The value for the colorValuePath property is the field name from the data source of the shapeSettings which contains the color values.

var map = new ej.maps.Maps({
    layers: [{
        shapeData: world_map,
        shapePropertyPath: 'continent',
        shapeDataPath: 'continent',
        dataSource: [
            { continent: "North America", color: '#71B081' },
            { continent: "South America", color: '#5A9A77' },
            { continent: "Africa", color: '#498770' },
            { continent: "Europe", color: '#39776C' },
            { continent: "Asia", color: '#266665' },
            { continent: "Oceania", color: '#124F5E' }
        ],
        shapeSettings: {
            colorValuePath: 'color',
        }
    }]
});
map.appendTo('#element');
<!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="world-map.js"></script>

    <script src="https://cdn.syncfusion.com/ej2/25.1.35/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>

    <div id="container" style="height: 500px; width: 700px">
        <div id="element"></div>
    </div>


    <script>
        var ele = document.getElementById('container');
        if (ele) {
            ele.style.visibility = "visible";
        }   
    </script>
    <script src="index.js" type="text/javascript"></script>
</body>

</html>

Applying border to individual shapes

The border of each shape in the Maps can be customized using the borderColorValuePath and borderWidthValuePath properties to modify the color and the width of the border respectively. The field name in the data source of the layer which contains the color and the width values must be set in the borderColorValuePath and borderWidthValuePath properties respectively. If the values of borderWidthValuePath and borderColorValuePath do not match with the field name from the data source, then the color and width of the border will be applied to the shapes using the border property in the shapeSettings.

var map = new ej.maps.Maps({
    layers: [{
        shapeData: world_map,
        shapePropertyPath: 'continent',
        shapeDataPath: 'continent',
        dataSource: [
            { continent: "North America", color: '#71B081', borderColor: '#CCFFE5', width: 2 },
            { continent: "South America", color: '#5A9A77', borderColor: 'red', width: 2 },
            { continent: "Africa", color: '#498770', borderColor: '#FFCC99', width: 2 },
            { continent: "Europe", color: '#39776C', borderColor: '#66B2FF', width: 2 },
            { continent: "Asia", color: '#266665', borderColor: '#999900', width: 2 },
            { continent: "Australia", color: '#124F5E ', borderColor: 'blue', width: 2 }
        ],
        shapeSettings: {
            borderColorValuePath: 'borderColor',
            borderWidthValuePath: 'width',
            colorValuePath: 'color',
        }
    }]
});

map.appendTo('#element');
<!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="world-map.js"></script>


    <script src="https://cdn.syncfusion.com/ej2/25.1.35/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>

    <div id="container" style="height: 500px; width: 700px">
        <div id="element"></div>
    </div>


    <script>
        var ele = document.getElementById('container');
        if (ele) {
            ele.style.visibility = "visible";
        }   
    </script>
    <script src="index.js" type="text/javascript"></script>
</body>

</html>

Projection type

The Maps control supports the following projection types:

  • Mercator
  • Equirectangular
  • Miller
  • Eckert3
  • Eckert5
  • Eckert6
  • Winkel3
  • AitOff

By default, the Maps are rendered by the Mercator projection type in which the Maps are rendered based on the coordinates. So, the Maps is not stretched. To change the type of projection in the Maps, the projectionType property is used.

var maps = new ej.maps.Maps({
    layers: [{
        shapeData: world_map,
        shapeDataPath: 'Country',
        shapePropertyPath: 'name',
        dataSource: projectionData,
        tooltipSettings: {
            visible: true,
            valuePath: 'Country'
        },
        shapeSettings: {
            fill: '#E5E5E5',
            colorMapping: [
                {
                    value: 'Permanent',
                    color: '#EDB46F'
                },
                {
                    color: '#F1931B',
                    value: 'Non-Permanent'
                }
            ],
            colorValuePath: 'Membership'
        }
    }]
});
maps.appendTo('#container');
document.getElementById('projectiontype').onchange = () => {
    maps.projectionType = document.getElementById('projectiontype').value;
    maps.refresh();
};
<!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="projection-data.js"></script>
    <script src="world-map.js"></script>
<script src="https://cdn.syncfusion.com/ej2/25.1.35/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>

<body>
    
    <div class="col-lg-9 control-section">
        <div id="container" align="center"></div>
    </div>
    <div class="col-lg-3 property-section">
        <table id="property" title="Properties" style="width: 100%">
            <tbody><tr style="height: 50px">
                <td style="width: 60%">
                    <div>Projection Type</div>
                </td>
                <td style="width: 40%;">
                    <select name="projectionType" id="projectiontype" style="margin-left: -25px">
                        <option value="Mercator">Mercator</option>
                        <option value="Equirectangular">Equirectangular</option>                    
                        <option value="Miller">Miller</option>
                        <option value="Eckert3">Eckert3</option>
                        <option value="Eckert5">Eckert5</option>
                        <option value="Eckert6">Eckert6</option>
                        <option value="Winkel3">Winkel3</option>                    
                        <option value="AitOff">AitOff</option>
                    </select>
                </td>
            </tr>
        </tbody></table>
    </div>
    


<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
      </script>
<script src="index.js" type="text/javascript"></script>
</body></html>