Skip to content

Commit c83e04c

Browse files
kb(Map): address comments
1 parent 02532a6 commit c83e04c

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

knowledge-base/map-center-on-selected-marker.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
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.
44
type: how-to
55
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
88
res_type: kb
99
ticketid: 1671734
1010
---
@@ -24,26 +24,28 @@ ticketid: 1671734
2424

2525
There's a list of markers. I need to center the map on a marker when it's selected from the list.
2626

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?
2828

2929
## Solution
3030

3131
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:
3232

3333
1. Use a component like the `TelerikDropDownList` to display the list of markers. Handle the `OnChange` event to update the map's center.
3434

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
3638
3739
````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)"
4244
OnChange="@MyOnChangeHandler">
4345
</TelerikDropDownList>
4446
4547
<TelerikMap Center="@MapCenter"
46-
Zoom="3">
48+
Zoom="@MapZoom">
4749
<MapLayers>
4850
<MapLayer Type="@MapLayersType.Tile"
4951
Attribution="@LayerAttribution"
@@ -61,7 +63,8 @@ To center the map on a specific marker's coordinates, use a variable to bind the
6163
6264
@code {
6365
private double[] MapCenter { get; set; } = new double[] { 30.268107, -97.744821 };
64-
private int selectedValue { get; set; }
66+
private int SelectedValue { get; set; }
67+
private int MapZoom { get; set; } = 3;
6568
6669
private readonly string[] LayerSubdomains = new string[] { "a", "b", "c" };
6770
private const string LayerUrlTemplate = "https://#= subdomain #.tile.openstreetmap.org/#= zoom #/#= x #/#= y #.png";

0 commit comments

Comments
 (0)