简体   繁体   English

如何在 MapControl 中动态使用具有多个引脚的多个自定义弹出窗口

[英]How to use multiple custom popup with multiple pins dynamically in MapControl

I'm trying to add custom text to the title of my custom Popup but can't seem to find the correct way to find the control itself dynamically from the main page of my project.我正在尝试将自定义文本添加到我的自定义弹出窗口的标题中,但似乎无法找到正确的方法来从我的项目的主页动态地找到控件本身。 How can this be achieved?如何做到这一点?

Expected result预期结果

在此处输入图像描述

在此处输入图像描述

Current result当前结果

在此处输入图像描述

在此处输入图像描述

MainPage.cs主页.cs

public sealed partial class MainPage: Page
 {
     public MainPage()
     {
         this.InitializeComponent();


         TabView tabView = mainPage.MyTabs;

         var tab1 = new TabViewItem { Header = "Tab 1"

         tabView.SelectedItem = tab1;


         var mapPage= new MapPage();

         tab1.Content = mapPage;


         var MyLandmarks = new List<MapElement>();

         BasicGeoposition snPosition = new BasicGeoposition { Latitude = 51.120005, Longitude = -0.1000001 };
         Geopoint snPoint = new Geopoint(snPosition);

         var spaceNeedleIcon = new MapIcon
         {
             Location = snPoint,
             NormalizedAnchorPoint = new Point(0.5, 1.0),
             ZIndex = 0,
             Title = "Space Needle",
             Image = mapPushpinStreamReference
         };

         BasicGeoposition snPosition2 = new BasicGeoposition { Latitude = 51.000000, Longitude = -0.100000 };
         Geopoint snPoint2 = new Geopoint(snPosition2);


         var spaceNeedleIcon2 = new MapIcon
         {
             Location = snPoint2,
             NormalizedAnchorPoint = new Point(0.5, 1.0),
             ZIndex = 0,
             Title = "Space N",
             Image = mapPushpinStreamReference
         };

         MyLandmarks.Add(spaceNeedleIcon);
         MyLandmarks.Add(spaceNeedleIcon2);

         var LandmarksLayer = new MapElementsLayer
         {
             ZIndex = 1,
             MapElements = MyLandmarks
         };

         pageMap.theMapControl.Layers.Add(LandmarksLayer);


         // Specify location of MapView centre.
         BasicGeoposition cityPosition = new BasicGeoposition() { Latitude 25.0, Longitude = -0.1 };
         var cityCenter = new Geopoint(cityPosition);

         // Set MapView centre
         pageMap.theMapControl.Center = cityCenter;
     }
 }

MapPage.xaml MapPage.xaml

     <Page
     x:Class="MyApp.MapPage"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     xmlns:local="using:MyApp"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:Maps="using:Windows.UI.Xaml.Controls.Maps"
     mc:Ignorable="d">
    
     <Grid x:Name="MyGrid">
         <Grid.RowDefinitions>
             <RowDefinition Height="*"/>
             <RowDefinition Height="Auto"/>
         </Grid.RowDefinitions>
    
         <Maps:MapControl
             Grid.Row="0"
             x:Name="MyMapControl"  
             MapServiceToken="[token]"
             ZoomLevel="8"
             MapElementClick="MyMapControl_MapElementClick">
    
             <Popup x:Name="PushpinPopup" IsLightDismissEnabled="True">
                 <Grid Background="Black">
                     <ScrollViewer>
                         <StackPanel Orientation="Vertical">
                             <TextBlock Text="{x:Bind PopupTitle, Mode=OneWay}" />
                             <Button x:Name="DescriptionButton" Content="Description"/>
                         </StackPanel>
                     </ScrollViewer>
                 </Grid>
             </Popup>
         </Maps:MapControl>
     </Grid>
 </Page>

MapPage.cs地图页面.cs

 public sealed partial class MapPage: Page
 {
     public MapControl theMapControl { get; set; }

     public PageMap()
     {
         this.InitializeComponent();

         theMapControl = MyMapControl;
     }

     public static readonly DependencyProperty PopupTitleProperty =
         DependencyProperty.Register("PopupTitle", typeof(string),
             typeof(Popup),
             new PropertyMetadata(""));

     public static readonly DependencyProperty PushpinPopupSubtitleProperty =
         DependencyProperty.Register("PushpinPopupSubtitle", typeof(string),
             typeof(Popup),
             new PropertyMetadata(""));

     public string PopupTitle
     {
         get => GetValue(PopupTitleProperty).ToString();
         set { SetValue(PopupTitleProperty, value); }
     }

     private void MyMapControl_MapElementClick(MapControl sender, MapElementClickEventArgs args)
     {
         Point point = args.Position;
         PushpinPopup.IsOpen = true;
     }
 }

MainPage.xaml主页.xaml

<Page
    x:Class="MyApp.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <CommandBar Grid.Row="0">
            ...
        </CommandBar>

        <Frame Name="MainFrame" Grid.Row="1"/>
    </Grid>
</Page>

How to use multiple custom popup with multiple pins dynamically in MapControl如何在 MapControl 中动态使用具有多个引脚的多个自定义弹出窗口

For the requirement, you could move the popup into usercontrol and make tile and subtitle property.对于要求,您可以将弹出窗口移动到用户控件中并制作 tile 和 subtitle 属性。

Getting which MapIcon with MapIcon's tag where in the MapElementClick event.MapElementClick事件中使用 MapIcon 的标记获取哪个MapIcon Then pass the title and subtitle value to UserControl 's title and subtitle property then show the popup.然后将标题和副标题值传递给UserControl的标题和副标题属性,然后显示弹出窗口。

MapIcon myClickedIcon = args.MapElements.FirstOrDefault(x => x.Tag.ToString() == "tag") as MapIcon;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 LINQ如何动态使用多个ThenBy? - LINQ How to use multiple ThenBy dynamically? Windows Phone 8.1 Runtime中具有多个子节点的MapControl性能很差 - Terrible performance of MapControl with multiple children in Windows Phone 8.1 Runtime WP 8.1 MapControl如何添加自定义图钉并以编程方式添加ItemSource? - WP 8.1 MapControl How add custom pushpin and programmatically add ItemSource? Azure 映射 - 渲染 - 获取 Map 图像 - 如何将多个 colors 应用到不同的引脚 - Azure Maps - Render - Get Map Image - How to apply multiple colors to different pins 如何动态创建多个GridView? - How to create multiple gridviews dynamically? 带iframe的弹出窗口:一次使用多个@ Html.AntiForgeryToken() - Popup with iframe: Use of multiple @Html.AntiForgeryToken() at once 如何使用 U-SQL 自定义提取器动态输出多个文件? - How to output multiple files dynamically using U-SQL custom Extractors? 如何旋转放置在Mapcontrol上的图像 - How to rotate image placed on a Mapcontrol 如何在MapControl上获取图像的坐标 - how to get the coordinates of an image on MapControl 如何使用多个 AND 运算符? - How to use multiple AND operators?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM