WPF:根据 Bing 地图的当前比例动态调整网格的大小

WPF: Dynamically adjust the size of a grid with respect to current scale of Bing map

我正在使用 Visual Studio Community 2017。

我拥有的和有效的:

看起来像这样:

我现在想做的事情:从两张截图可以看出,网格的大小是静态的,不会随着用户放大而改变。我想要完全改变:我希望网格具有固定到地图的大小,即当用户缩放 in/out 时网格大小会发生变化。具体来说,我想:

它应该(大致)如下图所示。红色圆圈突出显示点 (47.6424,-122.3219)。当用户缩小时,网格应该根据 Bing 地图的比例动态变小。两个图中网格的缩放比例不是 100% 准确,但你明白了。

我怎样才能做到这一点? 注意: 将来我需要做同样的事情,但使用六边形网格。我提到这一点是为了防止这可能会改变我想要采用的方法。

谢谢!

XAML:(Bing 地图需要密钥)

<Window x:Class="squareGridBing.MainWindow"
    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"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:ProofOfConcept"
    mc:Ignorable="d"
    Title="Square grid on Bing Map" Height="450" Width="808.4">
<Grid>
    <m:Map Margin="5,0,249.6,0" CredentialsProvider="[YOUR KEY TO BE INSERTED HERE]">
        <Grid ShowGridLines="True" Margin="100,100,220,100" Opacity="0.5">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>

            <Button Grid.Column="0" Grid.Row="0" Click="ButtonClick" />
            <Button Grid.Column="1" Grid.Row="0" Click="ButtonClick" />
            <Button Grid.Column="2" Grid.Row="0" Click="ButtonClick" />

            <Button Grid.Column="0" Grid.Row="1" Click="ButtonClick" />
            <Button Grid.Column="1" Grid.Row="1" Click="ButtonClick" />
            <Button Grid.Column="2" Grid.Row="1" Click="ButtonClick" />

            <Button Grid.Column="0" Grid.Row="2" Click="ButtonClick" />
            <Button Grid.Column="1" Grid.Row="2" Click="ButtonClick" />
            <Button Grid.Column="2" Grid.Row="2" Click="ButtonClick" />

        </Grid>
    </m:Map>
</Grid>

CS:

using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace squareGridBing
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void ButtonClick(object sender, RoutedEventArgs e)
    {
        Button _btn = sender as Button;

        int _row = (int)_btn.GetValue(Grid.RowProperty);
        int _column = (int)_btn.GetValue(Grid.ColumnProperty);
        MessageBox.Show(string.Format("Button clicked at column {0}, row {1}", _column, _row));
    }
}
}

您是否考虑过将网格(或六边形,因为您想将其扩展到其他形状)作为多边形直接添加到地图? https://msdn.microsoft.com/en-us/library/hh868034.aspx 以这种方式添加到地图的多边形随地图内容移动和缩放。您应该能够在用户单击事件以获取他们单击的单元格时收听事件。