Skip to main content

Microsoft Silverlight

Callback Function TroubleRSS Feed

(0)

surrounded
surrounded

Member

Member

15 points

47 Posts

Callback Function Trouble

I have a function called from Page() in Page.xaml.cs which contains a foreach loop. 

The loop calls a web service and retrieves coordinate geometry from user specified polygons.  This is done through a callback function. 

MY PROBLEM:

The callback function successfully retrieves the coordinate geometry for the first polygon, however all subsequent loops through the callback function contain the same coordinate geometry.  So if I loop through the callback function four times, only the geometry from polygon 1 is correctly accessed.  The remaining three coordinate geometries are the same as the first geometry.  If I run the callback on each polygon separately, the corresponding geometry is correctly returned for each polygon.  NOTE: for my purposes, the program needs dynamic geometry retrieval.

Suggestions for solving this.......thanks.

Skyrunner
Skyrunner

Contributor

Contributor

2489 points

485 Posts

Silverlight MVP

Re: Callback Function Trouble

Without some code it's hard to see your problem.

Can you post some please.

duefectu
duefectu

Participant

Participant

786 points

238 Posts

Re: Callback Function Trouble

There are several possible problems, and I don't understand the problem.

Do you have problems with a xaml created polygons?

WCF provided polygons?

Code behind created polygons?

Maybe a Thread problem?

Can you explain a litle more?

Un saludo!
Juan Segura

Plase, "Mark as Answer..." if it solve the problem!

surrounded
surrounded

Member

Member

15 points

47 Posts

Re: Callback Function Trouble

From Page() in Page.xaml.cs, I call a web service to tell me the geometry type of a shapefile (ESRI format).  The geometry type is returned as a string.  Then I make a call to another web service to return coordinate geometry.  To get the coordinate geometry from the shapefile, I use FDO (Feature Data Object - OSGeo).  The coordinates are returned to the calling program in string[] format.  The geometries (polygons) are added to a virtual earth map.

pCoords (returned coordinate geometry) in CompletePoly always contains the first geometry.

CODE BELOW:

//*****************THIS FUNCTION IS CALLED FROM Page() in Page.xaml.cs 

public void drawLayersOnMap()

{

//LOAD XML FILE CONTAINING LAYER INFORMATION

List<DeepEarthPrototype.ControllerFunctions.GISLayer> layerlist = pCFunctions.readXMLFile("Data/LayerInfo.xml");

//CREATE SHAPELAYER FOR EACH GIS LAYER AND ADD TO MAP

foreach (DeepEarthPrototype.ControllerFunctions.GISLayer s in layerlist.ToArray())

{

shapeLayer =
new ShapeLayer { ID = s.mapID };shapeLayer.IsVisible = true;

map.Layers.Add(shapeLayer);

}

//ADD FEATURES TO THE SHAPELAYERS

foreach (DeepEarthPrototype.ControllerFunctions.GISLayer s in layerlist.ToArray())

{

shapeLayer = getShapelayer(s.mapID);

SessionManager.Session["SHPFILEPATH"] = s.filename;

SessionManager.Session["MAPID"] = s.mapID;

getGeometryOfLayer((string)SessionManager.Session["SHPFILEPATH"]);

}

 

 

public void getGeometryOfLayer(List<DeepEarthPrototype.ControllerFunctions.GISLayer> layerlist)

{

//CALL ASP.NET WEB SERVICE TO READ SHAPEFILE COORDINATES

GISFunctions.Service1SoapClient asmx = new GISFunctions.Service1SoapClient(bind, endpoint);

asmx.SHP_LayerGeometryTypeCompleted += new System.EventHandler<DeepEarthPrototype.GISFunctions.SHP_LayerGeometryTypeCompletedEventArgs>(returnGeometry);

asmx.SHP_LayerGeometryTypeAsync((string)SessionManager.Session["SHPFILEPATH"]);

}

 

//***************THIS RETURNS THE GEOMETRY TYPE AS A STRING

void returnGeometry(object sender, GISFunctions.SHP_LayerGeometryTypeCompletedEventArgs e)

{

//AN STRING ARRAY IS RETURNED; EACH RECORD CONTAINS THE X AND Y COORDINATES FOR FEATURE SEPARATED BY :

string geometryType = (string)e.Result;

//************THIS MAKES ANOTHER CALL TO ANOTHER WEB SERVICE TO GET COORDINATE GEOMETRY

DrawShape(geometryType);

}

 

//***********GET COORDINATE GEOMETRY 

public void DrawShape(string shapeType)

{

//CALL ASP.NET WEB SERVICE TO READ SHAPEFILE COORDINATES

GISFunctions.Service1SoapClient asmx = new GISFunctions.Service1SoapClient(bind, endpoint);if (shapeType.ToUpper().CompareTo("GEOMETRYTYPE_POLYGON") == 0)

{

asmx.SHP_ReturnGeometryCompleted += new System.EventHandler<DeepEarthPrototype.GISFunctions.SHP_ReturnGeometryCompletedEventArgs>(CompletePoly);

asmx.SHP_ReturnGeometryAsync((string)SessionManager.Session["SHPFILEPATH"]);

}

else if (shapeType.ToUpper().CompareTo("GEOMETRYTYPE_POINT") == 0)

{

asmx.SHP_ReturnGeometryCompleted +=
new System.EventHandler<DeepEarthPrototype.GISFunctions.SHP_ReturnGeometryCompletedEventArgs>(CompletePoint);asmx.SHP_ReturnGeometryAsync(@"C:\Data\VELayers\D3Access_Subset.shp");

}

}

 

void CompletePoly(object sender, GISFunctions.SHP_ReturnGeometryCompletedEventArgs e)

{

//AN STRING ARRAY IS RETURNED; EACH RECORD CONTAINS THE X AND Y COORDINATES FOR FEATURE SEPARATED BY :

DeepEarthPrototype.GISFunctions.ArrayOfString pCoords = (DeepEarthPrototype.GISFunctions.ArrayOfString)e.Result;

//pGeometryList.Add(pCoords);

System.Collections.Generic.List<Point> sArray = ConvertToPts(pCoords);

//ADD THE POLYGON LAYER TO THE MAP

PolygonShape polygon = new PolygonShape { Points = sArray };

shapeLayer.List.Add(polygon);

shapeLayer.IsVisible =
true;

 

////HARDCODED A TEST POLYGON

//List<Point> points = new List<Point> { new Point(-114.1576, 45.0711), new Point(-116.1576, 44.0711), new Point(-113.1576, 43.0711), new Point(-114.1576, 45.0711) };

//PolygonShape polygon = new PolygonShape { Points = points };

//shapeLayer.List.Add(polygon);

}

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities