Select to view content in your preferred language

Zoom to Graphic Laybe point Point

624
4
10-14-2011 05:52 AM
MattMiley
Deactivated User
Alright here is my code
private void FindDetails_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // Highlight the graphic feature associated with the selected row
            DataGrid dataGrid = sender as DataGrid;

            int selectedIndex = dataGrid.SelectedIndex;
            if (selectedIndex > -1)
            {
                FindResult findResult = (FindResult)FindDetailsDataGrid.SelectedItem;
                Graphic graphic = findResult.Feature;

                switch (graphic.Attributes["Shape"].ToString())
                {
                    case "Polygon":
                        graphic.Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
                        break;
                    case "Polyline":
                        graphic.Symbol = LayoutRoot.Resources["DefaultLineSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
                        break;
                    case "Point":
                        graphic.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol1"] as ESRI.ArcGIS.Client.Symbols.Symbol;
                        break; 
                }

                GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
                graphicsLayer.ClearGraphics();
                graphicsLayer.Graphics.Add(graphic);

                // Zoom to selected feature (define expand percentage)
                ESRI.ArcGIS.Client.Geometry.Envelope selectedFeatureExtent = graphic.Geometry.Extent;

                //MyMap.ZoomTo(graphic.Geometry as ESRI.ArcGIS.Client.Geometry.Envelope);

                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));

                MyMap.ZoomTo(displayExtent);
            }
        }


The map zooms to the polylines and polygons just fine, but it won't pan to the points. I even added a zoom to graphic layer button just to see if that would work whenever i selected a point in the grid and then it makes the point graphic layer except it won't zoom to it. Does anyone have any suggestions on how to zoom to a graphic point?

Thanks
0 Kudos
4 Replies
SanajyJadhav
Deactivated User
Try creating a small Envelope around your point and then zoom to that envelope.

Sanjay.
0 Kudos
SanajyJadhav
Deactivated User

                // Zoom to selected feature (define expand percentage)
                ESRI.ArcGIS.Client.Geometry.Envelope selectedFeatureExtent = graphic.Geometry.Extent;


Might be envelope of the point geometry is to small for zooming. Try creating a more bigger envelope (although you have done it) and then zoom to that envelope.

-
Sanjay.
0 Kudos
MattMiley
Deactivated User
Try creating a more bigger envelope (although you have done it) and then zoom to that envelope.

-
Sanjay.


Whenever i do that it only changes the extent on the polygon graphics. It zooms to the same extent every time on the polylines, and doesn't zoom at all to the points.

I almost think i need just need to zoom the the center point of the graphic object somehow.
0 Kudos
MattMiley
Deactivated User
I figured it out... peep game

private void FindDetails_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // Highlight the graphic feature associated with the selected row
            DataGrid dataGrid = sender as DataGrid;

            int selectedIndex = dataGrid.SelectedIndex;
            if (selectedIndex > -1)
            {
                FindResult findResult = (FindResult)FindDetailsDataGrid.SelectedItem;
                Graphic graphic = findResult.Feature;
                 
                switch (graphic.Attributes["Shape"].ToString())
                {
                    case "Polygon":
                        graphic.Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
                        break;
                    case "Polyline":
                        graphic.Symbol = LayoutRoot.Resources["DefaultLineSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
                        break;
                    case "Point":
                        graphic.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol1"] as ESRI.ArcGIS.Client.Symbols.Symbol;
                        
                        MapPoint candidatePoint = graphic.Geometry as MapPoint;
                double displaySize = MyMap.MinimumResolution * 30;

                ESRI.ArcGIS.Client.Geometry.Envelope displayExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(
                    candidatePoint.X - (displaySize / 2),
                    candidatePoint.Y - (displaySize / 2),
                    candidatePoint.X + (displaySize / 2),
                    candidatePoint.Y + (displaySize / 2));

                MyMap.ZoomTo(displayExtent);
                break;
                }

                GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
                graphicsLayer.ClearGraphics();
                graphicsLayer.Graphics.Add(graphic);

                // Zoom to selected feature (define expand percentage)
                ESRI.ArcGIS.Client.Geometry.Envelope selectedFeatureExtent = graphicsLayer.FullExtent;   //graphic.Geometry.Extent; 

                MyMap.ZoomTo(selectedFeatureExtent);
            }
        }
0 Kudos