ArcGIS API for Silverlight Point flows along a line

Source: Internet
Author: User
Tags silverlight

Overview

Some time ago to do a project, the requirement is that there are some power transmission lines, power transmission lines or oil pipelines are flow direction, users want to do a dynamic effect to simulate the transmission of electricity. In fact, it is easy to do so as long as the online logo an arrow on it. But if it is made dynamic, at least arcengine is a bit cumbersome to implement. However, ArcGIS API for Silverlight can solve this problem.

Implementation ideas

The data on the map showing the lines of power transmission and simulating the direction of electrical transmission are the objects defined in the ArcGIS API, and no one will show up on the map. So how do you make the point move along the line? Do you want to use a timer? And then no interval of 0.1 seconds, even if the point should be in the position? This is the most primitive way, I believe in the earlier time, we use Arcengine to do the tracking will be played back in this way. But now we use the API is Silverlight-based, Silverlight itself is animated module, we can use Silverlight animation to achieve.

The objects that Silverlight animations Target are the points, lines, or other objects defined in Silverligt, which we also need to transform to convert the points we get to the points that the objects in the ArcGIS API will recognize when the animation is played.

To solve the above problems, the solution is almost.

Realize

First, we want to define animations, there are many types of animations defined in Silverlight, we use the Pointanimationusingpath class, and we can see the role of the class by its name. Line-based point animation.

By looking at the definition of the class, we know that we need to define a path when we use the class, set how long it takes to go through the road, and whether it will be looped back.

The following code we define the path, we are first known to the line object in ArcGIS, and then into the animation of the path object, the code is as follows:

Point Mystartpoint=new Point (THIS._ELINE.STARTPOINT.POINT.X,THIS._ELINE.STARTPOINT.POINT.Y); List<pathsegment> mypathsegmentlist=new list<pathsegment> (); foreach (ESRI. ArcGIS.Client.Geometry.PointCollection mypointcollection in this._eline.line.paths) {    list<point> Mypointlist=new list<point> ();    foreach (ESRI. ArcGIS.Client.Geometry.MapPoint mymappoint in mypointcollection)    {       Mypointlist.add (the new Point (Mymappoint.x, MYMAPPOINT.Y));     }     PolyLineSegment mypolylinesegment=new polylinesegment (mypointlist,false);     Mypathsegmentlist.add (mypolylinesegment); }
Definition is still very troublesome, but the code is understood at a glance, the following we are animated object

Pointanimationusingpath Mypointanimationusingpath = new Pointanimationusingpath (); List<pathfigure> mypathfigurelist=new list<pathfigure> (); Mypathfigurelist.add (New PathFigure ( Mystartpoint,mypathsegmentlist,false)); mypointanimationusingpath.pathgeometry = new PathGeometry (myPathFigureList );//set path mypointanimationusingpath.duration = new Duration (Timespan.fromseconds (5));// Set the time required to go through the path Mypointanimationusingpath.repeatbehavior = repeatbehavior.forever;//loop playback

Here we define the points and artboards to be moving:

This._arrowgraphic = new Arrowgraphic ();//Define the point object we want to move this._arrowgraphic.setzindex ((int) graphiczindex.elinearrow) ;//displayed on top this._arrowgraphic.geometry = new ESRI. ArcGIS.Client.Geometry.MapPoint (0, 0);//Set start position this._application. GRAPHICSLAYER.GRAPHICS.ADD (this._arrowgraphic);//Add to map This._storyboard = new Storyboard ();//define Artboard This._ STORYBOARD.CHILDREN.ADD (Mypointanimationusingpath);//Add animation to the artboard Storyboard.settarget (This._storyboard, This._ arrowgraphic);//The associated artboard and the object to be run Storyboard.settargetproperty (Mypointanimationusingpath, New PropertyPath ( Arrowgraphic.pointproperty));//an attribute This._storyboard.begin () that correlates animated objects and motion points;//Start animation
By looking at the API of the Pointanimationusingpath class, we can see that the output of the animation is an object of type System.Windows.Point, and we have to convert this object to the geometry that the object of the ArcGIS API can recognize, So we have customized the Arrowgraphic object instantiated above, and Arrowgraphic is an object inheriting the graphic class in the ArcGIS API. Defined as follows:

public class arrowgraphic:graphic{public point, {get {return (point) GetValue (Pointproperty);}    set {SetValue (Pointproperty, value);}  public static readonly DependencyProperty pointproperty = Dependencyproperty.register (' point ', typeof (Point),    typeof (Arrowgraphic), New Frameworkpropertymetadata (onpointchanged)); public static void Onpointchanged (DependencyObject D, DependencyPropertyChangedEventArgs e) {arrowgraphic Myarr        Owgraphic = d as arrowgraphic;        MapPoint mymappoint = new MapPoint (MYARROWGRAPHIC.POINT.X,MYARROWGRAPHIC.POINT.Y);    Myarrowgraphic.geometry = Mymappoint;        } public Arrowgraphic () {Simplemarkersymbol mymarkersymbol = new Simplemarkersymbol ();        Mymarkersymbol.size = 10;        Mymarkersymbol.style = SimpleMarkerSymbol.SimpleMarkerStyle.Circle;        Mymarkersymbol.color = System.Windows.Media.Brushes.Green; This.    Symbol = Mymarkersymbol; }}
The object is simply to convert the Silverlight point to MapPoint in the ArcGIS API by Pointproperty, then assign it to the graphic so that as the animation plays, The geometry of graphic is constantly changing so that graphic can move along the line.

As for how our custom graphic is displayed, it is necessary to define the point, picture or other.

For example, we want to show arrows, arrows have direction, how to control the direction of the arrow? Then when you get to a point, when Pointproperty gets a new value, it can be calculated from the previous value and then assigned to geometry.

Here's how it works:

A few green dots on the line in the picture are always moving along the line, and will not do jpg animations, only a static picture.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.