This is a migrated thread and some comments may be shown as answers.

Centering Map on Form Load

4 Answers 113 Views
Map
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 05 Dec 2016, 09:43 PM

 

 

        private void frmMapping_Load(object sender, EventArgs e)
        {
            string cacheFolder = @"..\..\cache";

            bingProvider.UseSession = true;
            bingProvider.BingKey = "MyKey";
            LocalFileCacheProvider cache = new LocalFileCacheProvider(cacheFolder);
            bingProvider.CacheProvider = cache;
            bingProvider.ImagerySet = Telerik.WinControls.UI.Map.Bing.ImagerySet.Road;
            this.radMap1.Providers.Add(bingProvider);

            PointG racheer = new PointG(38.595592, -90.429629);
            MapPin racheerPin = new MapPin(racheer);
            racheerPin.Text = "Right Here Man!!!";
            racheerPin.BackColor = Color.AliceBlue;

    }

4 Answers, 1 is accepted

Sort by
0
Scott
Top achievements
Rank 1
answered on 05 Dec 2016, 09:45 PM

OK... Posted accidentally before I was finished.
I am trying center the map on load.  However the map is not centering when I use this code.  Please advise.

Thank you.

-Scott

0
Scott
Top achievements
Rank 1
answered on 05 Dec 2016, 09:47 PM

and forgot the last line of code....

this.radMap1.MapElement.Center = racheer;

Another suggestion...  The ability to edit Posts rather than have to write additional Reply entries.

-Scott

0
Dimitar
Telerik team
answered on 06 Dec 2016, 11:22 AM
Hello Scott,

Thank you for writing.

First, you need to add the pin to a layer and then use the BringIntoView method: 
private void radButton1_Click(object sender, EventArgs e)
{
    PointG racheer = new PointG(38.595592, -90.429629);
    MapPin racheerPin = new MapPin(racheer);
    racheerPin.Text = "Right Here Man!!!";
    racheerPin.BackColor = Color.Red;
 
    this.radMap1.MapElement.Layers.Add(new MapLayer("PinLayer"));
    this.radMap1.MapElement.Layers[0].Add(racheerPin);
  
    this.radMap1.MapElement.BringIntoView(racheer);
}

I hope this information is useful. Let me know if you need further assistance.

Regards,
Dimitar
Telerik by Progress
Telerik UI for WinForms is ready for Visual Studio 2017 RC! Learn more.
0
MrBizzl
Top achievements
Rank 2
Iron
answered on 27 Dec 2021, 10:32 AM

Hello

It is important to adjust the zoom before positioning.
Otherwise, probably due to a calculation inaccuracy, an incorrect map section will be displayed.

Private Sub bingProvider_InitializationComplete(sender As Object, e As EventArgs)
        ' Position New Your
        Dim latitude As Double = 40.712728
        Dim longitude As Double = -74.006015
        Dim location As New Map.PointG(latitude, longitude)
        Dim pinsLayer As MapLayer = New MapLayer("Pins")
        mapStart.Layers.Add(pinsLayer)
        Dim pin As New MapPin(location)
        pin.Size = New Size(20, 40)
        pin.BackColor = Color.Red
        mapStart.MapElement.Layers("Pins").Add(pin)

        mapStart.Zoom(18)
        mapStart.BringIntoView(location)

End Sub

Best
Timo

Dess | Tech Support Engineer, Principal
Telerik team
commented on 27 Dec 2021, 11:24 AM

Hi, Timo,

Thank you for pointing this out. Please have in mind that the internal logic of the BringIntoView method calculates the location of the passed PointG on the viewport considering the current map's ZoomLevel and then it performs a pan operation to make the point visible and centered. If you change the zoom level after bringing the point into the view, it may not be centered anymore. That is why you are obtaining such a behavior.

Tags
Map
Asked by
Scott
Top achievements
Rank 1
Answers by
Scott
Top achievements
Rank 1
Dimitar
Telerik team
MrBizzl
Top achievements
Rank 2
Iron
Share this question
or