Map HtmlHelper Overview
The Telerik UI Map HtmlHelper for ASP.NET MVC is a server-side wrapper for the Kendo UI Map widget.
The Map displays geospatial information organized in layers and is supported for both desktop and mobile devices. It also provides tile layers, shape (vector) layers, and marker layers.
Basic Configuration
- Make sure you followed all the steps from the introductory article on Telerik UI for ASP.NET MVC.
-
Create a new action method which renders the view.
public ActionResult Index() { return View(); }
-
Add a Map.
<%: Html.Kendo().Map() .Name("map") .Layers(layers => { layers.Add() .Type(MapLayerType.Tile) .UrlTemplate("http://#= subdomain #.tile.openstreetmap.org/#= zoom #/#= x #/#= y #.png") .Subdomains("a", "b", "c"); }) %>
@(Html.Kendo().Map() .Name("map") .Layers(layers => { layers.Add() .Type(MapLayerType.Tile) .UrlTemplate("http://#= subdomain #.tile.openstreetmap.org/#= zoom #/#= x #/#= y #.png") .Subdomains("a", "b", "c"); }) )
Events
You can subscribe to all Map events. For a complete example on basic Map events, refer to the demo on using the events of the Map.
Handling by Handler Name
The following example demonstrates how to subscribe to events by a handler name.
<%: Html.Kendo().Map()
.Name("map")
.Layers(layers =>
{
layers.Add()
.Type(MapLayerType.Tile)
.UrlTemplate("http://#= subdomain #.tile.openstreetmap.org/#= zoom #/#= x #/#= y #.png")
.Subdomains("a", "b", "c");
})
.Events(e => e
.Reset("mapReset")
)
%>
<script>
function mapReset(e) {
// Handle the reset event.
}
</script>
@(Html.Kendo().Map()
.Name("map")
.Layers(layers =>
{
layers.Add()
.Type(MapLayerType.Tile)
.UrlTemplate("http://#= subdomain #.tile.openstreetmap.org/#= zoom #/#= x #/#= y #.png")
.Subdomains("a", "b", "c");
})
.Events(e => e
.Reset("mapReset")
)
)
<script>
function mapReset(e) {
// Handle the reset event.
}
</script>
Handling by Template Delegate
The following example demonstrates how to subscribe to events by a template delegate.
@(Html.Kendo().Map()
.Name("map")
.Layers(layers =>
{
layers.Add()
.Type(MapLayerType.Tile)
.UrlTemplate("http://#= subdomain #.tile.openstreetmap.org/#= zoom #/#= x #/#= y #.png")
.Subdomains("a", "b", "c");
})
.Events(e => e
.Reset(@<text>
function() {
// Handle the reset event inline.
}
</text>)
)
)
Referencing Existing Instances
To reference an existing Kendo UI Map instance, use the jQuery.data()
configuration option. Once a reference is established, use the Map API to control its behavior.
// Place the following after the Map for ASP.NET MVC declaration.
<script>
$(function() {
// The Name() of the Map is used to get its client-side instance.
var map = $("#map").data("kendoMap");
});
</script>