using System.Windows; using ESRI.ArcGIS.Client; using ESRI.ArcGIS.Client.Symbols; using System.Windows.Media; using ESRI.ArcGIS.Client.Geometry; using System; using System.Windows.Threading; namespace SmoothAnimation { public partial class MainWindow : Window { GraphicsLayer _gl; private DateTime animateStartTime; private DispatcherTimer animationTimer; private int animationDuration = 5000; SimpleMarkerSymbol defaultSymbol; SimpleMarkerSymbol animatingSymbol; public MainWindow() { InitializeComponent(); _gl = new GraphicsLayer(); MyMap.Layers.Add(_gl); } private void MyMap_MouseClick(object sender, Map.MouseEventArgs e) { if (defaultSymbol == null) { defaultSymbol = new SimpleMarkerSymbol() { Color = Brushes.Red, Size = 12, Style = SimpleMarkerSymbol.SimpleMarkerStyle.Circle }; } if (animatingSymbol == null) { animatingSymbol = new SimpleMarkerSymbol() { Color = Brushes.Blue, Size = 12, Style = SimpleMarkerSymbol.SimpleMarkerStyle.Circle }; } if (_gl.Graphics.Count == 3) _gl.Graphics.Clear(); if (_gl.Graphics.Count == 2) _gl.Graphics.Remove(_gl.Graphics[0]); _gl.Graphics.Add(new Graphic() { Symbol = defaultSymbol, Geometry = e.MapPoint }); } private void AnimateButton_Click(object sender, RoutedEventArgs e) { MapPoint startPoint = _gl.Graphics[0].Geometry as MapPoint; MapPoint finishPoint = _gl.Graphics[1].Geometry as MapPoint; MapPoint animatingPoint = startPoint; _gl.Graphics.Add(new Graphic() { Geometry = animatingPoint,Symbol = animatingSymbol }); animationTimer= new DispatcherTimer(); animationTimer.Interval = TimeSpan.FromMilliseconds(33); animateStartTime = DateTime.Now; animationTimer.Tick += (s, ex) => { double fraction = (DateTime.Now - animateStartTime).TotalMilliseconds / animationDuration; fraction = QuinticEasingInOut(fraction, 0, 1, 1); var x = (finishPoint.X - startPoint.X) * fraction + startPoint.X; var y = (finishPoint.Y - startPoint.Y) * fraction + startPoint.Y; animatingPoint.MoveTo(x, y); }; animationTimer.Start(); } public double QuinticEasingInOut(double t, double b, double c, double d) { t /= d / 2; if (t < 1) return c / 2 * t * t * t * t * t + b; t -= 2; return c / 2 * (t * t * t * t * t + 2) + b; } } }
<Window x:Class="SmoothAnimation.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:esri="http://schemas.esri.com/arcgis/client/2009" Title="MainWindow" Height="350" Width="525"> <Grid> <esri:Map x:Name="MyMap" UseAcceleratedDisplay="True" MouseClick="MyMap_MouseClick"> <esri:ArcGISTiledMapServiceLayer ID="World Topo Map" Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/> </esri:Map> <Button Content="Animate" x:Name="AnimateButton" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="10" Click="AnimateButton_Click"> </Button> </Grid> </Window>
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.