SuperMap.WindowsPhone.Mapping.LayerContainer.ArrangeOverride C# (CSharp) Method

ArrangeOverride() protected method

protected ArrangeOverride ( Size finalSize ) : Size
finalSize System.Windows.Size
return System.Windows.Size
        protected override Size ArrangeOverride(Size finalSize)
        {
            double resolution = this.Resolution;
            Point2D origin = new Point2D(this.OriginX, this.OriginY);
            Rectangle2D clipBox = new Rectangle2D(
                origin.X - (resolution * 4191.0),
                origin.Y - (resolution * 4191.0),
                origin.X + (resolution * 4191.0),
                origin.Y + (resolution * 4191.0));
            if (this.Layer is ElementsLayer) (Layer as ElementsLayer).BoundsCollection.Clear();
            if (this.Layer is ElementsLayer) orignalBounds.Clear();
            bool istrue = this.Layer is ElementsLayer ? (this.Layer as ElementsLayer).IsAutoAvoidance : false;
            if (istrue)
            {
                foreach (UIElement element in base.Children)
                {
                    Rectangle2D b = GetBounds(element);
                    double referenceLength = (Layer as ElementsLayer).GetReferenceLength(element) * resolution;
                    if (b.BottomLeft == b.TopRight)
                    {
                        b = new Rectangle2D(b.Left - (referenceLength) / 2, b.Bottom - (element.DesiredSize.Height * resolution) / 2,
                                            b.Left + (referenceLength) / 2, b.Bottom + (element.DesiredSize.Height * resolution) / 2);
                    }
                    orignalBounds.Add(b);
                }
            }

            foreach (UIElement element in base.Children)
            {
                if (element.Visibility != Visibility.Visible)
                {
                    continue;
                }
                if (element is FeatureElement)
                {
                    this.ArrangeFeature(element as FeatureElement, clipBox);
                    continue;
                }
                if (element is ShapeElement)
                {
                    this.ArrangeShapeBase(element as ShapeElement, clipBox);
                    continue;
                }
                Rectangle2D b = GetBounds(element);

                if (istrue)
                {
                    if (b.BottomLeft == b.TopRight)
                    {
                        b = new Rectangle2D(b.Left - (element.DesiredSize.Width * resolution) / 2, b.Bottom - (element.DesiredSize.Height * resolution) / 2,
                                            b.Left + (element.DesiredSize.Width * resolution) / 2, b.Bottom + (element.DesiredSize.Height * resolution) / 2);
                    }
                    bool isIntersect;
                    bool isGetNewBounds;
                    double referenceLength = (Layer as ElementsLayer).GetReferenceLength(element) * resolution;
                    Size referenceSize = (Layer as ElementsLayer).GetReferenceSize(element);

                    b = isBoundsChange(b, referenceLength, referenceSize, out isIntersect, out isGetNewBounds);

                    if (isIntersect)
                    {
                        if (isGetNewBounds)
                        {
                            (element as UIElement).Opacity = 1;
                        }
                        else
                        {
                            (element as UIElement).Opacity = 0;
                        }
                    }
                    else
                    {
                        (element as UIElement).Opacity = 1;
                    }

                    (Layer as ElementsLayer).BoundsCollection.Add(element, b);
                }

                if (!Rectangle2D.IsNullOrEmpty(b))
                {
                    double pixelX = (b.Left - origin.X) / resolution;
                    double pixelY = (origin.Y - b.Top) / resolution;
                    double pixelWidth = b.Width / resolution;
                    double pixelHeight = b.Height / resolution;
                    //&& 
                    if (this.Layer is TiledLayer)
                    {
                        pixelWidth++;
                        pixelHeight++;
                        element.UseLayoutRounding = false;
                    }

                    if (((!double.IsInfinity(pixelWidth) && !double.IsInfinity(pixelHeight)) && (!double.IsInfinity(pixelX) && !double.IsInfinity(pixelY))) && ((!double.IsNaN(pixelWidth) && !double.IsNaN(pixelHeight)) && (!double.IsNaN(pixelX) && !double.IsNaN(pixelY))))
                    {
                        double width;
                        double height;
                        if (((element is FrameworkElement) && (pixelWidth != 0.0)) && (pixelHeight != 0.0))
                        {
                            (element as FrameworkElement).Width = pixelWidth;
                            (element as FrameworkElement).Height = pixelHeight;
                        }
                        if ((pixelWidth != 0.0) || (pixelHeight != 0.0))
                        {
                            element.Arrange(new Rect(pixelX, pixelY, pixelWidth, pixelHeight));
                            continue;
                        }
                        //相当于左上,右下,中心等位置的设定。
                        //设在某个点,bbox的宽和高都是0,比如pushpin\textbox等
                        switch (((HorizontalAlignment)element.GetValue(FrameworkElement.HorizontalAlignmentProperty)))
                        {
                            case HorizontalAlignment.Left:
                                width = element.DesiredSize.Width;
                                break;

                            case HorizontalAlignment.Right:
                                width = 0.0;
                                break;

                            default:
                                width = element.DesiredSize.Width * 0.5;
                                break;
                        }
                        switch (((VerticalAlignment)element.GetValue(FrameworkElement.VerticalAlignmentProperty)))
                        {
                            case VerticalAlignment.Top:
                                height = element.DesiredSize.Height;
                                break;

                            case VerticalAlignment.Bottom:
                                height = 0.0;
                                break;

                            default:
                                height = element.DesiredSize.Height * 0.5;
                                break;
                        }
                        element.Arrange(new Rect(new Point(pixelX - width, pixelY - height), element.DesiredSize));
                    }
                }
            }
            return base.ArrangeOverride(finalSize);
        }