Rotate vehicle pin on MapControl according to the path - Uwp C#

不想你离开。 提交于 2019-12-24 11:16:01

问题


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.

My Code :

  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();
     }

回答1:


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.

The solution is like the Justin XL said:

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.



来源:https://stackoverflow.com/questions/51518355/rotate-vehicle-pin-on-mapcontrol-according-to-the-path-uwp-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!