You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: knowledge-base/map-center-on-selected-marker.md
+15-12Lines changed: 15 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,10 @@
1
1
---
2
-
title: Center the Map on a Selected Marker
3
-
description: Learn how to center a Telerik Map for Blazor component on a marker selected from a list.
2
+
title: Center Map on Selected Marker
3
+
description: Learn how to programmatically center a Telerik Map for Blazor component on a marker selected from a list.
4
4
type: how-to
5
5
page_title: How to Center a Map on Marker in Blazor Applications
6
-
slug: map-center-on-selected-marker
7
-
tags: map, blazor, center, marker, selection, list
6
+
slug: map-kb-center-on-selected-marker
7
+
tags: blazor, map, marker
8
8
res_type: kb
9
9
ticketid: 1671734
10
10
---
@@ -24,26 +24,28 @@ ticketid: 1671734
24
24
25
25
There's a list of markers. I need to center the map on a marker when it's selected from the list.
26
26
27
-
-How can I dynamically update the center of a map based on a marker's coordinates?
27
+
How can I dynamically update the center of a map based on a marker's coordinates?
28
28
29
29
## Solution
30
30
31
31
To center the map on a specific marker's coordinates, use a variable to bind the `Center` parameter of the `TelerikMap` component. Update this variable whenever a selection is made from the list. Here's how you can implement this:
32
32
33
33
1. Use a component like the `TelerikDropDownList` to display the list of markers. Handle the `OnChange` event to update the map's center.
34
34
35
-
2. In the `OnChange` event handler, update the map's `Center` property to the coordinates of the selected marker.
35
+
2. In the `OnChange` event handler, update the map's `Center` property value to the coordinates of the selected marker.
36
+
37
+
>caption Centering the Map on a Selected Marker
36
38
37
39
````RAZOR
38
-
<TelerikDropDownList Data="@MarkerData"
39
-
@bind-Value="@selectedValue"
40
-
TextField="Title"
41
-
ValueField="Id"
40
+
<TelerikDropDownList Data="@MarkerData"
41
+
@bind-Value="@SelectedValue"
42
+
TextField="@nameof(MarkerModel.Title)"
43
+
ValueField="@nameof(MarkerModel.Id)"
42
44
OnChange="@MyOnChangeHandler">
43
45
</TelerikDropDownList>
44
46
45
47
<TelerikMap Center="@MapCenter"
46
-
Zoom="3">
48
+
Zoom="@MapZoom">
47
49
<MapLayers>
48
50
<MapLayer Type="@MapLayersType.Tile"
49
51
Attribution="@LayerAttribution"
@@ -61,7 +63,8 @@ To center the map on a specific marker's coordinates, use a variable to bind the
0 commit comments