其中index为当前要素在查询结果集(dataset或者datatable)中的索引号
/// <param name="index">要素索引号</param>
public void FeatureLocation(int index)
{
DataSet ds = Session["Gridview1"] as DataSet; //Session["Gridview1"] 为查询结果集
DataTable pDT = ds.Tables[0];
if (pDT.Rows.Count < 1) return;
try
{
ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicsLayer pGraLyr = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToGraphicsLayer(pDT);
ESRI.ArcGIS.ADF.Web.Geometry.Geometry pGeo = pGraLyr.GeometryFromRow(pGraLyr.Rows[index]);
ESRI.ArcGIS.ADF.Web.Geometry.Envelope Penv = new ESRI.ArcGIS.ADF.Web.Geometry.Envelope();
if (pGeo is ESRI.ArcGIS.ADF.Web.Geometry.Point)
{
ESRI.ArcGIS.ADF.Web.Geometry.Point pPT = (ESRI.ArcGIS.ADF.Web.Geometry.Point)pGeo;
Penv.XMin = pPT.X - 0.00001;
Penv.XMax = pPT.X + 0.00001;
Penv.YMin = pPT.Y - 0.00001;
Penv.YMax = pPT.Y + 0.00001;
}
else if (pGeo is ESRI.ArcGIS.ADF.Web.Geometry.Polyline)
{
ESRI.ArcGIS.ADF.Web.Geometry.Polyline pLY = (ESRI.ArcGIS.ADF.Web.Geometry.Polyline)pGeo;
Penv = ESRI.ArcGIS.ADF.Web.Geometry.Geometry.GetMinimumEnclosingEnvelope(pLY);
} //另外面的处理情况与线类似
Penv = Penv.Expand(2);
CustomFunction.Location.ClearTempElementInMap("TempEle", Map1);//此函数为清除定位标记
Map1.Extent = Penv;
CustomFunction.Location.AddTempGraphicElement(pGeo, false, "", false, System.Drawing.Color.Red, 40, Map1);//此函数为添加定位标记
Map1.CallbackResults.CopyFrom(Toolbar1.CallbackResults);
smapstring = Map1.CallbackResults.ToString();
pDT.Dispose();
}
catch (Exception ex)
{
SystemLog.WriteLog("当前记录定位错误!", ex);
}
}