silverlight路径的动态展示

来源:互联网 发布:100m网络迅雷下载速度 编辑:程序博客网 时间:2024/06/05 20:37

之前看了几篇点沿着线流动的博客,照着去实现,发现在silverlight中不行,原因是好几个类引用的.net框架的,而在silverlight中不能使用这些类。

首先是最短路径的生成:这里注意网络数据集制作时需要有HierarchyMultiNet等级限制才能正常运行。

生成路径后,下面就是动态展示了:

            将查询出的路线转换成arcGIS的Polyline对象

            ESRI.ArcGIS.Client.Geometry.Polyline _ELine =newESRI.ArcGIS.Client.Geometry.Polyline ();

            _ELine =(ESRI.ArcGIS.Client.Geometry.Polyline)routeResult.Route.Geometry;           

           

            ////

            ////

            //定义路径,将线对象转换成动画中的路径对象        

            //设置路线的起点

            PointmyStartPoint =new Point(_ELine.Paths[0][0].X,_ELine.Paths[0][0].Y);

        接下来,arcgis的Polyline转换成silverlight的Geometry对象

            PathSegmentCollectionmyPathSegmentList =new PathSegmentCollection();

            foreach(ESRI.ArcGIS.Client.Geometry.PointCollectionmyPointCollectionin _ELine.Paths)

            {

                List<Point> myPointList =newList<Point>();

                System.Windows.Media.PointCollection pointCollection =new System.Windows.Media.PointCollection();

                foreach(ESRI.ArcGIS.Client.Geometry.MapPointmyMapPointin myPointCollection)

                {

                    myPointList.Add(newPoint(myMapPoint.X,myMapPoint.Y));

                    pointCollection.Add(newPoint(myMapPoint.X,myMapPoint.Y));

                  

                }               

                PolyLineSegmentmyPolyLineSegment =new PolyLineSegment();

                myPolyLineSegment.Points =pointCollection;                

               myPathSegmentList.Add(myPolyLineSegment);

            }

            这里的PointAnimationUsingPath类是用的老外写的类,可以下载到:http://www.codeproject.com/KB/silverlight/PathAnimation.aspx

            //定义动画

            PointAnimationUsingPathmyPointAnimationUsingPath =new PointAnimationUsingPath();

            List<PathFigure> myPathFigureList =new List<PathFigure>();

 

            PathFigurepathFigure =new PathFigure();

            pathFigure.StartPoint =myStartPoint;

            pathFigure.Segments =myPathSegmentList;

            pathFigure.IsClosed = false;

 

           myPathFigureList.Add(pathFigure);          

 

            PathGeometry_pathGeometry =new PathGeometry();

            _pathGeometry.Figures.Add(pathFigure);          

 

          然后设置myPointAnimationUsingPath的属性

           myPointAnimationUsingPath.PathGeometry = _pathGeometry;//设置路径          

           

            myPointAnimationUsingPath.Duration= TimeSpan.FromSeconds(5);//设置走完路径需要的时间 

           myPointAnimationUsingPath.RepeatBehavior = RepeatBehavior.Forever;//循环播放         

           自己改写的Graphic运动点对象

            ArrowGraphic_ArrowGraphic =new ArrowGraphic();//定义我们要运动的点对象           

 

            //_ArrowGraphic.SetZIndex((int)GraphicZIndex.ELineArrow);//显示在最上面 

            _ArrowGraphic.Geometry = new ESRI.ArcGIS.Client.Geometry.MapPoint(myStartPoint.X,myStartPoint.Y);//设置起始位置 

           RoutegraphicsLayer.Graphics.Add(_ArrowGraphic);//添加到地图上 

            将动画路径与运动点关联,设置关联属性 (_ArrowGraphic的point属性)

            myPointAnimationUsingPath.Target =_ArrowGraphic;

           myPointAnimationUsingPath.TargetProperty = newPropertyPath(ArrowGraphic.PointProperty);          

              

           myPointAnimationUsingPath.Begin();     

            

 

 

//通过PointPropertySilverlightPoint转换成ArcGIS API中的Mappoint

    //然后赋值给该Graphic

   

    public class ArrowGraphic: Graphic

    {

        public Point Point

        {         

            get{

                return(Point)GetValue(PointProperty);

            }

            set{               

                    SetValue(PointProperty, value);           

            }      

          

        }

 这里之前我看到的PropertyMetadata用的就是.net的类,现在我参考改成了silverlight的类了

        public static readonly DependencyProperty PointProperty = DependencyProperty.Register

            ("Point",typeof(Point),typeof(ArrowGraphic),newPropertyMetadata((Point)newPoint(),

               newPropertyChangedCallback(OnPointChanged)));

 

        public static voidOnPointChanged(DependencyObject d,DependencyPropertyChangedEventArgs e)

        {

            ArrowGraphicmyArrowGraphic = das ArrowGraphic;

            MapPointmyMapPoint =new MapPoint(myArrowGraphic.Point.X,myArrowGraphic.Point.Y);

            myArrowGraphic.Geometry =myMapPoint;

        }

 

        publicArrowGraphic()

        {

 

            SimpleMarkerSymbolmyMarkerSymbol =new SimpleMarkerSymbol();

            myMarkerSymbol.Size = 20;

            myMarkerSymbol.Style = SimpleMarkerSymbol.SimpleMarkerStyle.Circle;

            //myMarkerSymbol.Color= System.Windows.Media.Brushes.Green;

            myMarkerSymbol.Color = newSolidColorBrush(Color.FromArgb(255, 255, 0, 0));

 

            this.Symbol= myMarkerSymbol;

           

        }

    } 

下面是我参考的文章:http://blog.csdn.net/beniao277/article/details/5664691

                                http://blog.csdn.net/mytudousi/article/details/34107199

虽然照着都没有实现,还是感谢文章作者!

还有老外的文章和类下载:http://www.codeproject.com/KB/silverlight/PathAnimation.aspx(现在好像要翻墙才能下载)

 

0 0
原创粉丝点击