Completed
Last Updated: 25 Aug 2017 11:20 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 23 Aug 2017 05:54
Category: Map
Type: Bug Report
2
FIX. RadMap - OverflowException when pan / zoom operation is performed with the mouse
You can find attached a sample project, video, demonstrating the steps and a screenshot of the error.

Workaround:

public class MyMapVisualElementFactory : MapVisualElementFactory
{
    public override MapVisualElement CreatePolyline(Collection<PointG> points)
    {
        return new MyMapPolyline(points);
    }
}

public class MyMapPolyline : MapPolyline
{
    private FieldInfo pathsField;
    private FieldInfo boundingRectsField;
    private FieldInfo isInViewportField;

    public MyMapPolyline(Collection<PointG> points) : base(points)
    {
        this.pathsField = typeof(MapPolyline).GetField("paths", BindingFlags.Instance | BindingFlags.NonPublic);
        this.boundingRectsField = typeof(MapPolyline).GetField("boundingRects", BindingFlags.Instance | BindingFlags.NonPublic);
        this.isInViewportField = typeof(MapPolyline).GetField("isInViewport", BindingFlags.Instance | BindingFlags.NonPublic);
    }

    public override void ViewportChanged(IMapViewport viewport, ViewportChangeAction action)
    {
        if ((action & ViewportChangeAction.All) == action) 
        {
            long mapSize = MapTileSystemHelper.MapSize(viewport.ZoomLevel);
            List<GraphicsPath> paths = new List<GraphicsPath>();
            List<RectangleL> boundingRects = new List<RectangleL>();

            long start = viewport.PanOffset.Width;
            int maxWraparounds = 1;

            while (start + mapSize < viewport.ViewportInPixels.Width)
            {
                maxWraparounds++;
                start += mapSize;
            }

            for (int i = -1; i <= maxWraparounds; i++)
            {
                GraphicsPath path = new GraphicsPath();

                List<PointF> drawPoints = new List<PointF>();

                foreach (PointG p in this.Points)
                {
                    PointL pixel = MapTileSystemHelper.LatLongToPixelXY(p.Latitude, p.Longitude, viewport.ZoomLevel);
                    drawPoints.Add(new PointF(pixel.X + i * mapSize, pixel.Y));
                }

                path.AddLines(drawPoints.ToArray());

                RectangleF rect = path.GetBounds();
                RectangleF view = new RectangleF(viewport.ViewportInPixels.X, viewport.ViewportInPixels.Y, 
                    viewport.ViewportInPixels.Width, viewport.ViewportInPixels.Height);

                if (rect.IntersectsWith(view))
                {
                    paths.Add(path);
                }

                boundingRects.Add(new RectangleL((long)rect.X, (long)rect.Y, (long)rect.Width, (long)rect.Height)); 
            }

            this.pathsField.SetValue(this, paths);
            this.boundingRectsField.SetValue(this, boundingRects);
        }

        if (action != ViewportChangeAction.None)
        {
            this.isInViewportField.SetValue(this, false);
            List<RectangleL> boundingRects = this.boundingRectsField.GetValue(this) as List<RectangleL>;

            foreach (RectangleL rect in boundingRects)
            {
                if (viewport.ViewportInPixels.IntersectsWith(rect))
                {
                    this.isInViewportField.SetValue(this, true);
                }
            }
        }
    }
}

public class MyMapVisualElementFactory : MapVisualElementFactory
{
    public override MapVisualElement CreatePolyline(Collection<PointG> points)
    {
        return new MyMapPolyline(points);
    }
}

public class MyMapPolyline : MapPolyline
{
    private FieldInfo pathsField;
    private FieldInfo boundingRectsField;
    private FieldInfo isInViewportField;

    public MyMapPolyline(Collection<PointG> points) : base(points)
    {
        this.pathsField = typeof(MapPolyline).GetField("paths", BindingFlags.Instance | BindingFlags.NonPublic);
        this.boundingRectsField = typeof(MapPolyline).GetField("boundingRects", BindingFlags.Instance | BindingFlags.NonPublic);
        this.isInViewportField = typeof(MapPolyline).GetField("isInViewport", BindingFlags.Instance | BindingFlags.NonPublic);
    }

    public override void ViewportChanged(IMapViewport viewport, ViewportChangeAction action)
    {
        if ((action & ViewportChangeAction.All) == action) 
        {
            long mapSize = MapTileSystemHelper.MapSize(viewport.ZoomLevel);
            List<GraphicsPath> paths = new List<GraphicsPath>();
            List<RectangleL> boundingRects = new List<RectangleL>();

            long start = viewport.PanOffset.Width;
            int maxWraparounds = 1;

            while (start + mapSize < viewport.ViewportInPixels.Width)
            {
                maxWraparounds++;
                start += mapSize;
            }

            for (int i = -1; i <= maxWraparounds; i++)
            {
                GraphicsPath path = new GraphicsPath();

                List<PointF> drawPoints = new List<PointF>();

                foreach (PointG p in this.Points)
                {
                    PointL pixel = MapTileSystemHelper.LatLongToPixelXY(p.Latitude, p.Longitude, viewport.ZoomLevel);
                    drawPoints.Add(new PointF(pixel.X + i * mapSize, pixel.Y));
                }

                path.AddLines(drawPoints.ToArray());

                RectangleF rect = path.GetBounds();
                RectangleF view = new RectangleF(viewport.ViewportInPixels.X, viewport.ViewportInPixels.Y, 
                    viewport.ViewportInPixels.Width, viewport.ViewportInPixels.Height);

                if (rect.IntersectsWith(view))
                {
                    paths.Add(path);
                }

                boundingRects.Add(new RectangleL((long)rect.X, (long)rect.Y, (long)rect.Width, (long)rect.Height)); 
            }

            this.pathsField.SetValue(this, paths);
            this.boundingRectsField.SetValue(this, boundingRects);
        }

        if (action != ViewportChangeAction.None)
        {
            this.isInViewportField.SetValue(this, false);
            List<RectangleL> boundingRects = this.boundingRectsField.GetValue(this) as List<RectangleL>;

            foreach (RectangleL rect in boundingRects)
            {
                if (viewport.ViewportInPixels.IntersectsWith(rect))
                {
                    this.isInViewportField.SetValue(this, true);
                }
            }
        }
    }
}
0 comments