Search results

Internationalization in ASP.NET MVC Maps control

15 Oct 2021 / 1 minute to read

Maps provide support for internationalization for the below elements.

  • Data label
  • Tooltip

For more information about number and date formatter, refer to the internationalization section.

Globalization

Globalization is the process of designing and developing a component that works in different cultures/locales. Internationalization library is used to globalize number, date, time values in Maps component using Format property in the Maps.

Numeric format

The numeric formats such as currency, percentage and so on can be displayed in the tooltip and data labels of the Maps using the Format property in the Maps. In the below example, the tooltip is globalized to German culture. When setting the UseGroupingSeparator property as true, the numeric text in the Maps separates with the comma separator.

razor
internationalization.cs
Copied to clipboard
@using Syncfusion.EJ2.Maps;
@using Syncfusion.EJ2;

@{
    var internData = new[]
    {
        new { Country= "China", Membership="Permanent", population= "38332521" },
        new { Country= "France", Membership="Permanent", population= "19651127" },
        new { Country= "Russia", Membership="Permanent", population= "3090416" },
        new { Country= "Kazakhstan", Membership="Non-Permanent", population= "1232521" },
        new { Country= "Poland", Membership="Non-Permanent", population= "90332521" },
        new { Country= "Sweden", Membership="Non-Permanent", population= "383521" }
    };
    var colorMapping = new List<Syncfusion.EJ2.Maps.MapsColorMapping> {
        new MapsColorMapping {Value="Permanent", Color="#D84444"},
        new MapsColorMapping {Value="Non-Permanent", Color="#316DB5"}
     };
}

@Html.EJS().Maps("maps").Format("c").UseGroupingSeparator(true).Layers(l =>
{
    l.ShapeSettings(s => s.ColorValuePath("Membership").Fill("#E5E5E5").ColorMapping(colorMapping)).
      TooltipSettings(tooltip => tooltip.Visible(true).ValuePath("population")).
      DataSource(internData).ShapeDataPath("Country").ShapePropertyPath("name").
      ShapeData(ViewBag.worldMap).Add();
}).Render()
Copied to clipboard
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using EJ2_Core_Application.Models;
using Newtonsoft.Json;

namespace EJ2_Core_Application.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            ViewBag.world_map = GetWorldMap();
            ViewBag.worldMap = GetMap();
            return View();
        }
        public object GetWorldMap()
        {
            string allText = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/world_map.js");
            return JsonConvert.DeserializeObject(allText);
        }
        public object GetMap()
        {
            string allText = System.IO.File.ReadAllText(Server.MapPath("~/App_Data/WorldMap.json"));
            return JsonConvert.DeserializeObject(allText, typeof(object));
        }
    }
}

Internationalization