How to reproduce: check the attached video
Workaround: create a custom MapSearchBarElement
public class MyRadMap : RadMap
{
public override string ThemeClassName
{
get
{
return typeof(RadMap).FullName;
}
}
protected override RadMapElement CreateMapElement()
{
return new MyRadMapElement();
}
}
public class MyRadMapElement : RadMapElement
{
protected override Type ThemeEffectiveType
{
get
{
return typeof(RadMapElement);
}
}
protected override MapSearchBarElement CreateSearchBarElement()
{
return new MyMapSearchBarElement(this);
}
}
public class MyMapSearchBarElement : MapSearchBarElement
{
public MyMapSearchBarElement(MyRadMapElement mapElement)
: base(mapElement)
{ }
protected override Type ThemeEffectiveType
{
get
{
return typeof(MapSearchBarElement);
}
}
protected override void SearchProviderSearchError(object sender, SearchErrorEventArgs e)
{
IMapSearchProvider provider = sender as IMapSearchProvider;
provider.SearchCompleted -= SearchProviderSearchCompleted;
provider.SearchError -= SearchProviderSearchError;
if (this.ElementTree != null)
{
UnsubscribeToTextBoxEvents(this.SearchTextBoxElement);
RadMessageBox.SetThemeName(this.ElementTree.ThemeName);
RadMessageBox.Show(e.Error.Message);
SubscribeToTextBoxEvents(this.SearchTextBoxElement);
}
}
protected override void SubscribeToTextBoxEvents(RadTextBoxElement textBox)
{
textBox.TextChanged += OnSearchTextBoxTextChanged;
textBox.KeyDown += OnSearchTextBoxKeyDown;
}
protected override void UnsubscribeToTextBoxEvents(RadTextBoxElement textBox)
{
textBox.TextChanged -= OnSearchTextBoxTextChanged;
textBox.KeyDown -= OnSearchTextBoxKeyDown;
}
private void OnSearchTextBoxKeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
this.Search(this.SearchTextBoxElement.Text);
}
}
}
1. Open the demo application >> Map >> Search example.
2. Enter some text and press Enter.
3. Move the mouse a little bit and you will notice the search box looses focus.
Workaround: this.radMap1.MapElement.SearchBarElement.SearchTextBoxElement.TextBoxItem.LostFocus+=TextBoxItem_LostFocus;
private void TextBoxItem_LostFocus(object sender, EventArgs e)
{
this.radMap1.MapElement.SearchBarElement.SearchTextBoxElement.TextBoxItem.TextBoxControl.Focus();
}
In the scenario below one should be able to access the defined UserData value in the SearchCompleted event handler
How to reproduce:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.radMap1.ShowSearchBar = true;
BingRestMapProvider bingProvider = this.radMap1.Providers[0] as BingRestMapProvider;
this.radMap1.MapElement.SearchBarElement.SearchProvider = bingProvider;
this.radMap1.MapElement.SearchBarElement.SearchProvider.SearchCompleted += BingProvider_SearchCompleted;
}
private void BingProvider_SearchCompleted(object sender, SearchCompletedEventArgs e)
{
Telerik.WinControls.UI.Map.RectangleG allPoints = new Telerik.WinControls.UI.Map.RectangleG(double.MinValue, double.MaxValue, double.MaxValue, double.MinValue);
this.radMap1.Layers["Pins"].Clear();
foreach (Telerik.WinControls.UI.Map.Bing.Location location in e.Locations)
{
Telerik.WinControls.UI.Map.PointG point = new Telerik.WinControls.UI.Map.PointG(location.Point.Coordinates[0], location.Point.Coordinates[1]);
MapPin pin = new MapPin(point);
pin.Size = new System.Drawing.Size(20, 40);
pin.BackColor = Color.Red;
pin.ToolTipText = location.Address.FormattedAddress;
this.radMap1.MapElement.Layers["Pins"].Add(pin);
allPoints.North = Math.Max(allPoints.North, point.Latitude);
allPoints.South = Math.Min(allPoints.South, point.Latitude);
allPoints.West = Math.Min(allPoints.West, point.Longitude);
allPoints.East = Math.Max(allPoints.East, point.Longitude);
}
if (e.Locations.Length > 0)
{
if (e.Locations.Length == 1)
{
this.radMap1.BringIntoView(new Telerik.WinControls.UI.Map.PointG(e.Locations[0].Point.Coordinates[0], e.Locations[0].Point.Coordinates[1]));
}
else
{
this.radMap1.MapElement.BringIntoView(allPoints);
this.radMap1.Zoom(this.radMap1.MapElement.ZoomLevel - 1);
}
}
else
{
RadMessageBox.Show("No result found for the provided search query!");
}
}
Telerik.WinControls.UI.Map.Bing.SearchRequest request;
private void radButton1_Click(object sender, EventArgs e)
{
Telerik.WinControls.UI.MapLayer pinsLayer = new MapLayer("Pins");
this.radMap1.Layers.Add(pinsLayer);
request = new SearchRequest();
request.Query = "San Marino";
request.SearchOptions.Count = 10;
request.SearchOptions.QueryParse = true;
request.UserData = "Tooltip";
BingRestMapProvider bingProvider = this.radMap1.Providers[0] as BingRestMapProvider;
bingProvider.SearchAsync(request);
}
Workaround: if possible cache the data to be accessed at a later stage