gpt4 book ai didi

wpf - WPF 的 Bing map 、MapLayers/Pushpins 的 ZIndex?

转载 作者:行者123 更新时间:2023-12-01 21:55:11 27 4
gpt4 key购买 nike

只是一个序言,我意识到我正在以非 WPF 友好的方式执行我的解决方案。在完美的世界中,我会使用 MapItemsControl。

好的,我正在使用 WPF 的 Bing Maps 控件。这是我的 Bing map XAML

<m:Map CredentialsProvider="12345" 
x:Name="myMap" UseInertia="True" Loaded="Map_Loaded"
Width="1920" Height="990" Canvas.Top="110" ZoomLevel="5" Center="39.8282,-98.5795">
<m:MapLayer x:Name="MyPushPinLayer">
<Canvas x:Name="ContentPopup" Visibility="Collapsed" Width="250">
<Border Background="White" BorderThickness="1" BorderBrush="Gray" Width="250" Padding="5">
<StackPanel Canvas.Left="20" Canvas.Top="10">
<TextBlock x:Name="ContentPopupText" FontSize="18" FontWeight="Bold" Foreground="#CF0000" Width="240" TextWrapping="Wrap">
</TextBlock>
<TextBlock x:Name="ContentAddress" FontSize="13" Foreground="Black" Width="240" TextWrapping="Wrap"/>
<TextBlock x:Name="ContentQuestions" FontSize="13" Foreground="Black" Width="240" TextWrapping="Wrap" />
</StackPanel>
</Border>
</Canvas>
</m:MapLayer>
</m:Map>

基本上,这会绘制一张 map ,并且我有一个 map 播放器,单击时它将保存工具提示信息。在我后面的代码中,我从服务中提取数据并按程序将图钉添加到 map 中,如下所示:

Pushpin pin = new Pushpin();
pin.Location = new Microsoft.Maps.MapControl.WPF.Location(location.latitude, location.longitude);
pin.Content = location.name;
pin.Template = LGPushPinTemplate;

pin.MouseDown += new MouseButtonEventHandler(pin_MouseDown);
myMap.Children.Add(pin);

非常简单。但是,因为我在加载 map 后在 XAML 和子级中定义弹出层,所以图钉最后出现在 map 的子结构中,因此模态信息框出现在任何图钉下方。有没有办法重新排列这些项目的 z 顺序,而无需添加/删除 map 子集合中的所有内容?|

最佳答案

这个问题是可以解决的。我在四处搜索时发现了一些可能的解决方案。见下文。希望您能找到适合您的代码/情况的东西。

  1. 你能在最后动态创建弹出层吗?与生成图钉的方式类似。
  2. 将弹出窗口 Canvas.ZIndex 设置为较大的数字。以下是 ZIndex 的更多解决方案:silverlight control: how to manage the ZIndex?

    The zindex is an attached property of the parent canvas.

    For example we created an "enhancedMapLayer" for the Bing Maps Silverlight control in http://deepearth.codeplex.com and added the zindex as a property like so:

    public int ZIndex
    {
    get { return zIndex; }
    set
    {
    zIndex = value;
    if (Parent != null)
    {
    SetValue(Canvas.ZIndexProperty, zIndex);
    }
    }
    }

    The in our infogeometry class (provides labels, balloons for all the OGC geometry type, point, linestring, polygon, multipolygon etc) when we launch the balloon we do this:

       var layer = (EnhancedMapLayer) Parent;
    if (layer != null)
    {
    //set to top z-order
    prevZIndex = layer.ZIndex;
    layer.ZIndex = 1000;
    SetValue(Canvas.ZIndexProperty, 1000);
    applyTranslations();
    balloonShowStoryboard.Begin();
    balloonContainer.Visibility = Visibility.Visible;
    OnBalloon(new BalloonEventArgs { LayerID = layer.ID, ItemID = ItemID });
    }

    By storing the layer's previous ZIndex we can restore it to the correct order on hiding the balloon.

    In order to communicate between layers we used the command pattern for Silverlight so we simply call:

    Commands.ClosePopupCommand.Execute();

    To close all other balloon then subscribe to that event: Commands.ClosePopupCommand.Executed += ClosePopupCommand_Executed;

  3. This stackoverflow answer提供了一个很好的方法,包括提到 Microsoft's Interactive Map SDK 。基本上,尝试分离各层。

        <m:Map CredentialsProvider="Your Key">
    <m:MapLayer>
    <m:MapItemsControl x:Name="ListOfItems"
    ItemTemplate="{StaticResource LogoTemplate}"
    ItemsSource="{Binding MyLocalizedEntities}">
    </m:MapItemsControl>
    </m:MapLayer>
    <m:MapLayer>
    <!-- You can have content in multiple layers: Latter layers are infront of former ones. -->
    </m:MapLayer>
    </m:Map>
  4. 其他可能有帮助的类似 stackoverflow 问题。

关于wpf - WPF 的 Bing map 、MapLayers/Pushpins 的 ZIndex?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14025054/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com