Search results

Annotation in ASP.NET MVC Maps control

21 Oct 2021 / 1 minute to read

Annotations are used to mark the specific area of interest in the Maps with texts, shapes, or images. Any number of annotations can be added to the Maps component.

Initialize the Maps control with annotation option, text content or ID of an HTML element or an HTML string can be specified to render a new element that needs to be displayed in the Maps by using the Content property. To specify the content position with X and Y properties as mentioned in the following example.

razor
howto-annotation.cs
Copied to clipboard
@using Syncfusion.EJ2.Maps;
@using Syncfusion.EJ2;

@Html.EJS().Maps("maps").Load("mapsLoad").Layers(layer =>
{
    layer.ShapeSettings(s => s.Fill("url(#grad1)")).ShapeData(ViewBag.africa).Add();
}).Render()

<script>
    function mapsLoad(args) {
        var maps = args.maps;
        args.maps.annotations = [
            {
                content: '#maps-annotation',
                x: '0%', y: '70%'
            },
            {
                content: '#compass-maps',
                x: '80%', y: '5%'
            }
        ];
    }
</script>

<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>
            <stop offset="100%" style="stop-color:#4C134F;stop-opacity:1"></stop>
        </linearGradient>
    </defs>
</svg>
<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="~/compass.png" height="75px" width="75px">
</div>
<style>
    #annotation {
        color: #DDDDDD;
        font-size: 12px;
        font-family: Roboto;
        background: #3E464C;
        margin: 20px;
        padding: 10px;
        border-radius: 2px;
        width: 300px;
        box-shadow: 0px 2px 5px #666;
    }
</style>
Copied to clipboard
using Newtonsoft.Json;
using Syncfusion.EJ2.Charts;

namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            ViewBag.africa = GetAfricaMap();
            return View();
        }
        public object GetAfricaMap()
        {
            string text = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/Africa.json");
            return JsonConvert.DeserializeObject(text);
        }
    }
}

Annotation