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
Modelthat will hold aPointTofield, which will be utilized for the drawing line shapes and establishing the route. - Supplement the data on the backend with
RouteModelinstances. - Create
3layers 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
Resetevent. - 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
Resetevent handler, traverse through each of the Markers' Layer and execute thelinkMarkerfunction created in the previous step.
The
PointTofield needs to include a Longitude and Latitude similar to an existing object.
Razor
@(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");
})
)