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

Items disappearing on shape file while zooming out

1 Answer 137 Views
Map
This is a migrated thread and some comments may be shown as answers.
da cunha
Top achievements
Rank 1
da cunha asked on 05 Sep 2016, 04:08 PM

Hello,

We are currently using the radmap control to display a shape file (1MB) showing a map of the world.

The virtualization engine is also used in order to maximize the performance for this relatively large shape file.

It is used as follow (largely inspired by telerik examples):

 

<telerik:VisualizationLayer
MapShapeVisualizationCreated="VisualizationLayer_MapShapeVisualizationCreated"
MapShapeVisualizationRemoved="VisualizationLayer_MapShapeVisualizationRemoved"
AutoHighlightMapShape="False" >
<telerik:VisualizationLayer.VirtualizationSource>
 <telerik:MapShapeDataVirtualizationSource x:Name="VirtualisationSource" BusyIndicator="{Binding ElementName=busyIndicator}">
<telerik:MapShapeDataVirtualizationSource.Reader>
<telerik:AsyncShapeFileReader ReadShapeDataCompleted="AsyncShapeFileReader_ReadShapeDataCompleted"  />
</telerik:MapShapeDataVirtualizationSource.Reader>
</telerik:MapShapeDataVirtualizationSource>
</telerik:VisualizationLayer.VirtualizationSource>
<telerik:VisualizationLayer.ZoomLevelGridList>
<telerik:ZoomLevelGrid MinZoom="5" />
<telerik:ZoomLevelGrid MinZoom="6" />
<telerik:ZoomLevelGrid MinZoom="7" />
<telerik:ZoomLevelGrid MinZoom="8" />
<telerik:ZoomLevelGrid MinZoom="9" />
<telerik:ZoomLevelGrid MinZoom="10" />
<telerik:ZoomLevelGrid MinZoom="11" />
<telerik:ZoomLevelGrid MinZoom="12" />
</telerik:VisualizationLayer.ZoomLevelGridList>
<telerik:VisualizationLayer.ItemTemplate>
<DataTemplate>
<Rectangle Width="10"
Height="10"
telerik:MapLayer.Location="{Binding}"
Fill="Transparent"
MouseMove="Rectangle_MouseMove"
StrokeThickness="2" telerik:MapLayer.ZoomRange="5,12">
<!--<telerik:MapLayer.HotSpot>
<telerik:HotSpot X="0.5" Y="0.5" />
</telerik:MapLayer.HotSpot>-->
</Rectangle>
</DataTemplate>
</telerik:VisualizationLayer.ItemTemplate>
</telerik:VisualizationLayer>

 

A menu is displayed when the map is right clicked. It allows to add a start or a waypoint. A line is traced between the rectangles item

<telerik:RadMap.ContextMenu>
<ContextMenu>
<MenuItem Click="StartNewRouteMenuItem_Click" Header="Start new route" />
<MenuItem x:Name="AddWayPointMenuItem"
Click="AddWayPointMenuItem_Click"
 Header="Add way point"
IsEnabled="False" />
<MenuItem x:Name="EndRouteMenuItem"
   Click="EndRouteMenuItem_Click"
   Header="end route"
   IsEnabled="False" />
  <MenuItem x:Name="ResetMenuItem"
     Click="ResetMenuItem_Click"
 Header="Reset route"
 IsEnabled="True" />
     </ContextMenu>

Firts issue :

When the map is right clicked the menu is shown, but the shape file disappears.

Moving the map will correct this.

 

Second issue :

While zooming out the lines and the rectangle disappears , while the shape file is correctly displayed.

 

Here is apart of the code behind :

/// <summary>
 
        /// Handles the MouseRightButtonDown event of the WorldRadMap control.
 
        /// </summary>
 
        /// <param name="sender">The source of the event.</param>
 
        /// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs" /> instance containing the event data.</param>
 
        private void WorldRadMap_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
 
        {
 
            previousMouseClickPos = lastMouseClickPos;
 
            lastMouseClickPos = e.GetPosition(WorldRadMap);
 
            Point1 = Point2;
 
            Point2 = Location.GetCoordinates(WorldRadMap, lastMouseClickPos);
 
        }
 
        
 
        /// <summary>
 
        /// Adds the point to map.
 
        /// </summary>
 
        /// <returns></returns>
 
        private bool AddPointToMap()
 
        {
 
            var location = Location.GetCoordinates(WorldRadMap, lastMouseClickPos);
 
            if (GribAPI_GTT.IsOnContinent(location.Longitude, location.Latitude))
 
            {
 
                MessageBox.Show("WayPoint must be in open sea");
 
                return false;
 
            }
 
            
 
            this.visualizationlayer.Items.Add(Location.GetCoordinates(WorldRadMap, lastMouseClickPos));
 
            return true;
 
        }
 
  
 
/// <summary>
 
        /// Draws the line.
 
        /// </summary>
 
        private void DrawLine()
 
        {
 
            LineData line = new LineData()
 
            {
 
                Point1 = Point1,
 
                Point2 = Point2,
 
                ShapeFill = new MapShapeFill()
 
                {
 
                    Stroke = new SolidColorBrush(Colors.Purple),
 
                    StrokeThickness = 2,
 
                }
 
            };
 
            
 
            this.visualizationlayer.Items.Add(line);
 
        }

 

 

Is there a way that the items and the shapefile keep displaying

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 08 Sep 2016, 09:07 AM
Hello,

The shapes from the shape file disappears when you zoom in/out because each time you enter a zoom range from the ZoomLevelGridList a new request to the virtualization source is made and the shapes in the view port are redrawn. Currently, you can ZoomLevelGrids defined for each level between 5 and 12. This means that a request will be made at each level between 5 and 12. If you want to minimize the shape's disappearing you can define bigger zoom level ranges. For example:
<telerik:VisualizationLayer.ZoomLevelGridList>
    <telerik:ZoomLevelGrid MinZoom="5" />
    <telerik:ZoomLevelGrid MinZoom="8" />
    <telerik:ZoomLevelGrid MinZoom="10" />
</telerik:VisualizationLayer.ZoomLevelGridList>
In this example requests will be made and the shapes will be redrawn when the map is at zoom level 5, 8, 10. In between those ranges the map will use the already rendered shapes and won't request new items.

About the context menu and the shapes disappearing, I wasn't able to reproduce this. However, keep in mind that when you use a reader the newly read shapes will override any other elements defined in the layer. This is why you can consider using separate layer for the line drawn between the clicked points.
 
Regards,
Martin
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
Map
Asked by
da cunha
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or