Search results

Getting Started with ASP.NET Core

Prerequisites

To get start with ASP.NET Core application, need to ensure the following software to be installed on the machine.

  • Visual Studio 2017
  • DotNet Core 2.0

Setup ASP.NET Core application with Essential JS 2 for ASP.NET Core

The following steps to create ASP.NET Core Application.

Step 1: Create ASP.NET Core Web Application with default template project in Visual Studio 2017.

Alt text

Step 2: Once your project created. We need to add Syncfusion EJ2 package into your application by using Nugget Package Manager.

Open the nuGet package manager.

Alt text

Install the Syncfusion.EJ2 package to the application

Alt text

After Installation complete this will included in the project. You can refer it from the Project Assembly Reference.

We need to install NewtonSoft.JSON as dependency since it Syncfusion.EJ2 dependent to NewtonSoft.JSON package.

Step 3: Open the _ViewImports.cshtml to import Syncfusion.EJ2 package.

@addTagHelper *, Syncfusion.EJ2

Step 4: Add client side resource through CDN or local package in the layout page _Layout.cshtml.

@* Syncfusion Essential JS 2 Styles *@
<link rel="stylesheet" href="https://cdn.syncfusion.com/ej2/material.css" />

@* Syncfusion Essential JS 2 Scripts *@
<script src="https://cdn.syncfusion.com/ej2/dist/ej2.min.js"></script>

Step 5: Adding Script Manager in layout page _Layout.cshtml.

<ejs-scripts></ejs-scripts>

Step 6: Add the below code to your Index.cshtml view page which is present under Views/Home folder, to initialize the maps.

@using Syncfusion.EJ2;
 <ejs-maps id="maps">
</ejs-maps>

Render shapes from GeoJSON data

This section explains how to bind GeoJSON data to the map.

public IActionResult Default()
{
    ViewBag.mapdata = GetUSMap();
    return View();
}
public object GetUSMap()
{
    string allText = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/USA.json");
    return JsonConvert.DeserializeObject(allText);
}

Elements in the maps will be rendered in the layers. So, add a layer collection to the maps by using the[layers]property. Now bind the GeoJSON data to the [shapeData] property.

@using Syncfusion.EJ2;
 <ejs-maps id="maps">
    <e-layers>
        <e-layer shapeData="ViewBag.usmap">
        </e-layer>
    </e-layers>
</ejs-maps>

Bind data source to map

The following properties in layers are used for binding data source to map.

  • [dataSource]
  • [shapeDataPath]
  • [shapePropertyPath]

The [dataSource] property takes collection value as input. For example, a list of objects can be provided as input. This data is further used in tooltip, data label, bubble, legend and color mapping.

The [shapeDataPath] property is used to reference the data ID in dataSource. Whereas, the [shapePropertyPath] property is used to reference the column name in shapeData to identify the shape. Both properties are related to each other. When the values of the shapeDataPath property in the dataSource property and the value of shapePropertyPath in the shapeData property match, then the associated object from the dataSource is bound to the corresponding shape.

The JSON object “electionData” is used as data source as follows.

@using Syncfusion.EJ2;
 <ejs-maps id="maps" load="window.onMapLoad" shapeSelected="window.shapeSelected">
    <e-layers>
        <e-layer dataSource="ViewBag.electiondata" shapeData="ViewBag.usmap" shapeDataPath="State" shapePropertyPath="name">
        </e-layer>
    </e-layers>
</ejs-maps>

Apply color mapping

The color mapping feature supports customization of shape colors based on the underlying value of shape received from the bound data. Specify the field name from which the values have to be compared for the shapes in the [colorValuePath] property in [shapeSettings].

Specify the color and value in the [colorMapping] property. Here ‘#D84444’ is specified for ‘Trump’ and ‘#316DB5’ is specified for ‘Clinton’.

@using Syncfusion.EJ2;
var shape = new
{
    colorValuePath = "Candidate",
    colorMapping = new[] {
        new { value = "Trump", color = "#D84444" },
        new { value = "Clinton", color = "#316DB5" }
    }
};
<ejs-maps id="maps">
    <e-layers>
        <e-layer shapeSettings="shape" dataSource="ViewBag.electiondata" shapeData="ViewBag.usmap" shapeDataPath="State" shapePropertyPath="name">
        </e-layer>
    </e-layers>
</ejs-maps>

Add title to maps

You can add a title using the [titleSettings] property to the map to provide information to the user about the shapes rendered in the map.

@using Syncfusion.EJ2;
var shape = new
{
    colorValuePath = "Candidate",
    colorMapping = new[] {
        new { value = "Trump", color = "#D84444" },
        new { value = "Clinton", color = "#316DB5" }
    }
};
<ejs-maps id="maps">
    <e-maps-titlesettings text="USA Election Results - 2016" textStyle="titleStyle"></e-maps-titlesettings>
    <e-layers>
        <e-layer shapeSettings="shape" dataSource="ViewBag.electiondata" shapeData="ViewBag.usmap" shapeDataPath="State" shapePropertyPath="name">
        </e-layer>
    </e-layers>
</ejs-maps>

Enable legend

You can enable the legend for the maps by setting the [visible] property to true in [legendSettings] object.

@using Syncfusion.EJ2;
var shape = new
{
    colorValuePath = "Candidate",
    colorMapping = new[] {
        new { value = "Trump", color = "#D84444" },
        new { value = "Clinton", color = "#316DB5" }
    }
};
<ejs-maps id="maps">
    <e-maps-titlesettings text="USA Election Results - 2016" textStyle="titleStyle"></e-maps-titlesettings>
    <e-maps-legendsettings visible="true" position="Top"></e-maps-legendsettings>
    <e-layers>
        <e-layer shapeSettings="shape" dataSource="ViewBag.electiondata" shapeData="ViewBag.usmap" shapeDataPath="State" shapePropertyPath="name">
        </e-layer>
    </e-layers>
</ejs-maps>

Add data label

You can add data labels to show additional information of the shapes in map. This can be achieved by setting the [visible] property to true in the [dataLabelSettings] object.

@using Syncfusion.EJ2;
var shape = new
{
    colorValuePath = "Candidate",
    colorMapping = new[] {
        new { value = "Trump", color = "#D84444" },
        new { value = "Clinton", color = "#316DB5" }
    }
};
var dataLabelSettings = new
{
        visible = true,
        labelPath = "name",
        smartLabelMode = "Trim"
};
<ejs-maps id="maps">
    <e-maps-titlesettings text="USA Election Results - 2016" textStyle="titleStyle"></e-maps-titlesettings>
    <e-layers>
        <e-layer dataLabelSettings="dataLabelSettings" shapeSettings="shape" dataSource="ViewBag.electiondata" shapeData="ViewBag.usmap"
            shapeDataPath="State" shapePropertyPath="name">
        </e-layer>
    </e-layers>
</ejs-maps>

Enable tooltip

The tooltip is used when you cannot display the information by using the data labels due to space constraints. You can enable tooltip by setting the [visible] property to true in [tooltipSettings] object.

@using Syncfusion.EJ2;
<ejs-maps id="maps" load="window.onMapLoad" shapeSelected="window.shapeSelected">
    <e-maps-titlesettings text="USA Election Results - 2016" textStyle="titleStyle"></e-maps-titlesettings>
    <e-maps-zoomsettings enable="false"></e-maps-zoomsettings>
    <e-maps-legendsettings visible="true" mode="Interactive" position="Top" width="80%" textStyle="textStyle"></e-maps-legendsettings>
    <e-layers>
        <e-layer shapeSettings="shape" dataSource="ViewBag.electiondata" shapeData="ViewBag.usmap" shapeDataPath="State" shapePropertyPath="name"
            tooltipSettings="tooltipSettings" highlightSettings="highlightSettings" selectionSettings="selectionSettings">
        </e-layer>
    </e-layers>
</ejs-maps>