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();
//通过PointProperty把Silverlight的Point转换成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(现在好像要翻墙才能下载)
- silverlight路径的动态展示
- Silverlight工作室的案例展示和联系方式
- highchart 动态图的展示
- winform展示Unity3D文件(支持动态改变文件路径)
- 如何用silverlight 做用于图片展示的画廊
- DeskViewer基于Silverlight 2.0开发的个性相册展示系统
- 给大家展示一个简单的silverlight个人网站模版
- Silverlight - 资源文件的路径 - ResourceHelper
- Silverlight图片相对路径的设置
- SilverLight 获得项目文件夹路径的问题。
- Silverlight图片相对路径的设置
- 利用Path路径设计的按钮图标(Silverlight)
- SilverLight动态指定Image的Source
- SilverLight动态指定Image的Source
- Silverlight/WPF中 动态Style 的问题
- SilverLight动态指定Image的Source
- Silverlight中WCF的动态部署
- silverlight动态加载模板的例子
- LeetCode_10---Regular Expression Matching
- Java基本数据类型
- Linux FTP安装与简单配置
- map和set异同
- 简明python教程:第2章 安装Python
- silverlight路径的动态展示
- CentOS搭建shadowsocks-libev服务端
- SSI2整合,spring和xfire 整合之后,加入Struts2 上传下载功能
- 一致性hash算法释义
- How are REST APIs versioned?
- Android 集成支付宝SDK实现快捷支付--详解
- VC 从服务器下载文件
- Mysql Event Scheduler
- tomcat如何禁止显示目录和文件列表