New to Telerik UI for ASP.NET MVC? Start a free 30-day trial
Adding Routes in Map
Environment
Product | Progress Telerik UI for ASP.NET MVC Map |
Progress Telerik UI for ASP.NET MVC version | Created with the 2023.2.606 version |
Description
How can I add routes to given location markers when working with the Telerik UI for ASP.NET MVC Map component?
Solution
Follow the steps below to achieve the desired scenario:
- Create a
Model
that will hold aPointTo
field, which will be utilized for the drawing line shapes and establishing the route. - Supplement the data on the backend with
RouteModel
instances. - Create
3
layers within the Map component that will hold aTile
,Shape
, andMarker
. From there, bind the previously defined data for the markers using a DataSource mediator. - Subscribe to the
Reset
event. - To draw the routes, create a custom function that will execute for drawing lines using the help of the Kendo UI Drawing API.
- Within the
Reset
event handler, traverse through each of the Markers' Layer and execute thelinkMarker
function created in the previous step.
The
PointTo
field needs to include a Longitude and Latitude similar to an existing object.
Index.cshtml
@(Html.Kendo().Map()
.Name("map")
.Center(30.268107, -97.744821)
.Zoom(6)
.Layers(layers =>
{
layers.Add() // Layer 1
.Type(MapLayerType.Tile)
.UrlTemplate("https://#= subdomain #.tile.openstreetmap.org/#= zoom #/#= x #/#= y #.png")
.Subdomains("a", "b", "c")
.Attribution("© <a href='https://osm.org/copyright'>OpenStreetMap contributors</a>");
layers.Add() // Layer 2
.Type(MapLayerType.Shape);
layers.Add() // Layer 3
.Type(MapLayerType.Marker)
.DataSource(dataSource => dataSource
.Read(read => read.Action("_LoadRoutes", "Home"))
)
.LocationField("Location")
.TitleField("Title");
})
.Events(events => {
events.Reset("onReset");
})
)