This is a migrated thread and some comments may be shown as answers.

Map Layout Cycle Detected

3 Answers 84 Views
Map
This is a migrated thread and some comments may be shown as answers.
Oliver
Top achievements
Rank 1
Oliver asked on 05 Mar 2015, 03:45 PM
Hello, I was hoping someone can help me with this issue I am having. 

I have a map application that does the following functions: 

I displays routes that contains varying numbers of stops. Each stop is represented by a flag and the route is the line that connects its related stops (all color coded per route). Right now I encounter the error :Unhandled Error in Silverlight Application Code: 4008  which crashes my application  ONLY when displaying 42 routes and above. I initially thought that it might have something to do with the number of stops but I have tested using more than 5k stops and it works fine as long as there 41 routes or less.

my code is sort of divided into a number of user controls but I will try to present the relevant parts here:

the xaml view:

<UserControl x:Class="PcsysSLFx.Controls.Maps.SLFxMapView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             d:DesignHeight="300"
             d:DesignWidth="400"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             Loaded="UserControl_Loaded">
    <UserControl.Resources>

        <DataTemplate x:Key="MapItemTemplate">
            <Border telerik:MapLayer.Location="{Binding Location}"
                    telerik:MapLayer.HotSpot="{Binding HotSpot}"
                    Background="{Binding Background}"
                    BorderBrush="{Binding BorderBrush}"
                    BorderThickness="{Binding BorderThickness}">
                <Grid Width="50"
                      Height="70"
                      Margin="5">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <TextBlock Grid.Row="0"
                               Text="{Binding Title}"
                               HorizontalAlignment="Center" />
                    <TextBlock Grid.Row="1"
                               Text="{Binding Description}"
                               HorizontalAlignment="Center" />
                </Grid>
            </Border>
        </DataTemplate>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot"
          Background="White">

        <telerik:RadBusyIndicator x:Name="busyIndicator"
                                  IsIndeterminate="False">
            <telerik:RadMap x:Name="slFxMapView"
                            InitializeCompleted="slFxMapView_InitializeCompleted"
                            MapMouseDoubleClick="slFxMapView_MapMouseDoubleClick"
                            UseDefaultLayout="True"
                            ScaleVisibility="Collapsed"
                            MiniMapExpanderVisibility="Collapsed"
                            MouseLocationIndicatorVisibility="Collapsed"
                            ZoomBarPresetsVisibility="Collapsed"
                            MouseClickMode="Center"
                            MouseDoubleClickMode="None"
                            ZoomLevel="{Binding Path=ZoomLevel}"
                            Center="{Binding Path=Center}"
                            ZoomChanged="slFxMapView_ZoomChanged"
                            NavigationVisibility="Collapsed">
             

                <telerik:InformationLayer x:Name="calloutLayer" />
                
                <telerik:InformationLayer x:Name="vehicleLayer" />
               
            </telerik:RadMap>
        </telerik:RadBusyIndicator>
    </Grid>
</UserControl>  

Code Behind:  

private void SetMapItems()
        {
            if (this.MapItem.PcsysFxMapDataSets == null)
            {
                return;
            }


            this.busyIndicator.IsBusy = true;
            if (this.MapItem == null)
            {
                this.busyIndicator.IsBusy = false;
                return;
            }

            this.slFxMapView.Items.Clear();
            this.layerList.Clear();
            itemFound = false;

            if (this.ParentOfType<SLFxMap>().MapSearch.TimerRequest != true)
            {
                this.calloutLayer.Items.Clear();
                this.vehicleLayer.Items.Clear();
            }

            Location topLeftLocation = new Location(0, 100);
            Location bottomRightLocation = new Location(100, 0);

            int appColorcount = AppBase.Current.RootVisualContainer.Colors.Count(); 
           

            foreach (var dataSet in this.MapItem.PcsysFxMapDataSets)
            {
                
                var itemsList = (from l in dataSet.PointLocations orderby l.ExtraData["GroupingField"] select l.ExtraData["GroupingField"]).Distinct();
                
                
                if (itemsList.Count() > 0) this.ImageHeadings = new List<RotateTransform>();
                int count = 0;
              

                    foreach (var listItem in itemsList)
                    {
                        
                        
                        var color = AppBase.Current.RootVisualContainer.Colors.FirstOrDefault(p => p.ColorId == count);
                        if (dataSet.ConnectedPoints)
                        {
                            InformationLayer lineLayer = new InformationLayer();

                            InformationLayer pointLayer = new InformationLayer();

                            InformationLayer pinpointLayer = new InformationLayer();

                            MapPolyline polyLine = new MapPolyline();
                            polyLine.Points = new LocationCollection();

                            foreach (MapViewItem item in dataSet.PointLocations.OrderBy(d => d.DateTime).Where(p => p.ExtraData["GroupingField"].ToString() == listItem.ToString()))
                            {
                                topLeftLocation = this.GetExtremeTopLeft(topLeftLocation, item.GPSLat, item.GPSLon);
                                bottomRightLocation = this.GetExtremeBottomRight(bottomRightLocation, item.GPSLat, item.GPSLon);

                                // test code to make ellipse into pinpoint
                                var pinPoint = new SLFxMapPinPoint();
                                pinPoint.ImageSource = ResolveImageUri(dataSet.ImageUri);
                                pinPoint.MaskSource = ResolveImageUri(dataSet.ImageMaskUri);
                                pinPoint.MaskColor = GetMapItemColor(color);
                                pinPoint.MapPinPointLocation = new Location(item.GPSLat, item.GPSLon);
                                ToolTipService.SetToolTip(pinPoint, BuildToolTipString(dataSet.PcsysFxMapDataSetDisplayInfoes.ToList(), item));

                                MapLayer.SetLocation(pinPoint, pinPoint.MapPinPointLocation);

                                pinpointLayer.Items.Add(pinPoint);
                                pinpointlayercount++;

                                Location location = new Location(item.GPSLat, item.GPSLon);

                                if ((calloutDisplayed) && (item.Label == tempcalloutId))
                                {
                                    calloutLocation = pinPoint.MapPinPointLocation;
                                    itemFound = true;
                                }

                                polyLine.Stroke = new SolidColorBrush(color.MediaColor);

                                polyLine.StrokeThickness = dataSet.LineThickness;
                                polyLine.Points.Add(location);
                                polylinepointscount++;
                            }

                            lineLayer.Items.Add(polyLine);
                            this.slFxMapView.Items.Add(lineLayer);

                            this.slFxMapView.Items.Add(pointLayer);

                            this.slFxMapView.Items.Add(pinpointLayer);


                        }
                        else
                        {
                            InformationLayer layer = new InformationLayer();

                            var pointLocationsByTransportId = dataSet.PointLocations.Where(l => l.ExtraData["GroupingField"].ToString() == listItem.ToString());

                            foreach (MapViewItem item in pointLocationsByTransportId)
                            {
                                topLeftLocation = this.GetExtremeTopLeft(topLeftLocation, item.GPSLat, item.GPSLon);
                                bottomRightLocation = this.GetExtremeBottomRight(bottomRightLocation, item.GPSLat, item.GPSLon);

                                var pinPoint = new SLFxMapPinPoint();
                                var stopCompleted = false;
                                var activityStatus = string.Empty;
                                try
                                {
                                    stopCompleted = Convert.ToInt32(item.ExtraData["IsComplete"]) == 1 ? true : false;
                                }
                                catch
                                {
                                }

                                if (!stopCompleted)
                                {
                                    pinPoint.ImageSource = ResolveImageUri(dataSet.ImageUri);
                                }
                                else
                                {
                                    pinPoint.ImageSource = ResolveImageUri(dataSet.AlternateImageUri);
                                }

                                if (dataSet.ImageMaskUri != null && dataSet.ImageMaskUri != string.Empty)
                                {
                                    AssignMaskColor(ref pinPoint, item, dataSet);

                                    pinPoint.MaskSource = ResolveImageUri(dataSet.ImageMaskUri);
                                }

                                if (dataSet.ShowLabel)
                                {
                                    //display labels of map items and truncates labes greater than 10 characters for readability
                                    var label = item.Label;
                                    if (item.Label.Length > 12) label = label.Substring(0, 12) + "...";
                                    pinPoint.Text = label;
                                }

                                pinPoint.MapPinPointLocation = new Location(item.GPSLat, item.GPSLon);
                                MapLayer.SetLocation(pinPoint, pinPoint.MapPinPointLocation);
                                ToolTipService.SetToolTip(pinPoint, BuildToolTipString(dataSet.PcsysFxMapDataSetDisplayInfoes.ToList(), item));

                                if ((calloutDisplayed) && (item.Label == tempcalloutId))
                                {
                                    calloutLocation = pinPoint.MapPinPointLocation;
                                    itemFound = true;
                                }

                                double angle = -1.0;
                                try
                                {
                                    angle = Convert.ToDouble(item.ExtraData["Heading"]);
                                }
                                catch
                                {
                                }
                                if (angle > -1)
                                {
                                    RotateTransform maskheading = new RotateTransform();
                                    maskheading.Angle = Convert.ToDouble(item.ExtraData["Heading"], CultureInfo.InvariantCulture);

                                    pinPoint.mask.RenderTransformOrigin = new Point(0.5, 0.6);
                                    pinPoint.mask.RenderTransform = maskheading;
                                }

                                layer.Items.Add(pinPoint);

                                SetImageScale(layer);
                            }


                            this.slFxMapView.Items.Add(layer);
                            var test = layer.Items.Count();
                            layerList.Add(layer);
                        }
                    }

                
            }

            topLeftLocation.Latitude += margin;
            topLeftLocation.Longitude -= margin;
            bottomRightLocation.Longitude += margin;
            bottomRightLocation.Latitude -= margin;

            if (this.ParentOfType<SLFxMap>().MapSearch.TimerRequest != true)
            {
                LocationRect rect = new LocationRect(topLeftLocation, bottomRightLocation);

                try
                {
                    rect.MapControl = this.slFxMapView;
                }
                catch (Exception ex)
                {
                    if (ex != null)
                    {
                        this.busyIndicator.IsBusy = false;
                        return;
                    }
                }

                this.slFxMapView.Center = rect.Center;
                this.slFxMapView.ZoomLevel = rect.ZoomLevel;
            }

            foreach (var item in layerList)
            {
                SetImageScale(item);
            }

            if ((calloutDisplayed) && (this.calloutLayer.Items.Count > 0))
            {
                var vehicleCallout = this.calloutLayer.Items.FirstOrDefault() as MapViewItem;
                vehicleCallout.Location = calloutLocation;

                calloutLayer.Items.Clear();
                if (itemFound)
                {
                    calloutLayer.Items.Add(vehicleCallout);
                }
            }

            if (!this.slFxMapView.Items.Contains(this.calloutLayer))
            {
                this.slFxMapView.Items.Add(this.calloutLayer);
            }

            this.busyIndicator.IsBusy = false;
        }
So far when I trace the problem, the code actually passes through here without a hitch, its when it start to render does the app crash. Hope you guys can help, thanks in advance.

Oliver



















3 Answers, 1 is accepted

Sort by
0
Accepted
Pavel R. Pavlov
Telerik team
answered on 10 Mar 2015, 11:20 AM
Hello,

When working with the RadMap component you need to keep in mind that such limitations usually are limitations to the map provider itself. For example the Bing map provider can visualize up to 25 waypoints for a route. I am not sure which provider you use but I suggest checking if there is any limitation regarding the number of the routes in the documentation of the map provider (e.g. Bing map or ArcGis map).

Regards,
Pavel R. Pavlov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Oliver
Top achievements
Rank 1
answered on 12 Mar 2015, 12:49 PM
Hi Pavel,

Thanks for replying. I have been trying to approach the problem from different angles and I found out that when I remove the part that connects individual stops with MapPolylines , the crash does not occur. Would you have any idea why that is the case. Tracing the code does not reveal the error, only during render does it crash.  Obviously the lines connecting each stop is integral to the apps function so I cannot eliminate it.

Regards,
Oliver
0
Oliver
Top achievements
Rank 1
answered on 12 Mar 2015, 03:33 PM
Hi Pavel,

Nevermind, I have solved the issue. Apparently my code was generating a lot of information layers that causes the map to crash. Optimized that area of the code now.

Thanks,
Oliver

Tags
Map
Asked by
Oliver
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Oliver
Top achievements
Rank 1
Share this question
or