Solved! Go to Solution.
.... some other code above sets MyMap, GLayer is a graphics layer on MyMap and gets the URL for a geometry service.... if (MyMap.SpatialReference.WKID != 4326) { GeometryService gserv = new GeometryService(Application.Current.Resources["GeometryURL"].ToString()); gserv.ProjectCompleted += gserv_ProjectCompleted; gserv.ProjectAsync(GLayer.Graphics, MyMap.SpatialReference, GLayer); } } void gserv_ProjectCompleted(object sender, GraphicsEventArgs e) { //update rss layer with graphics reprojected to match the map GraphicsLayer GLayer = MyMap.Layers[(e.UserState as Layer).ID] as GraphicsLayer; for (int i = 0; i < GLayer.Graphics.Count(); i++) { GLayer.Graphics.Geometry = e.Results.Geometry; } }
.... some other code above sets MyMap, GLayer is a graphics layer on MyMap and gets the URL for a geometry service.... if (MyMap.SpatialReference.WKID != 4326) { GeometryService gserv = new GeometryService(Application.Current.Resources["GeometryURL"].ToString()); gserv.ProjectCompleted += gserv_ProjectCompleted; gserv.ProjectAsync(GLayer.Graphics, MyMap.SpatialReference, GLayer); } } void gserv_ProjectCompleted(object sender, GraphicsEventArgs e) { //update rss layer with graphics reprojected to match the map GraphicsLayer GLayer = MyMap.Layers[(e.UserState as Layer).ID] as GraphicsLayer; for (int i = 0; i < GLayer.Graphics.Count(); i++) { GLayer.Graphics.Geometry = e.Results.Geometry; } }
Try using the method overload that allows you to pass in the 3rd 'user token' parameter & pass the graphics layer as that object. In the handler for your ProjectCompleted event cast that back to a layer and apply the projected geometry to the graphics. Code below isn't tested & off the top of my head, but might help -
.... some other code above sets MyMap, GLayer is a graphics layer on MyMap and gets the URL for a geometry service.... if (MyMap.SpatialReference.WKID != 4326) { GeometryService gserv = new GeometryService(Application.Current.Resources["GeometryURL"].ToString()); gserv.ProjectCompleted += gserv_ProjectCompleted; gserv.ProjectAsync(GLayer.Graphics, MyMap.SpatialReference, GLayer); } } void gserv_ProjectCompleted(object sender, GraphicsEventArgs e) { //update rss layer with graphics reprojected to match the map GraphicsLayer GLayer = MyMap.Layers[(e.UserState as Layer).ID] as GraphicsLayer; for (int i = 0; i < GLayer.Graphics.Count(); i++) { GLayer.Graphics.Geometry = e.Results.Geometry; } }
Might want to test and make sure the order is maintained by checking an attribute that would easily identify if it's the correct graphic (e.g. name = 'New York' is not showing up in Texas...)
QueryTask qt = new QueryTask(uriQuery); ESRI.ArcGIS.Client.Tasks.Query qry = new ESRI.ArcGIS.Client.Tasks.Query(); qry.ReturnGeometry = true; qry.Where = strWhere; qry.OutSpatialReference = MyMap.SpatialReference;
Do you have the outSpatialReference on the Query the QueryTask is executing set to match your map? That wy the results from the query task shouldn't need reprojected at all.
e.g.QueryTask qt = new QueryTask(uriQuery); ESRI.ArcGIS.Client.Tasks.Query qry = new ESRI.ArcGIS.Client.Tasks.Query(); qry.ReturnGeometry = true; qry.Where = strWhere; qry.OutSpatialReference = MyMap.SpatialReference;
Re: the error on the null reference - my code sets a URL as an Application level resource, try replacing it with a hard coded URL to your geometry service.
SELECT TOP (100) PERCENT State + '-' + RIGHT('00000' + CONVERT(VARCHAR, FacilityID), 4) AS ID, FacilityName, FacilityType, lat, long, Address1, Address2, City, State, Zip, geography::STGeomFromText('POINT(' + STR(long, 25, 10) + ' ' + STR(lat, 25, 10) + ')', 4326) AS geog FROM dbo.uvFacilityAddress WHERE (isActive = 1)