Exemple #1
0
        public List <Path> GetPaths(Transform toScreen, BoundingBox mapBoundingBox, Action mouseDownAction = null)
        {
            if (_symbol == null)
            {
                return(new List <Path>());
            }

            var pathGeometry = GetPathGeometry(toScreen);

            var firstScreen  = toScreen.Transform(mapBoundingBox.TopLeft.AsWpfPoint());
            var secondScreen = toScreen.Transform(mapBoundingBox.BottomRight.AsWpfPoint());
            var screenLimit  = new BoundingBox(firstScreen.X, firstScreen.Y, secondScreen.X, secondScreen.Y);

            var size = toScreen.TransformBounds(Extent.AsRect());

            var size2 = pathGeometry.Bounds;

            var distance = Math.Max(size2.Width, size2.Height);

            var unitSize = Math.Max(_symbol.Bounds.Height, _symbol.Bounds.Width);

            var tolerance = distance / unitSize;

            List <Path> result = new List <Path>();

            var bound = _symbol.Bounds;

            for (int i = 0; i <= tolerance; i++)
            {
                double fraction = (i) / tolerance;

                System.Windows.Point location, direction;

                pathGeometry.GetPointAtFractionLength(fraction, out location, out direction);

                if (!screenLimit.Intersects(new Point(location.X, location.Y)))
                {
                    continue;
                }

                Path tempPath = new Path()
                {
                    Fill = this.VisualParameters.Fill, Data = _symbol
                };

                if (CanEdit && mouseDownAction != null)
                {
                    tempPath.MouseLeftButtonDown += (sender, e) =>
                    {
                        if (e.ClickCount > 1)
                        {
                            mouseDownAction();
                        }
                    };
                }

                Matrix matrix = Matrix.Identity;

                var rotation = Math.Atan2(direction.Y, direction.X) * 180 / Math.PI;

                matrix.RotateAt(rotation, (bound.Width + bound.X) / 2.0, (bound.Height + bound.Y) / 2.0);

                matrix.Translate(location.X - bound.Width / 2.0 - bound.X / 2.0, location.Y - bound.Height / 2.0 - bound.Y / 2.0);

                TransformGroup group = new TransformGroup();

                group.Children.Add(new MatrixTransform(matrix));

                tempPath.RenderTransform = group;

                //tempPath.Tag = new LayerTag(-1) { IsTiled = false, LayerType = LayerType.AnimatingItem };

                result.Add(tempPath);
            }

            return(result);
        }