This is a migrated thread and some comments may be shown as answers.
Dynamic Layer exception when loading too many objects
3 Answers 67 Views
Map
This is a migrated thread and some comments may be shown as answers.
Pedro
Top achievements
Rank 1
Pedro asked on 15 Oct 2010, 12:06 PM
Hi,

I am using Map control with dynamic layer and its working with fee objects, but when I try to load for instance 186 objects it throws ArgumentException with the error: "Value does not fall within the expected range.".
I dont know what it means.
My itemsRequest method is like this:

public void ItemsRequest(double minZoom, double maxZoom, Location upperLeft, Location lowerRight, Action<System.Collections.ICollection> callback)
        {
            LocationRect locationRect = new LocationRect(upperLeft, lowerRight);
            List<object> objects = new List<object>();  
            if (minZoom <= 3)
            {
                page.listTrackLayer.ForEach((trackLayer) =>
                    {
                        LocationRect rect = trackLayer.MapPolyline.GeographicalBounds;
                        if (rect.Intersect(locationRect))
                        {
                            objects.Add(trackLayer.MapPolyline);
                            trackLayer.PinPoints.ForEach((point) =>
                            {
                                 
                                objects.Add(point);
 
                            });
                        }
                    });
 
            }
            if (minZoom >= 9)
            {
                page.listTrackLayer.ForEach((trackLayer) =>
                {
                    LocationRect rect = trackLayer.MapPolyline.GeographicalBounds;
                    if (rect.Intersect(locationRect))
                    {
                        objects.Add(trackLayer.MapPolyline);
                        trackLayer.PinPoints.ForEach((point) =>
                            {
                                objects.Add(point);
 
                            });
                    }
                });
            }
             
            callback(objects);
        }

It throws this exception when I call the callback(objects).

Best regards,
Gonçalo

3 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 20 Oct 2010, 03:34 PM
Hello Gonçalo,

The exception could be thrown when you add some polyline to the dynamic layer twice, because a polyline can intersect more than one requested area. So, you should check that the polyline is not added to the dynamic layer earlier.

The sample code is below.
public void ItemsRequest(double minZoom, double maxZoom, Location upperLeft, Location lowerRight, Action<System.Collections.ICollection> callback)
{
    LocationRect locationRect = new LocationRect(upperLeft, lowerRight);
    List<object> objects = new List<object>();
    if (minZoom <= 3)
    {
        page.listTrackLayer.ForEach((trackLayer) =>
        {
            if (!page.dynamicLayer.Items.Contains(trackLayer.MapPolyline))
            {
                LocationRect rect = trackLayer.MapPolyline.GeographicalBounds;
                if (rect.Intersect(locationRect))
                {
                    objects.Add(trackLayer.MapPolyline);
                    trackLayer.PinPoints.ForEach((point) =>
                    {
                        objects.Add(point);
                    });
                }
            }
        });
    }
    if (minZoom >= 9)
    {
        page.listTrackLayer.ForEach((trackLayer) =>
        {
            if (!page.dynamicLayer.Items.Contains(trackLayer.MapPolyline))
            {
                LocationRect rect = trackLayer.MapPolyline.GeographicalBounds;
                if (rect.Intersect(locationRect))
                {
                    objects.Add(trackLayer.MapPolyline);
                    trackLayer.PinPoints.ForEach((point) =>
                    {
                        objects.Add(point);
                    });
                }
            }
        });
    }
    callback(objects);
}

Regards,
Andrey Murzov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Pedro
Top achievements
Rank 1
answered on 20 Oct 2010, 04:10 PM
Thanks for the answer. The problem is that actually I am doing that.

public void ItemsRequest(double minZoom, double maxZoom, Location upperLeft, Location lowerRight, Action<System.Collections.ICollection> callback)
        {
            OldLocation = new Location();
            Location TextOldLocation = new Location();            
            lock (page.listTrackLayer)
            {
                LocationRect locationRect = new LocationRect(upperLeft, lowerRight);
                List<object> objects = new List<object>();
                  
                    page.listTrackLayer.ForEach((trackLayer) =>
                        {
                            LocationRect rect = trackLayer.MapPolyline.GeographicalBounds;
                            if (rect.Intersect(locationRect))
                            {
                                if (!page.DynamicLayer.Items.Contains(trackLayer.MapPolyline))
                                    objects.Add(trackLayer.MapPolyline);                                
                                  
                                trackLayer.PinPoints.ForEach((point) =>
                                {
                                    Location location = MapLayer.GetLocation(point);
                                    if (locationRect.Contains(location))
                                    {                                   
                                        if (CheckMinimumDistance(location, OldLocation, 15))
                                        {
                                            if (!page.DynamicLayer.Items.Contains(point))
                                                objects.Add(point);
  
                                            OldLocation = location;
                                        }                                        
  
                                        if (CheckMinimumDistance(location, TextOldLocation, 75))
                                        {
                                            point.Text = trackLayer.PinPointSubtitle[point];
                                            TextOldLocation = location;
                                        }
                                        else
                                            point.Text = string.Empty;
                                    }
                                });                                
                            }
                        });
  
                callback(objects);
            }
        }

But it is working good till I delete the track line, and try to add it again. the second time it throws the exception. When I debug into the code I saw that the DynamicLayer doesn't have items (count = 0) and than it throws the exception in callback function.

I made a simple aplication that can simulate the problem.
for that you do the next steps:
Click buttons:
1 - create
2- Refresh
3-Delete
4-Create
5-Refresh

Throws exception.
Maybe the problem is because I create a new MapPolyline Object and when it looks into the DynamicLayer dont find the current object there, but there exists one with the same polyline. But its strange when the DynamicLayer.Items.Count = 0.

You can download the solution here:
http://www.megaupload.com/?d=RB47FCBM

Kind regards,
Gonçalo





0
Accepted
Andrey
Telerik team
answered on 22 Oct 2010, 08:01 AM
Hello Gonçalo,

Thank you for the sample solution. It was very helpful for reproducing and analyze.

A cause of the ArgumentException with the "Value does not fall within the expected range" error is in using the Name property of MapShape objects (MapPolyline, MapPolygon etc).
When you use the Name property then it is still registered in visual tree although it has been removed from the layer. And when you add the map polyline second time then the exception is thrown.

We have created the PITS issue to fix this problem in future releases.
You can track it using the following link:
http://www.telerik.com/support/pits.aspx#/public/silverlight/3789

As workaround use the map polylines without using the Name property or use the Tag property instead.


Kind regards,
Andrey Murzov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Map
Asked by
Pedro
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Pedro
Top achievements
Rank 1
Share this question
or