private static void AddFluid(DrawingMapLayer animationLayer, TongJi.Gis.Display.IDataFluidTheme theme, TongJi.Gis.IFeature f) { var poly = new TongJi.Geometry.Polyline(f.GeoData); double length = poly.Length; if (length < 10) { return; } // 生成PathGeometry var points = poly.Points.Select(p => new Point(p.x, p.y)).ToList(); PathGeometry geometry = new PathGeometry(); PathFigure figure = new PathFigure { StartPoint = points.First() }; PolyLineSegment segment = new PolyLineSegment(points, true); figure.Segments.Add(segment); geometry.Figures.Add(figure); // 读取参数 double velocity = theme.GetVelocity(f); double time = length / velocity; double space = 1 / theme.GetDensity(f); int spotCount = (int)(length / space) + 1; var color = theme.GetColor(f); // 应用动画 for (int i = 0; i < spotCount; i++) { PointAnimationUsingPath paup = new PointAnimationUsingPath(); paup.PathGeometry = geometry; paup.Duration = new Duration(new TimeSpan(0, 0, 0, 0, (int)(time * 1000))); paup.RepeatBehavior = RepeatBehavior.Forever; paup.BeginTime = new TimeSpan(0, 0, 0, 0, (int)(time / spotCount * i * 1000)); ColorAnimation ca = new ColorAnimation(color.Item1, color.Item2, new Duration(new TimeSpan(0, 0, 0, 0, (int)(time * 1000)))); ca.RepeatBehavior = RepeatBehavior.Forever; ca.BeginTime = new TimeSpan(0, 0, 0, 0, (int)(time / spotCount * i * 1000)); double radius = theme.GetDiameter(f) / 2; var fill = new SolidColorBrush(color.Item1); EllipseGeometry spot = new EllipseGeometry(new Point(), radius, radius); GeometryDrawing spotDrawing = new GeometryDrawing(fill, null, spot); animationLayer.AddOverlayChildren(spotDrawing); spot.BeginAnimation(EllipseGeometry.CenterProperty, paup); fill.BeginAnimation(SolidColorBrush.ColorProperty, ca); } }
private static void AddPump(DrawingMapLayer animationLayer, Point pos, Brush stroke, Brush fill, double size, double strokeWidth, double pumpSize, double periord) { EllipseGeometry geometry = new EllipseGeometry(pos, size, size); GeometryDrawing drawing = new GeometryDrawing(fill, new Pen(stroke, strokeWidth), geometry); //var mLayer = MapControl.Current.Layers.First(x => x.LayerData.Name == "城镇") as DrawingMapLayer; animationLayer.AddOverlayChildren(drawing); DoubleAnimationUsingKeyFrames animation = new DoubleAnimationUsingKeyFrames(); animation.Duration = new Duration(TimeSpan.FromMilliseconds(periord)); animation.RepeatBehavior = RepeatBehavior.Forever; animation.KeyFrames.Add(new LinearDoubleKeyFrame(size, KeyTime.FromPercent(0))); animation.KeyFrames.Add(new LinearDoubleKeyFrame(pumpSize, KeyTime.FromPercent(0.1))); animation.KeyFrames.Add(new LinearDoubleKeyFrame(size, KeyTime.FromPercent(1))); geometry.BeginAnimation(EllipseGeometry.RadiusXProperty, animation); geometry.BeginAnimation(EllipseGeometry.RadiusYProperty, animation); }