using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ESRI.ArcGIS.ADF.Web;
using ESRI.ArcGIS.ADF.Web.Geometry;
using ESRI.ArcGIS.ADF.Web.DataSources;
using ESRI.ArcGIS.ADF.Web.UI.WebControls;
using ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools;
/// <summary>
///IdentifyHelper 的摘要说明
/// </summary>
public class IdentifyHelper
{
public IdentifyHelper()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
public static void ShowIdentifyResult(Map map, DataTableCollection dtc)
{
string returnstring = string.Empty;
foreach (DataTable dt in dtc)
{
if (dt.Rows.Count == 0)
continue;
returnstring += GetHtmlFromDataTable(dt);
}
returnstring = returnstring.Replace("\r\n","");
returnstring = returnstring.Replace("\n","");
string functionValue="var theForm=doucumnet.forms[0];";
functionValue += "theForm.FunctionValue.Value='"+returnstring+"';";
functionValue += "open('IdentifyResult.htm','IdentifyResult');";
AddJavaScriptCallback(map, functionValue);
}
public static string GetHtmlFromDataTable(DataTable dt)
{
GridView gd = new GridView();
gd.ToolTip = dt.TableName;
gd.Caption = dt.TableName;
gd.DataSource = dt;
gd.DataBind();
gd.Visible = true;
gd.BorderWidth = 0;
gd.CssClass = "list-line";
gd.CellPadding = 3;
gd.CellSpacing = 1;
gd.HeaderStyle.CssClass = "barbg";
gd.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
gd.RowStyle.CssClass = "listbg";
string returnString = string.Empty;
using (System.IO.StringWriter sw = new System.IO.StringWriter())
{
HtmlTextWriter htw = new HtmlTextWriter(sw);
gd.RenderControl(htw);
htw.Flush();
string tempStr=sw.ToString();
returnString+=tempStr;
}
return returnString;
}
public static void AddJavaScriptCallback(Map map,string executeString)
{
object[] oa = new object[1];
oa[0] = executeString;
CallbackResult cr = new CallbackResult(null, null, "javascript", oa);
map.CallbackResults.Add(cr);
}
}
————————————————————————————————————————————————
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ESRI.ArcGIS.ADF.Web;
using ESRI.ArcGIS.ADF.Web.Geometry;
using ESRI.ArcGIS.ADF.Web.DataSources;
using ESRI.ArcGIS.ADF.Web.UI.WebControls;
using ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools;
/// <summary>
///IdentityPoint 的摘要说明
/// </summary>
public class IdentityPoint:IMapServerToolAction
{
public IdentityPoint()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
#region IMapServerToolAction 成员
void IMapServerToolAction.ServerAction(ToolEventArgs args)
{
Map map = args.Control as Map;
PointEventArgs point = args as PointEventArgs;
System.Drawing.Point screen_point = point.ScreenPoint;
Point pt = Point.ToMapPoint(screen_point.X, screen_point.Y, map.Extent, (int)map.Width.Value, (int)map.Height.Value);
IGISFunctionality gisfunc = map.GetFunctionality("province");
if (gisfunc == null)
return;
IGISResource gisresource = gisfunc.Resource;
bool supportquery = gisresource.SupportsFunctionality(typeof(IQueryFunctionality));
if (!supportquery)
return;
IQueryFunctionality qfunc;
qfunc = gisresource.CreateFunctionality(typeof(IQueryFunctionality), null) as IQueryFunctionality;
System.Data.DataTable[] qdatatable = qfunc.Identify(null, pt, 1, IdentifyOption.AllLayers, null);
if (qdatatable != null)
return;
System.Data.DataSet dataset= new System.Data.DataSet();
for (int i = 0; i < qdatatable.Length; i++)
dataset.Tables.Add(qdatatable[i]);
DataTableCollection dtc = dataset.Tables;
IdentifyHelper.ShowIdentifyResult(map,dtc);
}
#endregion
}