Having trouble getting help?
Contact Support
Contact Support
Marker types in ASP.NET CORE Maps Component
14 Nov 20227 minutes to read
Add different types of markers
Different marker objects can be added to the Maps component using the marker settings. To update different marker settings in Maps, follow the given steps.
Step 1:
Initialize the Maps component with marker settings. Here, a marker has been added with specified latitude and longitude of California by using the DataSource
property. To customize the shape of the marker using the Shape
property and change the border color and width of the marker using the Border
property as mentioned in the following example.
@{
var data = new[]
{
new { latitude= 40.7424509, longitude = -74.0081468, city = "New York"}
};
var border = new Syncfusion.EJ2.Maps.MapsBorder
{
Width = 2,
Color = "#333",
Opacity = 1
};
}
<div id="map">
<ejs-maps id="maps">
<e-maps-layers>
<e-maps-layer shapeData="ViewBag.worldmap">
<e-layersettings-markers>
<e-layersettings-marker visible="true" shape="Circle" fill="white" width="2" animationDuration="0" border="border" dataSource="data" ></e-layersettings-marker>
</e-layersettings-markers>
</e-maps-layer>
</e-maps-layers>
</ejs-maps>
</div>
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.worldmap = GetWorldMap();
ViewBag.worldMap = GetMap();
return View();
}
public object GetWorldMap()
{
string allText = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/WorldMap.json");
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));
}
}
}
Step 2:
Customize the above option for n number of markers as mentioned in the following example.
@{
var data = new[]
{
new { latitude= 40.7424509, longitude = -74.0081468, city = "New York"}
};
var data1 = new[]
{
new { latitude= 33.5302186, longitude = -117.7418381, city = "Laguna Niguel"}
};
var data2 = new[]
{
new { latitude= 37.6276571, longitude = -122.4276688, city = "San Bruno"}
};
var border = new Syncfusion.EJ2.Maps.MapsBorder
{
Width = 2,
Color = "#333",
Opacity = 1
};
var border1 = new Syncfusion.EJ2.Maps.MapsBorder
{
Width = 2,
Color = "#333",
Opacity = 1
};
var border2 = new Syncfusion.EJ2.Maps.MapsBorder
{
Width = 2,
Color = "blue",
Opacity = 1
};
}
<div id="map">
<ejs-maps id="maps">
<e-maps-layers>
<e-maps-layer shapeData="ViewBag.worldmap">
<e-layersettings-markers>
<e-layersettings-marker visible="true" shape="Circle" fill="white" width="3" animationDuration="0" border="border" dataSource="data2"></e-layersettings-marker>
<e-layersettings-marker visible="true" shape="Rectangle" fill="yellow" width="15" height="4" animationDuration="0" border="border" dataSource="data1"></e-layersettings-marker>
<e-layersettings-marker visible="true" shape="Diamond" fill="white" width="10" height="10" animationDuration="0" border="border" dataSource="data"></e-layersettings-marker>
</e-layersettings-markers>
</e-maps-layer>
</e-maps-layers>
</ejs-maps>
</div>
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.worldmap = GetWorldMap();
ViewBag.worldMap = GetMap();
return View();
}
public object GetWorldMap()
{
string allText = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/WorldMap.json");
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));
}
}
}