Markers
4 Apr 202324 minutes to read
Markers are notes that are used to leave a message on the Maps. It indicates or marks a specific location with desired symbols on the Maps. It can be enabled by setting the Visible
property of the MapsMarker
to true.
Adding marker
To add the markers, the DataSource
property of the MapsMarker
has a list of objects that contains the data for markers. Using this property, any number of markers can be added to the layers of the Maps. By default, it displays the markers based on the specified latitude and longitude in the given data source. Each data source object contains the following list of properties.
- latitude - The latitude point which determines the X location of the marker.
- longitude - The longitude point which determines the Y location of the marker.
@using Syncfusion.EJ2;
@using Syncfusion.EJ2.Maps;
@{
var propertyPath = new[] { "name" };
var data = new[]
{
new {latitude = 49.95121990866204, longitude = 18.468749999999998},
new {latitude = 59.88893689676585, longitude = -109.3359375},
new {latitude = -6.64607562172573, longitude = -55.54687499999999}
};
}
@Html.EJS().Maps("maps").Layers(l =>
{
l.MarkerSettings(marker =>
{
marker.Visible(true).AnimationDuration(0).DataSource(data).Height(20).Width(20).Add();
}).ShapeData(ViewBag.world_map).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.worldmap = GetWorldMap();
ViewBag.world_map = GetMap();
return View();
}
public object GetWorldMap()
{
string allText = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/WorldMap.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));
}
}
}
Adding marker template
The Marker can be added as a template in the Maps component. The Template
property of the MapsMarker
is used to set the HTML element or id of an element as a template.
@using Syncfusion.EJ2;
@using Syncfusion.EJ2.Maps;
@Html.EJS().Maps("maps").Layers(l=> {
l.ShapeData( ViewBag.world_map).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.worldmap = GetWorldMap();
ViewBag.world_map = GetMap();
return View();
}
public object GetWorldMap()
{
string allText = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/WorldMap.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));
}
}
}
Customization
The following properties are available in MapsMarker
class to customize the Markers of the Maps component.
-
Border
- To customize the color, width and opacity of the border for the markers in Maps. -
Fill
- To apply the color for markers in Maps. -
DashArray
- To define the pattern of dashes and gaps that is applied to the outline of the markers in Maps. -
Height
- To customize the height of the markers in Maps. -
Width
- To customize the width of the markers in Maps. -
Offset
- To customize the position of the markers in Maps. -
Opacity
- To customize the transparency of the markers in Maps. -
AnimationDelay
- To change the time delay in the transition for markers. -
AnimationDuration
- To change the time duration of animation for markers.
@using Syncfusion.EJ2
@using Syncfusion.EJ2.Maps
@{
var data = new[]
{
new {latitude = 37.0000, longitude = -120.0000, city= "California"},
new {latitude = 40.7127, longitude = -74.0059, city= "New York"},
new {latitude = 42.000, longitude = -93.000, city= "Iowa"}
};
var border = new MapsBorder
{
Color = "green",
Width = 2,
Opacity = 1
};
}
@Html.EJS().Maps("container").ZoomSettings(new Syncfusion.EJ2.Maps.MapsZoomSettings
{
Enable = true
}).Layers(new List<Syncfusion.EJ2.Maps.MapsLayer>
{
new Syncfusion.EJ2.Maps.MapsLayer
{
ShapeSettings = new MapsShapeSettings
{
Fill = "#C1DFF5"
},
ShapeData = ViewBag.world_map,
MarkerSettings = new List<Syncfusion.EJ2.Maps.MapsMarker>
{
new Syncfusion.EJ2.Maps.MapsMarker
{
Visible = true,
Fill = "red",
DataSource = data,
DashArray = "1",
Shape=MarkerType.Balloon,
TooltipSettings = new MapsTooltipSettings {
Visible = true,
ValuePath= "area",
},
Height= 20,
Width= 20,
AnimationDuration= 0,
AnimationDelay = 100,
Border = border
}
}}}).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.worldmap = GetWorldMap();
ViewBag.world_map = GetMap();
return View();
}
public object GetWorldMap()
{
string allText = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/WorldMap.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));
}
}
}
Marker shapes
The Maps component supports the following marker shapes. To set the shape of the marker, the Shape
property in MapsMarker
is used.
- Balloon
- Circle
- Cross
- Diamond
- Image
- Rectangle
- Start
- Triangle
- VerticalLine
- HorizontalLine
Rendering marker shape as image
To render a marker as an image in Maps, set the Shape
property of MapsMarker
as Image and specify the path of the image to ImageUrl
property. There is another way to render a marker as an image using the ImageUrlValuePath
property of the MapsMarker
. Bind the field name that contains the path of the image in the data source to the ImageUrlValuePath
property.
using Syncfusion.EJ2
@using Syncfusion.EJ2.Maps
@{ var data = new[]
{
new {latitude = 37.0000, longitude = -120.0000, city= "California"},
new {latitude = 40.7127, longitude = -74.0059, city= "New York"},
new {latitude = 42.000, longitude = -93.000, city= "Iowa"}
}; }
@Html.EJS().Maps("container").Layers(new List<Syncfusion.EJ2.Maps.MapsLayer>
{
new Syncfusion.EJ2.Maps.MapsLayer
{
ShapeData = ViewBag.worldMap,
ShapeSettings = new MapsShapeSettings
{
Fill="lightgray"
},
MarkerSettings = new List<Syncfusion.EJ2.Maps.MapsMarker>
{
new Syncfusion.EJ2.Maps.MapsMarker
{
Visible = true,
Fill = "green",
DataSource = data,
Shape=MarkerType.Image,
Height= 20,
Width= 20,
ImageUrl="~/ballon.png"
}
}}}).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.worldmap = GetWorldMap();
ViewBag.world_map = GetMap();
return View();
}
public object GetWorldMap()
{
string allText = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/WorldMap.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));
}
}
}
Multiple marker groups
Multiple groups of markers can be added in the Maps by adding multiple MapsMarker
in the MapsMarkers
and customization for the markers can be done with the MapsMarker
.
@using Syncfusion.EJ2
@using Syncfusion.EJ2.Maps
@{
var data = new[]
{
new {latitude = 37.0000, longitude = -120.0000, city= "California"},
new {latitude = 40.7127, longitude = -74.0059, city= "New York"},
new {latitude = 42.000, longitude = -93.000, city= "Iowa"}
};
var data1 = new[]
{
new {latitude = 19.228825, longitude = 72.854118, city= "Mumbai"},
new {latitude = 28.610001, longitude = 77.230003, city= "Delhi"},
new {latitude = 13.067439, longitude = 80.237617, city= "Chennai"}
};
}
@Html.EJS().Maps("container").ZoomSettings(new Syncfusion.EJ2.Maps.MapsZoomSettings
{
Enable = true
}).Layers(new List<Syncfusion.EJ2.Maps.MapsLayer>
{
new Syncfusion.EJ2.Maps.MapsLayer
{
ShapeData = ViewBag.world_map,
MarkerSettings = new List<Syncfusion.EJ2.Maps.MapsMarker>
{
new Syncfusion.EJ2.Maps.MapsMarker
{
Visible = true,
Fill = "green",
DataSource = data,
Shape=MarkerType.Diamond,
Height= 15,
Width= 15
},
new Syncfusion.EJ2.Maps.MapsMarker
{
Visible = true,
Fill = "green",
DataSource = data1,
Shape=MarkerType.Circle,
Height= 15,
Width= 15
}
}}}).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.worldmap = GetWorldMap();
ViewBag.world_map = GetMap();
return View();
}
public object GetWorldMap()
{
string allText = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/WorldMap.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));
}
}
}
Customize marker shapes from data source
Bind different colors and shapes to the marker from data source
Using the ShapeValuePath
and ColorValuePath
properties, the color and shape of the marker can be applied from the given data source. Bind the data source to the DataSource
property of the MapsMarker
class and set the field names that contains the shape and color values in the data source to the ShapeValuePath
and ColorValuePath
properties.
@using Syncfusion.EJ2
@using Syncfusion.EJ2.Maps
@{
var data = new[]
{
new {latitude = 49.95121990866204, longitude = 18.468749999999998, name="Europe", color="red",
shape="Triangle"},
new {latitude = 59.88893689676585, longitude = -109.3359375, name="North America", color="blue",
shape="Pentagon"},
new {latitude = -6.64607562172573, longitude = -55.54687499999999, name="South America", color="green",
shape="InvertedTriangle"}
};
}
@Html.EJS().Maps("container").Layers(new List<Syncfusion.EJ2.Maps.MapsLayer>
{
new Syncfusion.EJ2.Maps.MapsLayer
{
ShapeData = ViewBag.world_map,
MarkerSettings = new List<Syncfusion.EJ2.Maps.MapsMarker>
{
new Syncfusion.EJ2.Maps.MapsMarker
{
Visible = true,
DataSource = data,
ShapeValuePath = "shape",
ColorValuePath = "color"
}
}}}).Render()
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Syncfusion.EJ2.Maps;
using System.Web.Script.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using EJ2MVCSampleBrowser.Models;
namespace EJ2MVCSampleBrowser.Controllers.Maps
{
public partial class MapsController : Controller
{
// GET: MarkerClustering
public ActionResult MarkerClustering()
{
ViewBag.worldmap = GetWorldMap();
ViewBag.world_map = GetMap();
return View();
}
public object GetWorldMap()
{
string allText = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/WorldMap.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));
}
}
}
Setting value path from the data source
The latitude and longitude values are used to determine the location of each marker in the Maps. The LatitudeValuePath
and LongitudeValuePath
properties are used to specify the value path that presents in the data source of the marker. In the following example, the field name from the data source is set to the LatitudeValuePath
and LongitudeValuePath
properties.
@using Syncfusion.EJ2
@using Syncfusion.EJ2.Maps
@{
var data = new[]
{
new {latitude = 49.95121990866204, longitude = 18.468749999999998},
new {latitude = 59.88893689676585, longitude = -109.3359375},
new {latitude = -6.64607562172573, longitude = -55.54687499999999}
};
}
@Html.EJS().Maps("container").Layers(new List<Syncfusion.EJ2.Maps.MapsLayer>
{
new Syncfusion.EJ2.Maps.MapsLayer
{
ShapeData = ViewBag.world_map,
MarkerSettings = new List<Syncfusion.EJ2.Maps.MapsMarker>
{
new Syncfusion.EJ2.Maps.MapsMarker
{
Visible = true,
LatitudeValuePath = "latitude",
LongitudeValuePath = "longitude",
DataSource = data
}
}}}).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.worldmap = GetWorldMap();
ViewBag.world_map = GetMap();
return View();
}
public object GetWorldMap()
{
string allText = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/WorldMap.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));
}
}
}
Repositioning the marker using drag and drop
The markers on the map can be dragged and dropped to change their position. To enable marker drag and drop, set the EnableDrag property to true in the MarkerSettings property.
@using Syncfusion.EJ2
@using Syncfusion.EJ2.Maps
@{
var data = new[]
{
new { latitude = 49.95121990866204, longitude = 18.468749999999998, name= "MarkerOne" },
new { latitude = 59.88893689676585, longitude = -109.3359375, name="MarkerTwo"},
new { latitude = -6.64607562172573, longitude = -55.54687499999999 , name="MarkerThree"},
new { latitude = 23.644385824912135, longitude= 77.83189239539234 , name= "MarkerFour"},
new { latitude = 63.66569332894224, longitude= 98.2225173953924 , name= "MarkerFive"}
};
var border = new MapsBorder
{
Color = "#285255",
Width = 2,
Opacity = 1
};
}
@Html.EJS().Maps("container").Layers(new List<Syncfusion.EJ2.Maps.MapsLayer>
{
new Syncfusion.EJ2.Maps.MapsLayer
{
ShapeData = ViewBag.world_map,
ShapeSettings = new MapsShapeSettings {
Fill="#C3E6ED"
},
MarkerSettings = new List<Syncfusion.EJ2.Maps.MapsMarker>
{
new Syncfusion.EJ2.Maps.MapsMarker
{
Visible = true,
EnableDrag = true,
AnimationDuration= 0,
Shape= MarkerType.Balloon,
Border = border,
TooltipSettings = new MapsTooltipSettings {
Visible = true,
ValuePath = "name"
},
Width= 20,
Height= 20,
DataSource = data
}
}}}).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.worldmap = GetWorldMap();
ViewBag.world_map = GetMap();
return View();
}
public object GetWorldMap()
{
string allText = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/WorldMap.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));
}
}
}
The data of the drag and dropped marker in the marker data source can be customized using the MarkerDragStart and MarkerDragEnd events. When you change the appropriate marker data, the tooltip and legend item text of that marker are automatically updated. The following properties are available in the event argument of the marker drag events.
Argument Name | Description |
---|---|
dataIndex | It represents the index of the data of the dragged marker in the marker data source. |
latitude | It represents the latitude coordinate point of the dragged marker. |
longitude | It represents the longitude coordinate point for the dragged marker. |
markerIndex | It represents the index of the marker setting. |
layerIndex | It represents the index of the layer in which the marker belongs. |
name | It represents the name of the event. |
x | It represents the horizontal location of the mouse pointer on the map when the drag action is performed. |
y | It represents the vertical location of the mouse pointer on the map when the drag action is performed. |
The following example shows how to use marker drag events to customize the data of the drag and dropped marker in the marker data source.
@using Syncfusion.EJ2
@using Syncfusion.EJ2.Maps
@{
var data = new[]
{
new { latitude = 49.95121990866204, longitude = 18.468749999999998, name= "MarkerOne" },
new { latitude = 59.88893689676585, longitude = -109.3359375, name="MarkerTwo"},
new { latitude = -6.64607562172573, longitude = -55.54687499999999 , name="MarkerThree"},
new { latitude = 23.644385824912135, longitude= 77.83189239539234 , name= "MarkerFour"},
new { latitude = 63.66569332894224, longitude= 98.2225173953924 , name= "MarkerFive"}
};
var border = new MapsBorder
{
Color = "#285255",
Width = 2,
Opacity = 1
};
}
@Html.EJS().Maps("container").MarkerDragEnd("markerDragEnd").MarkerDragStart("markerDragStart").LegendSettings(legend => legend.Visible(true).Type(LegendType.Markers).ShapeBorder(shb => shb.Color("#285255").Width(2))).Layers(new List<Syncfusion.EJ2.Maps.MapsLayer>
{
new Syncfusion.EJ2.Maps.MapsLayer
{
ShapeData = ViewBag.world_map,
ShapeSettings = new MapsShapeSettings {
Fill="#C3E6ED"
},
MarkerSettings = new List<Syncfusion.EJ2.Maps.MapsMarker>
{
new Syncfusion.EJ2.Maps.MapsMarker
{
Visible = true,
LegendText="name",
EnableDrag = true,
AnimationDuration= 0,
Shape= MarkerType.Balloon,
Border = border,
TooltipSettings = new MapsTooltipSettings {
Visible = true,
ValuePath = "name"
},
Width= 20,
Height= 20,
DataSource = data
}
}}}).Render()
<script>
function markerDragStart(args){
// When the marker begins to move on the map, the event is triggered.
}
function markerDragEnd(args) {
// When the marker on the map stops dragging, the event is triggered.
var mapsInstance = document.getElementById('container').ej2_instances[0];
mapsInstance.layers[args.layerIndex].markerSettings[args.markerIndex].dataSource[args.dataIndex].name = 'Dragged Marker ' + (args.dataIndex + 1);
mapsInstance.refresh();
}
</script>
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.world_map = GetMap();
return View();
}
public object GetWorldMap()
{
string allText = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/WorldMap.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));
}
}
}
Marker zooming
The Maps can be initially scaled to the center value based on the marker distance. This can be achieved by setting the ShouldZoomInitially
property in MapsZoomSettings
as true.
@using Syncfusion.EJ2
@using Syncfusion.EJ2.Maps
@{
var data = new[]
{
new {latitude= 49.95121990866204, longitude= 18.468749999999998, name= "Europe" },
new {latitude= 59.88893689676585, longitude= -109.3359375, name= "North America" },
new {latitude= -6.64607562172573, longitude= -55.54687499999999, name= "South America" }
};
}
@Html.EJS().Maps("container").ZoomSettings(new Syncfusion.EJ2.Maps.MapsZoomSettings
{
Enable = true,
ShouldZoomInitially = true,
ToolbarSettings = new {horizontalAlignment = "Near"}
}).Layers(new List<Syncfusion.EJ2.Maps.MapsLayer>
{
new Syncfusion.EJ2.Maps.MapsLayer
{
ShapeData = ViewBag.world_map,
MarkerSettings = new List<Syncfusion.EJ2.Maps.MapsMarker>
{
new Syncfusion.EJ2.Maps.MapsMarker
{
Visible = true,
DataSource = data
}
}}}).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.worldmap = GetWorldMap();
ViewBag.world_map = GetMap();
return View();
}
public object GetWorldMap()
{
string allText = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/WorldMap.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));
}
}
}
Marker clustering
Maps provide support to cluster the markers when they overlap each other. The number on a cluster indicates how many overlapped markers it contains. If zooming is performed on any of the cluster locations in Maps, the number on the cluster will decrease, and the individual markers will be seen on the map. When zooming out, the overlapping marker will increase. So that it can cluster again and increase the count over the cluster.
To enable clustering in markers, set the AllowClustering
property of MapsMarkerClusterSettings
as true and customization of clustering can be done with the MapsMarkerClusterSettings
.
@using Syncfusion.EJ2
@using Syncfusion.EJ2.Maps
@Html.EJS().Maps("container").ZoomSettings(new Syncfusion.EJ2.Maps.MapsZoomSettings
{
Enable = true
}).Layers(new List<Syncfusion.EJ2.Maps.MapsLayer>
{
new Syncfusion.EJ2.Maps.MapsLayer
{
ShapeSettings = new MapsShapeSettings
{
Fill = "#C1DFF5"
},
ShapeData = ViewBag.shape_Data,
MarkerClusterSettings = new MapsMarkerClusterSettings
{
AllowClustering = true,
Shape = MarkerType.Circle,
Height = 40,
Width = 40,
},
MarkerSettings = new List<Syncfusion.EJ2.Maps.MapsMarker>
{
new Syncfusion.EJ2.Maps.MapsMarker
{
Visible = true,
DataSource = ViewBag.Cluster_data,
Shape=MarkerType.Circle,
TooltipSettings = new MapsTooltipSettings {
Visible = true,
ValuePath= "area",
},
Height= 20,
Width= 20,
AnimationDuration= 0,
}
}}}).Render()
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Syncfusion.EJ2.Maps;
using System.Web.Script.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using EJ2MVCSampleBrowser.Models;
namespace EJ2MVCSampleBrowser.Controllers.Maps
{
public partial class MapsController : Controller
{
// GET: MarkerClustering
public ActionResult MarkerClustering()
{
ViewBag.shapeData = this.GetWorldMap();
ViewBag.shape_Data = this.GetWMap();
ViewBag.ClusterData = this.ClusterData();
ViewBag.Cluster_data = this.getData();
return View();
}
public object ClusterData()
{
string allText = System.IO.File.ReadAllText(Server.MapPath("~/App_Data/MapData/ClusterData.json"));
return JsonConvert.DeserializeObject(allText, typeof(object));
}
public object GetWorldMap()
{
string allText = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/WorldMap.js");
return JsonConvert.DeserializeObject(allText);
}
public object getData()
{
string allText = System.IO.File.ReadAllText(Server.MapPath("./wwwroot/scripts/MapsData/ClusterData.json"));
return JsonConvert.DeserializeObject(allText, typeof(object));
}
public object GetWMap()
{
string allText = System.IO.File.ReadAllText(Server.MapPath("~/App_Data/WorldMap.json"));
return JsonConvert.DeserializeObject(allText, typeof(object));
}
}
}
Customization of marker cluster
The following properties are available to customize the marker clustering in the Maps component.
-
Border
- To customize the color, width and opacity of the border of cluster in Maps. -
ConnectorLineSettings
- To customize the connector line in cluster separating the markers. -
DashArray
- To customize the dash array for the marker cluster in Maps. -
Fill
- Applies the color of the cluster in Maps. -
Height
- To customize the height of the marker cluster in Maps. -
ImageUrl
- To customize the URL path for the marker cluster when the cluster shape is set as image in Maps. -
LabelStyle
- To customize the text in marker cluster. -
Offset
- To customize the offset position for the marker cluster in Maps. -
Opacity
- To customize the opacity of the marker cluster. -
Shape
- To customize the shape for the cluster of markers. -
Width
- To customize the width of the marker cluster in Maps.
@using Syncfusion.EJ2
@using Syncfusion.EJ2.Maps
@Html.EJS().Maps("container").ZoomSettings(new Syncfusion.EJ2.Maps.MapsZoomSettings
{
Enable = true
}).Layers(new List<Syncfusion.EJ2.Maps.MapsLayer>
{
new Syncfusion.EJ2.Maps.MapsLayer
{
ShapeData = ViewBag.worldmap,
MarkerClusterSettings = new MapsMarkerClusterSettings
{
AllowClustering = true,
Height = 40,
Width = 40,
Fill = "green",
Opacity = 0.9,
AllowClusterExpand = true,
Shape = Syncfusion.EJ2.Maps.MarkerType.Circle,
LabelStyle = new MapsFont
{
Color = "White"
},
ConnectorLineSettings = new MapsConnectorLineSettings
{
Color = "orange",
Opacity = 0.8,
Width = 2
}
},
MarkerSettings = new List<Syncfusion.EJ2.Maps.MapsMarker>
{
new Syncfusion.EJ2.Maps.MapsMarker
{
Visible = true,
DataSource = ViewBag.ClusterData,
Shape= MarkerType.Balloon,
Height = 20,
Width = 20,
AnimationDuration = 0,
}
}}}).Render()
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Syncfusion.EJ2.Maps;
using System.Web.Script.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using EJ2MVCSampleBrowser.Models;
namespace EJ2MVCSampleBrowser.Controllers.Maps
{
public partial class MapsController : Controller
{
// GET: MarkerClustering
public ActionResult MarkerClustering()
{
ViewBag.shapeData = this.GetWorldMap();
ViewBag.ClusterData = this.ClusterData();
return View();
}
public object ClusterData()
{
string allText = System.IO.File.ReadAllText(Server.MapPath("~/App_Data/MapData/ClusterData.json"));
return JsonConvert.DeserializeObject(allText, typeof(object));
}
public object GetWorldMap()
{
string allText = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/WorldMap.js");
return JsonConvert.DeserializeObject(allText);
}
}
}
Expanding the marker cluster
The cluster is formed by grouping an identical and non-identical marker from the surrounding area. By clicking on the cluster and setting the AllowClusterExpand
property in MapsMarkerClusterSettings
as true to expand the identical markers. If zooming is performed in any of the locations of the cluster, the number on the cluster will decrease and the overlapping marker will be split into an individual marker on the map. When performing zoom out, it will increase the marker count and then cluster it again.
@using Syncfusion.EJ2
@using Syncfusion.EJ2.Maps
@{
var data = new[]
{
new { latitude= 49.95121990866204, longitude= 18.468749999999998, name="Europe" },
new { latitude= 49.95121990866204, longitude= 18.468749999999998, name="Europe" },
new { latitude= 49.95121990866204, longitude= 18.468749999999998, name="Europe" },
new { latitude= 49.95121990866204, longitude= 18.468749999999998, name="Europe" },
new { latitude= 49.95121990866204, longitude= 18.468749999999998, name="Europe" },
new { latitude= 49.95121990866204, longitude= 18.468749999999998, name="Europe" },
new { latitude= 49.95121990866204, longitude= 18.468749999999998, name="Europe" },
new { latitude= 59.88893689676585, longitude= -109.3359375, name="North America" },
new { latitude= -6.64607562172573, longitude= -55.54687499999999, name="South America"}
};
}
@Html.EJS().Maps("container").ZoomSettings(new Syncfusion.EJ2.Maps.MapsZoomSettings
{
Enable = true
}).Layers(new List<Syncfusion.EJ2.Maps.MapsLayer>
{
new Syncfusion.EJ2.Maps.MapsLayer
{
ShapeData = ViewBag.worldmap,
MarkerClusterSettings = new MapsMarkerClusterSettings
{
AllowClustering = true,
AllowClusterExpand = true,
Height = 40,
Width = 40,
LabelStyle = new MapsFont
{
Color = "White"
}
},
MarkerSettings = new List<Syncfusion.EJ2.Maps.MapsMarker>
{
new Syncfusion.EJ2.Maps.MapsMarker
{
Visible = true,
DataSource = data
}
}}}).Render()
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Syncfusion.EJ2.Maps;
using System.Web.Script.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using EJ2MVCSampleBrowser.Models;
namespace EJ2MVCSampleBrowser.Controllers.Maps
{
public partial class MapsController : Controller
{
// GET: MarkerClustering
public ActionResult MarkerClustering()
{
ViewBag.shapeData = GetWorldMap();
ViewBag.clusterdata = GetClusterData();
return View();
}
public object GetWorldMap()
{
string allText = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/WorldMap.js");
return JsonConvert.DeserializeObject(allText);
}
public object GetClusterData()
{
string text = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/ClusterData.js");
return JsonConvert.DeserializeObject(text, typeof(object));
}
}
}
Tooltip for marker
Tooltip is used to display more information about a marker on mouse over or touch end event. This can be enabled separately for marker by setting the Visible
property of MapsTooltipSettings
to true. The ValuePath
property in the MapsTooltipSettings
takes the field name that presents in dataSource and displays that value as tooltip text.
@using Syncfusion.EJ2
@using Syncfusion.EJ2.Maps
@{
var border = new MapsBorder
{
Width = 2,
Color = "green",
Opacity = 1
};
var data = new[]
{
new { latitude= 40.7424509, longitude= 1-74.0081468, name="New York" }
};
}
@Html.EJS().Maps("container").ZoomSettings(new Syncfusion.EJ2.Maps.MapsZoomSettings
{
Enable = true
}).Layers(new List<Syncfusion.EJ2.Maps.MapsLayer>
{
new Syncfusion.EJ2.Maps.MapsLayer
{
ShapeData = ViewBag.usamap,
MarkerSettings = new List<Syncfusion.EJ2.Maps.MapsMarker>
{
new Syncfusion.EJ2.Maps.MapsMarker
{
Visible = true,
Fill = "white",
DataSource = data,
Shape=MarkerType.Circle,
TooltipSettings = new MapsTooltipSettings {
Visible = true,
ValuePath= "name",
},
Width= 2,
AnimationDuration= 0,
Border = border
}
}}}).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;
using Syncfusion.EJ2.Charts;
namespace EJ2_Core_Application.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
ViewBag.usa = GetUSMap();
ViewBag.usamap = GetUSAMap();
return View();
}
public object GetUSMap()
{
string text = System.IO.File.ReadAllText("./wwwroot/scripts/MapsData/USA.json");
return JsonConvert.DeserializeObject(text);
}
public object GetUSAMap()
{
string allText = System.IO.File.ReadAllText(Server.MapPath("~/App_Data/USA.json"));
return JsonConvert.DeserializeObject(text);
}
}
}