繁体   English   中英

C#WP8.1 - 使用Bing地图时在路径顶部显示MapIcon

[英]C# WP8.1 - Displaying a MapIcon on top of a Route when using Bing Maps

我现在正在玩bing地图。 我已经按照教程创建路线并添加了地图等,但我发现mapIcon不会显示它是否在路线上。 我尝试过使用mapIcon的Z-Index属性,但这看起来效果不大,因为我认为它只对其他MapElements产生影响。

有没有其他人知道如何实现这一目标?

我目前用于创建路径并尝试在目标上设置MapIcon的代码是(对于内容MapFunctions的abit只是我为功能所做的静态类,例如查找路径,获取当前位置等):

    private async void DrawRoute()
    {
        // Check if a destination has been set
        if(MapFunctions.destination != null)
        {
            route = await MapFunctions.GetRouteAsync(MapFunctions.destination.Point);

            if (route != null)
            {
                // Use the route to initialize a MapRouteView.
                MapRouteView viewOfRoute = new MapRouteView(route.Route);
                viewOfRoute.RouteColor = Colors.Yellow;
                viewOfRoute.OutlineColor = Colors.Black;


                // Add the new MapRouteView to the Routes collection
                // of the MapControl.
                MyMap.Routes.Add(viewOfRoute);

                // Fit the MapControl to the route.
                await MyMap.TrySetViewBoundsAsync(
                    route.Route.BoundingBox,
                    null,
                    Windows.UI.Xaml.Controls.Maps.MapAnimationKind.None);

                AddDestinationMapElement(MapFunctions.destination.Point);

                // Start timer to update the remaining time of the journey
                UpdateRemainingTime_Tick(this, new Object());
                dispatcherTimer.Start();
            }
            else
            {
                MessageDialog message = new MessageDialog("An error occured while trying to calculate your route. Please try again later.", "Error");
                await message.ShowAsync();
            }
        }
    }

    private void AddDestinationMapElement(Geopoint dest)
    {
        MapIcon MapIcon1 = new MapIcon();
        MapIcon1.Location = new Geopoint(new BasicGeoposition()
        {
            Latitude = dest.Position.Latitude,
            Longitude = dest.Position.Longitude
        });

        MapIcon1.Visible = true;
        MapIcon1.ZIndex = int.MaxValue;
        MapIcon1.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Images/mapIcon.png"));
        MapIcon1.NormalizedAnchorPoint = new Point(0.5, 1.0);
        MapIcon1.Title = "Destination";
        MyMap.MapElements.Add(MapIcon1);
    }

如果要在元素顶部添加图钉,可以使用MapOverlay,它允许您将图钉(带图像或任何XAML元素)添加到地图控件中:

MapOverlay pushpinStart = new MapOverlay();
pushpinStart.PositionOrigin = new Point(0.5, 0.5);
pushpinStart.Content = new Image()
                           {
                               Source =
                                   new BitmapImage(
                                   new Uri("../Assets/Ui/ui-pin-start.png", UriKind.Relative))
                           };
pushpinStart.GeoCoordinate = posCollection[0];

如果你想继续使用MapIcon,那么渲染引擎将根据缩放级别和当前位置以及其他元素碰撞算法的结果来计算最佳显示内容。 所以我不确定你在寻找什么。

对于WP8.1,这是等效的代码:

Image iconStart = new Image();
iconStart.Source = new BitmapImage(new Uri("ms-appx:///Assets/Ui/ui-pin-start.png"));
this.Map.Children.Add(iconStart);
MapControl.SetLocation(iconStart, new Geopoint(pos[0]));
MapControl.SetNormalizedAnchorPoint(iconStart, new Point(0.5, 0.5));

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM