New to Telerik UI for ASP.NET MVCStart a free 30-day trial

Adding Routes in Map

Environment

ProductProgress Telerik UI for ASP.NET MVC Map
Progress Telerik UI for ASP.NET MVC versionCreated 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:

  1. Create a Model that will hold a PointTo field, which will be utilized for the drawing line shapes and establishing the route.
  2. Supplement the data on the backend with RouteModel instances.
  3. Create 3 layers within the Map component that will hold a Tile, Shape, and Marker. From there, bind the previously defined data for the markers using a DataSource mediator.
  4. Subscribe to the Reset event.
  5. To draw the routes, create a custom function that will execute for drawing lines using the help of the Kendo UI Drawing API.
  6. Within the Reset event handler, traverse through each of the Markers' Layer and execute the linkMarker 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("&copy; <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");
        })
    )

More ASP.NET MVC Map Resources

See Also