Search results

Markers

Markers are notes that are used to show some message on the map. Marker can be set to map using the following two ways:

  • Marker and marker template

  • Adding marker objects to map.

Marker and marker template

The markerSettings.dataSource property has a list of objects that contains the data for annotation. By default, it displays the bound data at the specified latitude and longitude. The markerSettings.template property is used for customizing the template for markers.

Note: The markerSettings property is an array property.

razor
markers.cs
@using Syncfusion.EJ2;
@using Syncfusion.EJ2.Maps;
@Html.EJS().Maps("maps").Layers(l=> {
    l.ShapeData(ViewBag.usmap).MarkerSettings(new List<MapsMarker>
    {
        new MapsMarker{Visible=true, Template="#template", DataSource= new[]
    {
            new {latitude= 37.0000, longitude= -120.0000, city= "California" },
            new {latitude= 40.7127, longitude= -74.0059, city= "New York" },
            new {latitude= 42.0000, longitude= -93.0000, city= "Iowa" }
    }}
    }).Add();
}).Render()
<div id="template" style="display: none;">
    <div>
        <div style="background-image:url(http://js.syncfusion.com/demos/web/Images/map/pin.png);margin-left:3px;height:40px;width:25px;margin-top:-15px;">
        </div>
    </div>
</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.usmap = GetUSMap();
            return View();
        }
        public object GetUSMap()
        {
            string allText = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/usMap.js");
            return JsonConvert.DeserializeObject(allText);
        }
    }
}

Adding marker objects to map

The “n” number of markers can be added to shape layers using the markerSettings.dataSource property. Each dataSource object contains the following list of properties:

label: Text that displays some information about the annotation in text format. latitude: Latitude point that determines the y-axis position of annotation. longitude: Longitude point that determine the x-axis position of annotation.

razor
marker-label.cs
@using Syncfusion.EJ2;
@using Syncfusion.EJ2.Maps;
@Html.EJS().Maps("maps").Layers(l=> {
    l.ShapeData(ViewBag.usmap).MarkerSettings(new List<MapsMarker>
    {
        new MapsMarker{Visible=true, Template="#template", DataSource= new[]
    {
            new {latitude= 37.0000, longitude= -120.0000, city= "California" },
            new {latitude= 40.7127, longitude= -74.0059, city= "New York" },
            new {latitude= 42.0000, longitude= -93.0000, city= "Iowa" }
    }}
    }).Add();
}).Render()
<div id="template" style="display: none;">
    <div>
        <div style="margin-left:8px;height:45px;width:120px;margin-top:-23px;">
            <label style="color:black;margin-left:15px;font-weight:normal;">\{\{\:city\}\}</label>
        </div>
    </div>
</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.usmap = GetUSMap();
            return View();
        }
        public object GetUSMap()
        {
            string allText = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/usMap.js");
            return JsonConvert.DeserializeObject(allText);
        }
    }
}

Enable the Legend for map markers

The legend can be enabled for marker by setting the legendSettings.type to Markers and legend visible to true. Refer to the following code sample to enable the legend for the markers:

razor
legend.cs
@using Syncfusion.EJ2;
@using Syncfusion.EJ2.Maps;
@Html.EJS().Maps("maps").LegendSettings(legend=> legend.Visible(true).Type(LegendType.Markers)).Layers(l=> {
    l.ShapeData(ViewBag.usmap).MarkerSettings(new List<MapsMarker>
    {
        new MapsMarker{Visible=true, Shape=Syncfusion.EJ2.Maps.MarkerType.Diamond, LegendText="city", DataSource= new[]
    {
            new {latitude= 37.0000, longitude= -120.0000, city= "California" },
            new {latitude= 40.7127, longitude= -74.0059, city= "New York" },
            new {latitude= 42.0000, longitude= -93.0000, city= "Iowa" }
    }}
    }).Add();
}).Render()
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.usmap = GetUSMap();
            return View();
        }
        public object GetUSMap()
        {
            string allText = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/usMap.js");
            return JsonConvert.DeserializeObject(allText);
        }
    }
}

Refer to the API for marker feature.