根据路径旋转MapControl上的车辆销-Uwp C# [英] Rotate vehicle pin on MapControl according to the path - Uwp C#

查看:28
本文介绍了根据路径旋转MapControl上的车辆销-Uwp C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用使用以下代码在指定路线上行驶车辆.但是所用车辆的图像就像它的正面朝左.如何在行驶过程中旋转汽车的表面?我指的是链接来移动汽车

My app is moving a vehicle on specified route using below code. But the image of vehicle used is like it's front side is facing to left. How can I rotate the face of car on the way it goes? I'm referring this link to move the car.

我的代码:

  private void MovePinOnPath(bool isGeodesic)
    {      
    Image forImage = new Image
    {
        Width = 40,
        Source = CarIconSource,
    };
            BasicGeoposition geoposition = new BasicGeoposition();
            geoposition.Latitude = CarDetailsList.CodeArray[Startpt_index].CarLat;
            geoposition.Longitude = CarDetailsList.CodeArray[Startpt_index].CarLng;
            Geopoint mypoint2 = new Geopoint(geoposition);
            List<BasicGeoposition> GeoList = new List<BasicGeoposition>();
            for (int i = Startpt_index + 1; i <= Endpt_index; i++)
            {
                GeoList.Add(new BasicGeoposition()
                {
                    Latitude =  CarDetailsList.CodeArray[i].CarLat;
                    Longitude = CarDetailsList.CodeArray[i].CarLng;
                });
            }
            Geopath path3 = new Geopath(GeoList);
            MapControl.SetLocation(forImage, mypoint2);
            MapControl.SetNormalizedAnchorPoint(forImage, new Point(0.5, 1.0));
            currentAnimation = new PathAnimation(path3, (coord, pathIdx, frameIdx) =>
            {
                MapControl.SetLocation(forImage, new Geopoint(coord));
            }, isGeodesic, 10000);

            currentAnimation.Play();
     }

推荐答案

如果仅将常规Image控件放在MapControl上,则旋转变换将无法工作.贾斯汀XL对此线程进行了解释:如何旋转放置在Mapcontrol上的图像.

If you just put a general Image control on the MapControl, the rotation transform will not work. Justin XL has explained on this thread: How to rotate image placed on a Mapcontrol.

解决方案就像贾斯汀XL所说的:

The solution is like the Justin XL said:

创建一个名为ImageControl的UserControl,该UserControl封装此Image及其转换,并具有UriPath和Angle等依赖项属性,这些依赖项属性负责将信息向下传递到内部Image及其CompositeTransform属性.

create a UserControl called ImageControl which encapsulates this Image and its transform, with dependency properties like UriPath and Angle that are responsible for passing the information down to the inner Image and its CompositeTransform property.

这篇关于根据路径旋转MapControl上的车辆销-Uwp C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆