Center and Zoom on Bing Maps WPF

I created a WPF dialog box for Bing maps and would like to programmatically adjust the center and scale. I tried to use SetValue(), but I did not find the right to transfer it.

Here is the XAML for my Bing Maps dialog:

<Window 
        x:Class="RAPMkI.BingMapsDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF"
        Title="BingMapsDialog" Height="378" Width="467">
    <Grid>
        <m:Map CredentialsProvider="Haha, nice try."/>
        <Button Content="Locate" Margin="0,0,0,0" Name="button1" HorizontalAlignment="Right" Width="Auto" Height="Auto" VerticalAlignment="Top" />
    </Grid>
</Window>

The encoding is as follows:

namespace RAPMkI
{
    /// <summary>
    /// Interaction logic for BingMapsDialog.xaml
    /// </summary>
    public partial class BingMapsDialog : Window
    {
        public BingMapsDialog(Location center, int zoom)
        {
            InitializeComponent();
        }
    }
}

Is there a way to set the center and zoom level of my dialog box during initialization, using the Locationzoom that I went through?

+3
source share
4 answers

First you need to specify the name of your card so that you can access it programmatically. eg:.

<m:Map Name="theMap" CredentialsProvider="Haha, nice try."/>

Center ZoomLevel, , . :

public BingMapsDialog(Location center, int zoom)
{
    InitializeComponent();
    theMap.Center = center;
    theMap.ZoomLevel = zoom;
}

, Center ZoomLevel Loaded.

+4

, , , - , , - .

Center - , . (Lat: 0, Long: 0).

, , SetView(Location location, Double Zoom)

:
https://msdn.microsoft.com/en-us/library/hh709343.aspx

:

public BingMapsDialog(Location center, double zoom)
{
    InitializeComponent();
    theMap.SetView(center, zoom);
}

, .

+7

: ZoomLevel Center. , , , ZoomLevel Center.

ZoomLevel , , , , viewmodel. .

* , "TwoWays"

+1

XAML, :

<m:Map x:Name="mMap" 
               CredentialsProvider= "xxxxxxxxxx" 
               Center="40.13618,-0.45822" 
               ZoomLevel="15">
</m:Map>

, , :

mMap.SetView(mylocation, myzoomlevel) 'mylocation -> Location, myzoomlevel -> Double

:

mMap.Center = mylocation
mMap.ZoomLevel = myzoomlevel
0

Source: https://habr.com/ru/post/1533548/


All Articles