62,254
社区成员
发帖
与我相关
我的任务
分享using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using ESRI.ArcGIS.ADF.ArcGISServer;
using ESRI.ArcGIS.ADF.Web.DataSources;
using ESRI.ArcGIS.ADF.Web.UI.WebControls;
using ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer;
/// <summary>
/// Summary description for IdentifyHelper
/// </summary>
public class IdentifyHelper
{
public IdentifyHelper()
{
//
// TODO: Add constructor logic here
//
}
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);
}
public static string GetHtmlFromDataTable(DataTable dt)
{
DetailsView dv = new DetailsView();
dv.ToolTip = dt.TableName;
dv.Caption = dt.TableName;
dv.DataSource = dt;
dv.DataBind();
dv.Visible = true;
dv.BorderWidth = 0;
dv.CssClass = "list-line";
dv.CellPadding = 3;
dv.CellSpacing = 1;
dv.HeaderStyle.CssClass = "barbg";
dv.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
dv.RowStyle.CssClass = "listbg";
/* LinkButton lb = new LinkButton();
lb.Text = dv.Rows[0].Cells[1].Text;
lb.OnClientClick = "open('www.baidu.com','name');";
*/
string returnString = string.Empty;
using (System.IO.StringWriter sw = new System.IO.StringWriter())
{
HtmlTextWriter htw = new HtmlTextWriter(sw);
dv.RenderControl(htw);
htw.Flush();
string tempStr = sw.ToString();
returnString += tempStr;
}
return returnString;
}
public static int GeometryFieldIndex(DataTable datatable)
{
int geoIndex = -1;
for (int i = 0; i < datatable.Columns.Count; i++)
{
if (datatable.Columns[i].DataType == typeof(ESRI.ArcGIS.ADF.Web.Geometry.Geometry))
{
// 找到Geometry字段的序号
geoIndex = i;
break;
}
}
return geoIndex;
}
public static void CopyCustomGraphics(GraphicElement[] ges, MapDescription mapDescription)
{
if (mapDescription.CustomGraphics != null)
{
for (int i = 0; i < mapDescription.CustomGraphics.Length; i++)
ges[i] = mapDescription.CustomGraphics[i];
}
}
public static SimpleFillSymbol CreateSimpleFillSymbol()
{
ESRI.ArcGIS.ADF.ArcGISServer.RgbColor rgb;
rgb = new ESRI.ArcGIS.ADF.ArcGISServer.RgbColor();
rgb.Red = 255;
rgb.Green = 0;
rgb.Blue = 0;
rgb.AlphaValue = 255;
SimpleLineSymbol lineSym = new SimpleLineSymbol();
lineSym.Color = rgb;
lineSym.Width = 1.0;
lineSym.Style = esriSimpleLineStyle.esriSLSSolid;
SimpleFillSymbol sfs;
sfs = new SimpleFillSymbol();
sfs.Style = esriSimpleFillStyle.esriSFSForwardDiagonal;
sfs.Color = rgb;
sfs.Outline = lineSym;
return sfs;
}
public static void HighLightShow(Map map, DataTableCollection dtc)
{
MapFunctionality mf = (MapFunctionality)map.GetFunctionality("Map");
MapDescription mapDescription = mf.MapDescription;
mapDescription.CustomGraphics = null;
SimpleFillSymbol sfs = CreateSimpleFillSymbol();
foreach(DataTable dt in dtc)
{
if (dt.Rows.Count == 0)
continue;
HighLightPolygon(mapDescription, dt, sfs);
}
RefreshMap(map, "Map");
}
public static void HighLightPolygon(MapDescription mapDescription, DataTable datatable, SimpleFillSymbol sfs)
{
int hasCount = 0;
if (mapDescription.CustomGraphics != null)
hasCount = mapDescription.CustomGraphics.Length;
ESRI.ArcGIS.ADF.ArcGISServer.GraphicElement[] ges;
ges = new GraphicElement[hasCount + datatable.Rows.Count];
CopyCustomGraphics(ges, mapDescription);
int geoIndex = GeometryFieldIndex(datatable);
for (int i = 0; i < datatable.Rows.Count; i++)
{
ESRI.ArcGIS.ADF.Web.Geometry.Polygon polygon = datatable.Rows[i][geoIndex] as ESRI.ArcGIS.ADF.Web.Geometry.Polygon;
PolygonN ags_map_polyn;
ags_map_polyn = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.FromAdfPolygon(polygon);
PolygonElement polyelement;
polyelement = new PolygonElement();
polyelement.Symbol = sfs;
polyelement.Polygon = ags_map_polyn;
ges[hasCount + i] = polyelement;
}
mapDescription.CustomGraphics = ges;
}
public static void RefreshMap(Map map, string resourceName)
{
if (map.ImageBlendingMode == ImageBlendingMode.WebTier)
{
map.Refresh();
}
else if (map.ImageBlendingMode == ImageBlendingMode.Browser)
{
map.RefreshResource(resourceName);
}
}
public static void ShowIdentifyResult(Map map, DataTableCollection dtc)
{
string returnstring = string.Empty;
int i;
string str ="";
int count = dtc[0].Rows.Count;
string[] arry;
DataTable dTable = dtc[0];
GridView gView = new GridView();
gView.DataSource = dTable;
gView.DataBind();
if (count != 0)
{
arry = new string[count];
string url="";
for (i = 0; i < count; i++)
{
arry[i] = gView.Rows[i].Cells[0].Text;
str += arry[i]+" ,";
// DataTable dt = DbConnetion("3"); //替换成下面的语句
DataTable dt = DbConnetion(arry[i]);
returnstring += GetHtmlFromDataTable(dt);
url = "IdentifyResult.htm?id=" + arry[i].ToString();
}
HighLightShow(map, dtc);
returnstring = returnstring.Replace("\r\n", "");
returnstring = returnstring.Replace("\n", "");
string functionValue = "var theForm = document.forms[0];";
functionValue += "theForm.FunctionValue.Value='" + returnstring + "';";
// functionValue += "theForm.FunctionValue.Value='" + str + "';";
functionValue += "open('"+url+"','IdentifyResult','height=400,width=200,toolbar=no,location=no,menubar=no,scrollbars=yes,status=no');";
// functionValue += "open('IdentifyResult.htm','IdentifyResult','height=450,width=150,toolbar=no,location=no,menubar=no,scrollbar=yes,status=no');";
AddJavaScriptCallback(map, functionValue);
}
}
//查询用到的方法 为 Identify ,DbConnetion两个
public static void Identify(Map map, ESRI.ArcGIS.ADF.Web.Geometry.Geometry mapGeometry)
{
IGISFunctionality gisfunc = map.GetFunctionality("Map");
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;
string[] lIDs, lNames;
qfunc.GetQueryableLayers(null, out lIDs, out lNames);
ESRI.ArcGIS.ADF.Web.SpatialFilter spatialfilter = new ESRI.ArcGIS.ADF.Web.SpatialFilter();
spatialfilter.ReturnADFGeometries = false;
spatialfilter.MaxRecords = 1000;
spatialfilter.Geometry = mapGeometry;
System.Data.DataSet dataset = new System.Data.DataSet();
for (int i = 0; i < lIDs.Length; i++)
{
System.Data.DataTable datatable = qfunc.Query(null, lIDs[i], spatialfilter);
if (datatable == null)
continue;
if (datatable.Rows.Count == 0)
continue;
datatable.TableName = lNames[i];
dataset.Tables.Add(datatable);
}
DataTableCollection dtc = dataset.Tables;
if(dataset.Tables.Count !=0)
ShowIdentifyResult(map, dtc);
}
public static DataTable DbConnetion(string id)
{
string strCon = ConfigurationManager.ConnectionStrings["DV_SBGLConnectionString"].ConnectionString.ToString();
SqlConnection conn = new SqlConnection(strCon);
SqlCommand comm = new SqlCommand();
comm.CommandText = "select * from View_DevPole where 设备编号=" + id.ToString();
comm.Connection = conn ;
DataTable db = new DataTable();
SqlDataReader dr = null ;
conn.Open();
dr = comm.ExecuteReader();
db.Load(dr);
conn.Close();
return db;
}
}
protected override void OnLoadComplete(EventArgs e)
{
if (!IsPostBack)
{
//你的代码
}
}