Zoom to

2740
15
01-03-2011 08:15 AM
JayKappy
Occasional Contributor
I have my app and have added a bunch of layers from ESRI

 
Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_ShadedRelief_World_2D/MapServer"/>
Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer"/>    
Url="http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer" />
Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/>       
Url="http://servicer.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_MedianIncome_US_2D/MapServer"/>


They draw great...adn then I added a bunch of my own layers on top of those.  These are in a DIFFERENT projection that much I know.  But they still display fine.

I am no running into issues with an example from ESRI Silverlight API...
            ' Zoom to selected feature (define expand percentage)
            Dim selectedFeatureExtent As ESRI.ArcGIS.Client.Geometry.Envelope = selectedFeature.Geometry.Extent

            Dim expandPercentage As Double = 230

            Dim widthExpand As Double = selectedFeatureExtent.Width * (expandPercentage / 50)
            Dim heightExpand As Double = selectedFeatureExtent.He   ight * (expandPercentage / 50)

            Dim displayExtent As 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)


This code is sort of working....
It highlights the selected feature and does a zoom.
BUT i have no idea where the zoom is to?  Its moving to an entrire differnet location than the selected feature should be.  It is selecting a Parcel...but moves to another location where the parcels are not....Could this be an issues with the two different coordinate systems...(between the ESRI data and mine).

Any thoughts?  Is there a way I can specify the projection info on the Zoom ?????

Thanks
0 Kudos
15 Replies
dotMorten_esri
Esri Notable Contributor
The Client API does not automatically do reprojection. You would have to call the GeometryService.Project method to reproject you features to the spatial reference of the map, prior to calling zoom, or up front retrieve your features in the correct spatial reference.
0 Kudos
JayKappy
Occasional Contributor
The Client API does not automatically do reprojection. You would have to call the GeometryService.Project method to reproject you features to the spatial reference of the map, prior to calling zoom, or up front retrieve your features in the correct spatial reference.


Again just using an ESRI API example and nothing mentioned about this....
So you are saying that by placing the selected feature in Graphics layer like the example is whats causing the problem?

This is my Map Grid...Spatial Reference 4326....Any hints on how to actually call the GeometryService.Project method to reproject my features?

THanks
0 Kudos
JayKappy
Occasional Contributor
I think I am close but getting a few errors.... this is what I have right now..
I highlighted the areas that are causign issues...maybe soemone can put their eyes on them...
OR tell me I am totally off base here...

Again I am gettign errors on the RED code below...
Error 3 Argument not specified for parameter 'sender' of 'Private Sub GeometryService_ProjectCompleted(sender As Object, args As ESRI.ArcGIS.Client.Tasks.GraphicsEventArgs)'. C:\Users\jkapalczynski\Documents\Visual Studio 2010\Projects\gislis2010_live\MainPage.xaml.vb 1388 45 gislis2010_live

Error 2 Argument not specified for parameter 'args' of 'Private Sub GeometryService_ProjectCompleted(sender As Object, args As ESRI.ArcGIS.Client.Tasks.GraphicsEventArgs)'. C:\Users\jkapalczynski\Documents\Visual Studio 2010\Projects\gislis2010_live\MainPage.xaml.vb 1388 45 gislis2010_live

Error 1 'Public Event ProjectCompleted(sender As Object, e As ESRI.ArcGIS.Client.Tasks.GraphicsEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event. C:\Users\jkapalczynski\Documents\Visual Studio 2010\Projects\gislis2010_live\MainPage.xaml.vb 1388 9 gislis2010_live

Error 4 'Public Event AreasAndLengthsCompleted(sender As Object, e As ESRI.ArcGIS.Client.Tasks.AreasAndLengthsEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event. C:\Users\jkapalczynski\Documents\Visual Studio 2010\Projects\gislis2010_live\MainPage.xaml.vb 1507 9 gislis2010_live

Error 5 'GeometryService_AreasAndLengthsCompleted' is not declared. It may be inaccessible due to its protection level. C:\Users\jkapalczynski\Documents\Visual Studio 2010\Projects\gislis2010_live\MainPage.xaml.vb 1507 53 gislis2010_live



    Private Sub QueryTask_ExecuteCompletedSearch(ByVal sender As Object, ByVal args As ESRI.ArcGIS.Client.Tasks.QueryEventArgs)
        Dim featureSet As FeatureSet = args.FeatureSet

        ' If initial query to populate states combobox       
            If (TryCast(args.UserState, String)) = "initial" Then
            ' Just show on initial load            
           QueryComboBox.Items.Add("Select...")

            For Each graphic As Graphic In args.FeatureSet.Features
                QueryComboBox.Items.Add(graphic.Attributes("PID").ToString())
            Next graphic

            QueryComboBox.SelectedIndex = 0
            Return
        End If

        ' Remove the first entry if "Select..."       
        If QueryComboBox.Items(0).ToString().Contains("Select...") Then
            QueryComboBox.Items.RemoveAt(0)
        End If

        ' If an item has been selected      

' THIS IS WHERE I AM TRYING TO CHANGE THE GEOMETRY CALLING THE   Private Sub GeometryService_ProjectCompleted            
        Dim geometryService As New GeometryService("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" & "Geometry/GeometryServer")
 geometryService.ProjectCompleted += GeometryService_ProjectCompleted()        
        Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayerSearch"), GraphicsLayer)
        geometryService.ProjectAsync(graphicsLayer.ToList(), New SpatialReference(4326))

        graphicsLayer.ClearGraphics()

        If featureSet IsNot Nothing AndAlso featureSet.Features.Count > 0 Then
            ' Show selected feature attributes in DataGrid
            Dim selectedFeature As Graphic = featureSet.Features(0)

            IdentifyDetailsDataGrid5.DataContext = selectedFeature.Attributes

            ' Hightlight selected feature            
            selectedFeature.Symbol = TryCast(LayoutRoot.Resources("ResultsFillSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
            graphicsLayer.Graphics.Add(selectedFeature)

            Dim selectedFeatureExtent As ESRI.ArcGIS.Client.Geometry.Envelope = selectedFeature.Geometry.Extent

            Dim expandPercentage As Double = 230

            Dim widthExpand As Double = selectedFeatureExtent.Width * (expandPercentage / 100)
            Dim heightExpand As Double = selectedFeatureExtent.Height * (expandPercentage / 100)

            Dim displayExtent As 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)


            If IdentifyResultsPanel5.Visibility = Visibility.Collapsed Then
                IdentifyResultsPanel5.Visibility = Visibility.Visible
                IdentifyGrid5.Height = Double.NaN
                IdentifyGrid5.UpdateLayout()
            End If

        Else
            IdentifyResultsPanel5.DataContext = Nothing
            IdentifyResultsPanel5.Visibility = Visibility.Collapsed
            IdentifyGrid5.Height = Double.NaN
            IdentifyGrid5.UpdateLayout()
        End If

    End Sub

Private Sub GeometryService_ProjectCompleted(ByVal sender As Object, ByVal args As ESRI.ArcGIS.Client.Tasks.GraphicsEventArgs)
        Dim geometryService As New GeometryService("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" & "Geometry/GeometryServer")
 geometryService.AreasAndLengthsCompleted += GeometryService_AreasAndLengthsCompleted  
geometryService.AreasAndLengthsAsync(args.Results)
    
End Sub



Trying to Reference This:

http://help.arcgis.com/en/webapi/silverlight/help/index.html#//01660000001v000000.htm
0 Kudos
JMcNeil
Occasional Contributor III
Jay


I have my app and have added a bunch of layers from ESRI


Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_ShadedRelief_World_2D/MapServer"/>
Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer"/>    
Url="http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer" />
Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/>       
Url="http://servicer.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_MedianIncome_US_2D/MapServer"/>


They draw great...adn then I added a bunch of my own layers on top of those. These are in a DIFFERENT projection that much I know. But they still display fine.




Here's a few problems that I see:  All your ESRI Services are Cached Tiled Services and when you have Tiled Cached services I think you need them all to be in the same projection.

This one: Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/>
IS 102100 NOT 4326 I don't think this one is going to draw and it probably causing problems

This one has a typo "servicer" so there is no way this is drawing
Url="http://servicer.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_MedianIncome_US_2D/MapServer"/>


This is my Map Grid...Spatial Reference 4326....


Not 100% sure but I believe your map grid spatial ref will be the first Tiled Cache Service drawn so.... maybe its not 4326 (if the 102100 is drawing first).
0 Kudos
JayKappy
Occasional Contributor
Here's a few problems that I see: All your ESRI Services are Cached Tiled Services and when you have Tiled Cached services I think you need them all to be in the same projection.

This one: Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/>
IS 102100 NOT 4326 I don't think this one is going to draw and it probably causing problems
THIS one Draws Fine
This one has a typo "servicer" so there is no way this is drawing
Url="http://servicer.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_MedianIncome_US_2D/MapServer"/>
THIS one Draws Fine
For some reason the "r" was added in this post....in my code it displays as
Url="http://service.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_MedianIncome_US_2D/MapServer"/>



All of my layers Draw fine. I see everyone one of them....my problem is on the zoom...it querys the layer fine, comes up with a record, writes the feature to the Graphics Layer, Zooms to it, makes it blue....ALTHOUGH the area it zooms to is nowhere to be found...cant even get back to the main map.
I am thinking that Graphics layer has to be projected to that of what ever the map is projected to...that I have NO IDEA...how to you determine that....is it determined by what layer is drawn first?

How do you determine what the Spatial Reference of youe map is?


Not 100% sure but I believe your map grid spatial ref will be the first Tiled Cache Service drawn so.... maybe its not 4326 (if the 102100 is drawing first).


Am I close with my last post...the one with the errors? I am trying to define the projection of the Graphics Layer but hitting a brick wall....

Thanks for all your thoughts and ideas....VERY VERY Apprecaited


I ATTACHED A WORD DOC.....Look at the XY min and max after the zoom to...this is what I am talking about....its zooming to I dont know where...
0 Kudos
JMcNeil
Occasional Contributor III
Jay,

Trust me they are cached/tiled services in different projections...Not Clean.  Drop 10200 the service
http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer.

In your screenshots your starting coords are coods similar to: -115.55 and 26
These coords look like Web Mecator 4326 - Check out the rest end point of http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer
Your see the extents are
Intial Extent:

XMin: -301.639333008995
YMin: -226.229499756746
XMax: 301.639333008995
YMax: 226.229499756746
Spatial Reference: 4326

Full Extent:

XMin: -179.99999
YMin: -89.99999
XMax: 179.99999
YMax: 89.99999
Spatial Reference: 4326



NOW Lookk at the Coords after your Zoom:  They are like 5641362.218 and -10407985.655 - these look like Web Mecartor 102100 coords
Now take a look at this endpoint http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer

Notice the extent are very similar:

Intial Extent:

XMin: -20037507.0671618
YMin: -22882589.2065154
XMax: 20037507.0671618
YMax: 22882589.2065155
Spatial Reference: 102100 (3857)

Full Extent:

XMin: -20037507.0671618
YMin: -19971868.8804086
XMax: 20037507.0671618
YMax: 19971868.8804086
Spatial Reference: 102100 (3857)



From my understanding there is no way you can project these two services at the same time and it is very bad practice to have 2 different projected cached services!

Just for humor drop the http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer
Rebuild and test.

J
0 Kudos
dotMorten_esri
Esri Notable Contributor
when you query these layers, just make sure you set the OutputSpatialReference on the query to be the same as Map.SpatialReference. That way you will always get features back in an SR that matches the map, and you won't have to mess with reprojecting the features again later.
0 Kudos
JayKappy
Occasional Contributor
when you query these layers, just make sure you set the OutputSpatialReference on the query to be the same as Map.SpatialReference. That way you will always get features back in an SR that matches the map, and you won't have to mess with reprojecting the features again later.


This is what I am trying to do...then being told I do not have to do that...VERY confused here.

1. HOW DO I DETERMINE THE MAP.SPATIAL REFERENCE
2. HOW DO YOU SET THE OutPut Spatial Reference of the Query

ALRIGHT I eliminated all layers but these: SO THERE SHOULD be no more proj issues RIGHT?
a. There is one ESRI Service (Proj 4326)
b. A Few of my Layers (Proj: Hennepin Countys own projection)
c. A Few Graphics Layers.

            <esri:Map x:Name="MyMap" MouseClick="QueryPoint_MouseClick" TimeExtent="{Binding ElementName=MyTimeSlider, Path=Value}">
                <esri:Map.Extent>
                    <esri:Envelope XMin="-90.99999" YMin="25.99999" XMax="-95.99999" YMax="50.99999" >
                        <esri:Envelope.SpatialReference>
                            <esri:SpatialReference WKID="4326"/>
                        </esri:Envelope.SpatialReference>
                    </esri:Envelope>
                </esri:Map.Extent>

                <esri:Map.Layers>

                    <esri:ArcGISDynamicMapServiceLayer ID="State,City,Highway" Opacity="0.6" 
                        Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer"/>

            <!-- MAPLE GROVE LAYERS-->
                    <esri:ArcGISDynamicMapServiceLayer ID="MG_Streets" Visible="False" 
                     Url="http://gis.org/arcgis/rest/services/MG_Test/MapServer"
                     Initialized="Streets_Initialized"/>
                    <esri:ArcGISDynamicMapServiceLayer ID="MG_Parcels" 
                     Url="http://gis.org/arcgis/rest/services/MG_Test_WGS84/MapServer"
                     Initialized="Parcels_Initialized"/>

                    <esri:GraphicsLayer ID="MyGraphicsLayerSearch" />                  
                    <esri:GraphicsLayer ID="MyLayer" />

                </esri:Map.Layers>
            </esri:Map>



If I try and zoom without any extra projection code I get sent way out into space....
The Attribute Query Example Here: I did not make any modifications to the code
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#AttributeQuery

======================================================================


To Try and correct the problem I am TRYING THIS EXAMPLE TO Set the Projection of the graphic features....I CANT FIGURE IT OUT.......

http://help.arcgis.com/en/webapi/sil...001v000000.htm

THIS IS WHAT I AM TRYING: When I add this code NOTHING HAPPENS

  Private Sub QueryTask_ExecuteCompletedSearch(ByVal sender As Object, ByVal args As ESRI.ArcGIS.Client.Tasks.QueryEventArgs)
        Dim featureSet As FeatureSet = args.FeatureSet

        ' If initial query to populate states combobox
        If (TryCast(args.UserState, String)) = "initial" Then
            ' Just show on initial load
            QueryComboBox.Items.Add("Select...")

            For Each graphic As Graphic In args.FeatureSet.Features
                QueryComboBox.Items.Add(graphic.Attributes("PID").ToString())
            Next graphic

            QueryComboBox.SelectedIndex = 0
            Return
        End If

        ' Remove the first entry if "Select..."
        If QueryComboBox.Items(0).ToString().Contains("Select...") Then
            QueryComboBox.Items.RemoveAt(0)
        End If

        ' If an item has been selected            
        Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayerSearch"), GraphicsLayer)

        Dim geometryService As New GeometryService("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" & "Geometry/GeometryServer")
        AddHandler geometryService.ProjectCompleted, AddressOf GeometryService_ProjectCompleted
        Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayerSearch"), GraphicsLayer)
        geometryService.ProjectAsync(graphicsLayer.ToList(), New SpatialReference(4326))
        graphicsLayer.ClearGraphics()

        If featureSet IsNot Nothing AndAlso featureSet.Features.Count > 0 Then
            ' Show selected feature attributes in DataGrid
            Dim selectedFeature As Graphic = featureSet.Features(0)

            IdentifyDetailsDataGrid5.DataContext = selectedFeature.Attributes

            ' Hightlight selected feature
            selectedFeature.Symbol = TryCast(LayoutRoot.Resources("ResultsFillSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
            graphicsLayer.Graphics.Add(selectedFeature)

            ' Zoom to selected feature (define expand percentage)
            Dim selectedFeatureExtent As ESRI.ArcGIS.Client.Geometry.Envelope = selectedFeature.Geometry.Extent
            Dim expandPercentage As Double = 230
            Dim widthExpand As Double = selectedFeatureExtent.Width * (expandPercentage / 100)
            Dim heightExpand As Double = selectedFeatureExtent.Height * (expandPercentage / 100)
            Dim displayExtent As 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)

    End Sub

    Private Sub GeometryService_ProjectCompleted(ByVal sender As Object, ByVal args As ESRI.ArcGIS.Client.Tasks.GraphicsEventArgs)
        Dim geometryService As New GeometryService("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" & "Geometry/GeometryServer")
        AddHandler geometryService.AreasAndLengthsCompleted, AddressOf GeometryService_AreasAndLengthsCompleted
        geometryService.AreasAndLengthsAsync(args.Results)
    End Sub

    Private Sub GeometryService_AreasAndLengthsCompleted(ByVal sender As Object, ByVal args As AreasAndLengthsEventArgs)
        Dim results As String = ""
        For i As Integer = 0 To args.Results.Areas.Count - 1
            results += String.Format("Graphic {0}: Area = {1}, Perimeter = {2}" & vbLf, i, args.Results.Areas(i), args.Results.Lengths(i))
        Next
    End Sub




I THEN eliminated all layers but mine...and tried the out of the box zoom with NO projection code and it sent me into nowhere again....I have no idea whats going on here...

This is my Layers Spatial Reference

Spatial Reference: PROJCS["HENNEPIN COUNTY",GEOGCS["GCS_User_Defined",DATUM["D_User_Defined",SPHEROID["User_Defined_Spheroid",6378418.941,298.2572242549207]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",100000.0],PARAMETER["Central_Meridian",-93.38333333333334],PARAMETER["Standard_Parallel_1",44.88333333333333],PARAMETER["Standard_Parallel_2",45.13333333333333],PARAMETER["Latitude_Of_Origin",44.79111111111111],UNIT["Foot_US",0.304800609601219]]

Single Fused Map Cache: false

Intial Extent:

XMin: 450364.358218924
YMin: 197838.607031511
XMax: 508478.276672829
YMax: 234433.822809259
Spatial Reference: PROJCS["HENNEPIN COUNTY",GEOGCS["GCS_User_Defined",DATUM["D_User_Defined",SPHEROID["User_Defined_Spheroid",6378418.941,298.2572242549207]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",100000.0],PARAMETER["Central_Meridian",-93.38333333333334],PARAMETER["Standard_Parallel_1",44.88333333333333],PARAMETER["Standard_Parallel_2",45.13333333333333],PARAMETER["Latitude_Of_Origin",44.79111111111111],UNIT["Foot_US",0.304800609601219]]

Full Extent:

XMin: 457057.270826343
YMin: 197381.565205937
XMax: 498385.319567721
YMax: 234726.316205273
Spatial Reference: PROJCS["HENNEPIN COUNTY",GEOGCS["GCS_User_Defined",DATUM["D_User_Defined",SPHEROID["User_Defined_Spheroid",6378418.941,298.2572242549207]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",100000.0],PARAMETER["Central_Meridian",-93.38333333333334],PARAMETER["Standard_Parallel_1",44.88333333333333],PARAMETER["Standard_Parallel_2",45.13333333333333],PARAMETER["Latitude_Of_Origin",44.79111111111111],UNIT["Foot_US",0.304800609601219]]

Units: esriFeet
0 Kudos
DominiqueBroux
Esri Frequent Contributor
You have just to initialize the spatialreference of your identify parameters to the spatial reference of your map.

Something like:
identifyParams.SpatialReference = MyMap.SpatialReference
0 Kudos