Select to view content in your preferred language

Zoom

979
7
04-25-2011 09:22 AM
JayKappy
Frequent Contributor
In my app i have a PID value search.  It finds the PID value (finds the Land Parcel) and zooms to that Parcel.  Whiles this is happening I run another series of Querys that Buffer the Parcel and find records, addintially I do a series of spatial queries to find other data.

Everything works great but my zoom is only aware of the original Parcel found...At any one point I have two graphic layers beign displayed on the map....the Main Parcel and one of the other features, BUT only 2 at a time...

Is there a way to test wether or now a Graphic Layer is visable and if visialbe zoom to that layers extent?

Thanks
0 Kudos
7 Replies
JayKappy
Frequent Contributor
I am horsing around with this.....getting soemthing to zoom to the extent of a graphics layer
Missing syntax here.....AND dont even know if I can do this...

        Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayerSearch"), GraphicsLayer)

        ' Zoom to selected feature (define expand percentage)
        Dim ZoomTographicslayer As ESRI.ArcGIS.Client.Geometry.Envelope = graphicsLayer        
        Dim expandPercentage As Double = 230
        Dim widthExpand As Double = ZoomTographicslayer.Width * (expandPercentage / 4)
        Dim heightExpand As Double = ZoomTographicslayer.Height * (expandPercentage / 4)
        Dim displayExtent As New ESRI.ArcGIS.Client.Geometry.Envelope(ZoomTographicslayer.XMin - (widthExpand / 2), ZoomTographicslayer.YMin - (heightExpand / 2), ZoomTographicslayer.XMax + (widthExpand / 2), ZoomTographicslayer.YMax + (heightExpand / 2))

        MyMap.ZoomTo(ZoomTographicslayer)



Can I simply Zoom to graphics Layer?
0 Kudos
JayKappy
Frequent Contributor
Think I got it

        Dim l_Parks As GraphicsLayer = TryCast(Me.MyMap.Layers("MySelectionGraphicsLayerParks"), GraphicsLayer)
        l_Parks.Visible = True

        ' Zoom to feature (define expand percentage)
        Dim ZoomTographicslayer As ESRI.ArcGIS.Client.Geometry.Envelope = l_Parks.FullExtent
        Dim expandPercentage As Double = 230
        Dim widthExpand As Double = ZoomTographicslayer.Width * (expandPercentage / 4)
        Dim heightExpand As Double = ZoomTographicslayer.Height * (expandPercentage / 4)
        Dim displayExtent As New ESRI.ArcGIS.Client.Geometry.Envelope(ZoomTographicslayer.XMin - (widthExpand / 2), ZoomTographicslayer.YMin - (heightExpand / 2), ZoomTographicslayer.XMax + (widthExpand / 2), ZoomTographicslayer.YMax + (heightExpand / 2))
        MyMap.ZoomTo(ZoomTographicslayer)


BUT in one case I have 2 Graphic layers drawing.....one Polygon and one Point feature.....Can I combine the Geometry/Extent of the two AND THEN zoom to that?

Is there any way to zoom to the extent of 2 different Graphic Layers......being different FC types (point, line, poly)?????????
0 Kudos
TerryGiles
Frequent Contributor
The Envelope class has a Union method which you could try to use to get the full extent of both layers.. you may need to check the extent of the graphics layers containing 1 point though, as it my not have a valid extent.  If that's the case, just fake it by creating a new envelope centered on the point w/ the width & height set to 1 foot or meter or some other appropriately small value.


below is a C# example of using the union method.   Hope it helps, TG

                      //zoom to all features returned by the query task
                        Envelope extent = fs.Features[0].Geometry.Extent;
                        foreach (Graphic g in fs.Features)
                        {
                            extent.Union(g.Geometry.Extent);
                        } 
                        Map.ZoomTo(extent);
0 Kudos
JayKappy
Frequent Contributor
Not really following on the Union....I need to specifiy two Graphic layers that are in the map by name then union them and get the extent....
I am doign the zoom thing when the user hovers over a specific tab in a tab control...this is where I am turing on specific layers and zooming to them...

But do hear you on the point and not having a valid extent...I am running into that already...so I guess I have to start there...and then worry about the above...not really finding that or familiar with that in any way....can I do this on the fly when the Graphic point is created?


Dim l_PointOne As GraphicsLayer = TryCast(Me.MyMap.Layers("MySelectionGraphicsLayerPoint"), GraphicsLayer)
Dim l_polygon1 As GraphicsLayer = TryCast(Me.MyMap.Layers("MySelectionGraphicsLayerPoly"), GraphicsLayer)

'Then do some sort of Union and get the extent??????????????
0 Kudos
TerryGiles
Frequent Contributor
the GraphicLayers have a FullExtent property which returns an Envelope.  These 2 envelopes can be unioned to get the full extent of both layers.  In general like this ..

Dim l_PointOne As GraphicsLayer = TryCast(Me.MyMap.Layers("MySelectionGraphicsLayerPoint"), GraphicsLayer)
Dim l_polygon1 As GraphicsLayer = TryCast(Me.MyMap.Layers("MySelectionGraphicsLayerPoly"), GraphicsLayer)

'make sure the extent from the point graphics layer is valid otherwise create one here

Dim NewExtent as Envelope = l_polygon1.fullextent.union(l_pointone.fullextent)

MyMap.ZoomTo(NewExtent)


0 Kudos
JayKappy
Frequent Contributor
Thanks a ton....have to work on getting the extent of the point valid, but have a very solid base to work from ...thank again....

Here is a point....am I on the right path to Defien a new envelope for it as you mentioned..

        ' Turn On Layer
        Dim l_PoliceHQBuffer As GraphicsLayer = TryCast(Me.MyMap.Layers("MyGraphicsLayerPoliceHeadQuaters"), GraphicsLayer)
        l_PoliceHQBuffer.Visible = True

        ' Zoom to feature (define expand percentage)
        Dim ZoomTographicslayer As ESRI.ArcGIS.Client.Geometry.Envelope = l_PoliceHQBuffer.FullExtent
        Dim Width As Double = 1
        Dim Height As Double = 1        
        Dim expandPercentage As Double = 5
        Dim widthExpand As Double = ZoomTographicslayer.Width * (expandPercentage / 4)
        Dim heightExpand As Double = ZoomTographicslayer.Height * (expandPercentage / 4)
        Dim displayExtent As New ESRI.ArcGIS.Client.Geometry.Envelope(ZoomTographicslayer.XMin - (widthExpand / 2), ZoomTographicslayer.YMin - (heightExpand / 2), ZoomTographicslayer.XMax + (widthExpand / 2), ZoomTographicslayer.YMax + (heightExpand / 2))
        MyMap.ZoomTo(displayExtent)
0 Kudos
JayKappy
Frequent Contributor
Got it....was staring me right in the face....Thank you for the Union code and the directional push

THANKS A BUNCH....VERY APPRECIATED...


        ' Turn On Layer
        Dim l_Precinct As GraphicsLayer = TryCast(Me.MyMap.Layers("MySelectionGraphicsLayerPrecincts"), GraphicsLayer)
        l_Precinct.Visible = True
        Dim l_PrecinctPt As GraphicsLayer = TryCast(Me.MyMap.Layers("MySelectionGraphicsLayerPrecinctsPts"), GraphicsLayer)
        l_PrecinctPt.Visible = True

        ' SET EXTENT AND BACK OUT ZOOM OF THE PRECINCT PARCEL
        Dim ZoomTographicslayer As ESRI.ArcGIS.Client.Geometry.Envelope = l_Precinct.FullExtent
        Dim expandPercentage As Double = 5
        Dim widthExpand As Double = ZoomTographicslayer.Width * (expandPercentage / 4)
        Dim heightExpand As Double = ZoomTographicslayer.Height * (expandPercentage / 4)
        Dim displayExtentPrecinct As New ESRI.ArcGIS.Client.Geometry.Envelope(ZoomTographicslayer.XMin - (widthExpand / 2), ZoomTographicslayer.YMin - (heightExpand / 2), ZoomTographicslayer.XMax + (widthExpand / 2), ZoomTographicslayer.YMax + (heightExpand / 2))
        'MyMap.ZoomTo(displayExtent)

        ' REDEFINE THE EXTENT OF THE SINGLE POINT
        Dim ZoomTographicslayer1 As ESRI.ArcGIS.Client.Geometry.Envelope = l_PrecinctPt.FullExtent
        Dim Width As Double = 15
        Dim Height As Double = 15
        Dim displayExtentPrecinctPt As New ESRI.ArcGIS.Client.Geometry.Envelope(ZoomTographicslayer1.XMin - Width, ZoomTographicslayer1.YMin - Height, ZoomTographicslayer1.XMax + Width, ZoomTographicslayer1.YMax + Height)
        'MyMap.ZoomTo(displayExtent1)

        ' CREATE NEW ENVELOPE AND UNION THE TWO LAYERS
        Dim NewExtent As Envelope = displayExtentPrecinct.Union(displayExtentPrecinctPt)
        ' ZOOM TO THE NEW EXTENT
        MyMap.ZoomTo(NewExtent)
0 Kudos