Select to view content in your preferred language

FeatureDataGrid zoom to selection

2556
10
11-02-2010 01:28 PM
DavidAshton
Frequent Contributor
I'm using the SDK example for FeatureDataGrid
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#FeatureDataGrid

I have the FeatureDataGrid firing populating with selected polys or points.  It seems to work well with polys but when I populate the table with records of selected points it won't zoom to a selected point. 

Is there something I need to change to make the Option - Zoom to Selection, work with points?

Thanks
David
0 Kudos
10 Replies
AliMirzabeigi
Emerging Contributor
David,

The default behavior of the "Zoom to Selection" menu is if the newly calculated extent has width and height greater than zero then it will zoom to that extent otherwise, the map would pan to that extent.

If the command does nothing for your layer then I suspect that the point collection in your layer has no extent associated with each point; you can verify this by checking the Geometry property of the Graphic objects in your layer and looking at its Extent property.
0 Kudos
DavidAshton
Frequent Contributor
Ali,

I'm unsure on how to verify the Geometry property of the Graphic objects in your layer and looking at its Extent property.

Can you tell me how to go about this?

Thanks
David
0 Kudos
AliMirzabeigi
Emerging Contributor
To test you can add a button in your application and on its click event handler write something like this:
FeatureLayer lyr = MapView.Layers[1] as FeatureLayer;
foreach (Graphic g in lyr)
{
 if (g.Geometry == null || g.Geometry.Extent == null)
 {
   MessageBox.Show(string.Format("Graphic with ID={0} has no extent.", g.Attributes["ObjectID"]));
   break;
 }
}
0 Kudos
DavidAshton
Frequent Contributor
Ali,
Thanks for the reply.  So MapView.Layers[1] gives me an error stating MapView doesn't exist in the current content.  Should I change MapView to MyMap?  If and when I do my code...click the button nothing happens....so is that good?  Do I need to select a point or something.  Like I stated before the zoom to selected works with polygons just not points(markers).  I don't have lines in my application so I'm not sure about polylines.

Dave
0 Kudos
JenniferNery
Esri Regular Contributor
Yes, in the code snippet Ali posted "MapView" is the name of his map. However you need to update the foreach loop to the following since you will be iterating to all graphics of the given layer.
foreach (Graphic g in lyr.Graphics)
{//same code goes here.}


Once you have confirmed that none of your graphics have an empty geometry or extent, then that will help us narrow down the issue. FeatureDataGrid zoom to selection handles zoom to point differently than zoom to polyline/polygon, but it should not be a problem if the geometry extent has a value.
0 Kudos
DavidAshton
Frequent Contributor
Ali and Jennifer,

I'm so sorry; I just noticed my map is paning to the selected points and if I select two or more points it will zoom to them.......so based on what Ali stated

"newly calculated extent has width and height greater than zero then it will zoom to that extent otherwise, the map would pan to that extent."

It appears when one point is selected it does not have a extent has width and height greater than zero so can I some how change this?  Should I make my point much larger.

Here's what my xaml/animation/resource story look likes for my marker symbol

 <esri:SimpleMarkerSymbol x:Key="ResultsMarkerSymbol"  >
                <esri:SimpleMarkerSymbol.ControlTemplate>
                    <ControlTemplate>

                        <Grid>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal">
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="Element"
                                                        
                                                 Storyboard.TargetProperty= "(Fill).(Color)"
                                                To="#FFF5FF45" Duration="0:0:0.1" />
                                        </Storyboard>

                                    </VisualState>

                                    <VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="Element"
                                                Storyboard.TargetProperty="(Fill).(Color)"
                                                To="#8800FFFF" Duration="0:0:0.1" />
                                        </Storyboard>
                                    </VisualState>

                                    <VisualState x:Name="Selected">
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="Element"
                                                Storyboard.TargetProperty="(Fill).(Color)"
                                                To="#8800FFFF" Duration="0:0:0.1" />
                                        </Storyboard>
                                    </VisualState>

                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>

                            <Ellipse x:Name= "Element"             
                                               Stroke="Blue" Fill="#8800FFFF"
                                StrokeStartLineCap="Round" StrokeThickness="2" 
                                StrokeLineJoin="Round" StrokeEndLineCap="Round"    
                                     Width="16"                 
                                     Height="16"                    
                                                    
                                      />

                        </Grid>

                    </ControlTemplate>
                </esri:SimpleMarkerSymbol.ControlTemplate>
            </esri:SimpleMarkerSymbol>


Thanks again.
0 Kudos
JenniferNery
Esri Regular Contributor
So you do not see the map pan to the selected point?  Try out this example and see if it behaves the same: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ToolkitFeatureDataGrid

Either check the Auto Zoom to Selected under Options before making a selection or make a selection and choose Zoom to Selection.  If it is a single selection of point geometry, it will perform a pan where the selected graphic is the center.
0 Kudos
AliMirzabeigi
Emerging Contributor
David,

Based on what I saw in your last post, it looks like you are experiencing the expected behavior (please correct me if I'm wrong). If you would like to zoom to ONE point having it in the center of a new extent in your map then you should implement your own command and maybe replace "Zoom to Selection" with the one you developed. For the case we are talking about if your point, say p, is the only selected feature in your layer you can calculate the new extent by creating a new Envelope, say e, such that:
e.XMin = p.X - xOffset;
e.XMax = p.X + xOffset;
e.YMin = p.Y - yOffset;
e.XMax = p.Y + yOffset;
Where the xOffset and yOffset are constant double variables you defined in your application.
Then set your map's Extent property to the envelope you created above.

Hope this makes sense.
0 Kudos
DavidAshton
Frequent Contributor
Ali,

Thanks for the reply,  so this similar to code in my query task....which is from the SDK example and that code is not working either.  So maybe if I can get the zoom to selected feature after an attribute query to fire I can move it over to a table command. 

Here's the code for zoom to selected feature (after a query is excuted and populated).  The query works great it selects the features and populates them in my table/grid but the map doesn't resize or pan to the selected features.

  if (featureSet != null && featureSet.Features.Count > 0)
            {

                
               // Show selected feature attributes in DataGrid
                foreach (Graphic selectedFeature in featureSet.Features)
                {

                    // Hightlight selected feature
                    selectedFeature.Symbol = LayoutRoot.Resources["ResultsMarkerSymbol"] as SimpleMarkerSymbol;
                    // Add to table DataGrid
                    graphicsLayer.Graphics.Add(selectedFeature);


 // Zoom to selected feature (define expand percentage)

                ESRI.ArcGIS.Client.Geometry.Envelope selectedFeatureExtent = selectedFeature.Geometry.Extent;

                double expandPercentage = 30;

                double widthExpand = selectedFeatureExtent.Width * (expandPercentage / 100);
                double heightExpand = selectedFeatureExtent.Height * (expandPercentage / 100);

                ESRI.ArcGIS.Client.Geometry.Envelope displayExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(
                selectedFeatureExtent.XMin - (widthExpand / 2),
                selectedFeatureExtent.YMin - (heightExpand / 2),
                selectedFeatureExtent.XMax + (widthExpand / 2),
                selectedFeatureExtent.YMax + (heightExpand / 2));

                Map.ZoomTo(displayExtent);


                }


               ResultsDisplay.Visibility = Visibility.Visible;
            }
            MyDrawSurface.IsEnabled = false;



Can you see something I should change to make this work?
0 Kudos