arcgis Server .net adf中的选择操作
2008-11-07 09:37
507 查看
之前在工具条中新建一个Tool,ClickAction选DrawRectangle,ServerActionAssembly填App_Code,ServerActionClass填SelectFeatures
using System;
using System.Data;
using System.Text;
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.Drawing;
using System.Collections;
using System.Collections.Generic;
using ESRI.ArcGIS;
using ESRI.ArcGIS.ADF.Web;
using ESRI.ArcGIS.ADF.Web.DataSources;
using ESRI.ArcGIS.ADF.Web.Display;
using ESRI.ArcGIS.ADF.Web.UI.WebControls;
using ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools;
/// <summary>
/// Select_Features 的摘要说明
/// </summary>
public class SelectFeatures :System.Web.UI.Page,IMapServerToolAction
{
public SelectFeatures()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#region IMapServerToolAction 成员
public void ServerAction(ToolEventArgs args)
{
Map mapctrl = (Map)args.Control;
string targetlayername = "高切坡";//(string)mapctrl.Page.Session["TargetLayer"];
// Cast ToolEventArgs to RectangleEventArgs
RectangleEventArgs rectargs = (RectangleEventArgs)args;
System.Drawing.Rectangle rect = rectargs.ScreenExtent;
ESRI.ArcGIS.ADF.Web.Geometry.Point minpnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(rect.Left,rect.Bottom,mapctrl.Extent,(int)mapctrl.Width.Value,(int)mapctrl.Height.Value);
ESRI.ArcGIS.ADF.Web.Geometry.Point maxpnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(rect.Right,rect.Top,mapctrl.Extent,(int)mapctrl.Width.Value,(int)mapctrl.Height.Value);
//Create a new Envelope
ESRI.ArcGIS.ADF.Web.Geometry.Envelope mappoly = new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(minpnt,maxpnt);
IMapFunctionality mf = mapctrl.GetFunctionality(Session["resourceName"].ToString()) as IMapFunctionality;
IGISResource gisresource = mf.Resource;
//Call CreateFunctionality on the gisresource
IQueryFunctionality qfunc = (IQueryFunctionality)gisresource.CreateFunctionality(typeof(IQueryFunctionality),null);
string[] lids;
string[] lnames;
qfunc.GetQueryableLayers(null,out lids,out lnames);
int layer_index = 0;
for (int i = 0; i < lnames.Length; i++)
{
if (lnames[i] == targetlayername)
{
layer_index = i;
break;
}
}
//Create a new spatialfilter
ESRI.ArcGIS.ADF.Web.SpatialFilter spatialfilter = new SpatialFilter();
spatialfilter.MaxRecords = 1000;
spatialfilter.ReturnADFGeometries = true;
spatialfilter.Geometry = mappoly;
String[] flds = qfunc.GetFields(null,lids[layer_index]);
ESRI.ArcGIS.ADF.StringCollection scoll = new ESRI.ArcGIS.ADF.StringCollection(flds);
spatialfilter.SubFields = scoll;
//Initialize the datatable (Call Query on QueryFunctionality)
System.Data.DataTable datatable = null;
datatable = qfunc.Query(null,lids[layer_index],spatialfilter);
IEnumerable gfc = mapctrl.GetFunctionalities();
ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource gResource = null;
foreach (IGISFunctionality gfunc in gfc)
{
if (gfunc.Resource.Name == "Selection")
{
gResource = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource)gfunc.Resource;
}
}
if (gResource == null)
return;
ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer glayer = null;
foreach (System.Data.DataTable dt in gResource.Graphics.Tables)
{
if (dt is ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)
{
glayer = (ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)dt;
break;
}
}
if (glayer == null)
{
glayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();
gResource.Graphics.Tables.Add(glayer);
}
glayer.Clear();
DataRowCollection drs = datatable.Rows;
int shpind = -1;
if (Session["shapeid"] == null)
{
for (int i = 0; i < datatable.Columns.Count; i++)
{
if (datatable.Columns[i].DataType == typeof(ESRI.ArcGIS.ADF.Web.Geometry.Geometry))
{
shpind = i;
Session["shapeid"] = i;
break;
}
}
}
else
shpind = Convert.ToInt16(Session["shapeid"]);
if (Session["gqpbhcolum"] == null)
{
for (int i = 0; i < datatable.Columns.Count; i++)
{
if (datatable.Columns[i].ColumnName.Contains("高切坡编号"))
{
Session["gqpbhcolum"] = datatable.Columns[i].ColumnName;
break;
}
}
}
StringBuilder strb = new StringBuilder();
try
{
foreach (DataRow dr in drs)
{
ESRI.ArcGIS.ADF.Web.Geometry.Geometry geom = (ESRI.ArcGIS.ADF.Web.Geometry.Geometry)dr[shpind];
ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement ge = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(geom,System.Drawing.Color.Yellow);
ge.Symbol.Transparency = 50.0;
strb.Append(dr[Session["gqpbhcolum"].ToString()] + "&");
glayer.Add(ge);
}
}
catch (InvalidCastException ice)
{
throw new Exception("未选中");
}
if (mapctrl.ImageBlendingMode == ImageBlendingMode.WebTier)
{ mapctrl.Refresh(); }
else if (mapctrl.ImageBlendingMode == ImageBlendingMode.Browser)
{ mapctrl.RefreshResource(gResource.Name); }
if (strb.Length > 0)
Session["index"] = strb.Remove(strb.Length - 1,1);
else
Session["index"] = null;
}
#endregion
}
using System;
using System.Data;
using System.Text;
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.Drawing;
using System.Collections;
using System.Collections.Generic;
using ESRI.ArcGIS;
using ESRI.ArcGIS.ADF.Web;
using ESRI.ArcGIS.ADF.Web.DataSources;
using ESRI.ArcGIS.ADF.Web.Display;
using ESRI.ArcGIS.ADF.Web.UI.WebControls;
using ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools;
/// <summary>
/// Select_Features 的摘要说明
/// </summary>
public class SelectFeatures :System.Web.UI.Page,IMapServerToolAction
{
public SelectFeatures()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#region IMapServerToolAction 成员
public void ServerAction(ToolEventArgs args)
{
Map mapctrl = (Map)args.Control;
string targetlayername = "高切坡";//(string)mapctrl.Page.Session["TargetLayer"];
// Cast ToolEventArgs to RectangleEventArgs
RectangleEventArgs rectargs = (RectangleEventArgs)args;
System.Drawing.Rectangle rect = rectargs.ScreenExtent;
ESRI.ArcGIS.ADF.Web.Geometry.Point minpnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(rect.Left,rect.Bottom,mapctrl.Extent,(int)mapctrl.Width.Value,(int)mapctrl.Height.Value);
ESRI.ArcGIS.ADF.Web.Geometry.Point maxpnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(rect.Right,rect.Top,mapctrl.Extent,(int)mapctrl.Width.Value,(int)mapctrl.Height.Value);
//Create a new Envelope
ESRI.ArcGIS.ADF.Web.Geometry.Envelope mappoly = new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(minpnt,maxpnt);
IMapFunctionality mf = mapctrl.GetFunctionality(Session["resourceName"].ToString()) as IMapFunctionality;
IGISResource gisresource = mf.Resource;
//Call CreateFunctionality on the gisresource
IQueryFunctionality qfunc = (IQueryFunctionality)gisresource.CreateFunctionality(typeof(IQueryFunctionality),null);
string[] lids;
string[] lnames;
qfunc.GetQueryableLayers(null,out lids,out lnames);
int layer_index = 0;
for (int i = 0; i < lnames.Length; i++)
{
if (lnames[i] == targetlayername)
{
layer_index = i;
break;
}
}
//Create a new spatialfilter
ESRI.ArcGIS.ADF.Web.SpatialFilter spatialfilter = new SpatialFilter();
spatialfilter.MaxRecords = 1000;
spatialfilter.ReturnADFGeometries = true;
spatialfilter.Geometry = mappoly;
String[] flds = qfunc.GetFields(null,lids[layer_index]);
ESRI.ArcGIS.ADF.StringCollection scoll = new ESRI.ArcGIS.ADF.StringCollection(flds);
spatialfilter.SubFields = scoll;
//Initialize the datatable (Call Query on QueryFunctionality)
System.Data.DataTable datatable = null;
datatable = qfunc.Query(null,lids[layer_index],spatialfilter);
IEnumerable gfc = mapctrl.GetFunctionalities();
ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource gResource = null;
foreach (IGISFunctionality gfunc in gfc)
{
if (gfunc.Resource.Name == "Selection")
{
gResource = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource)gfunc.Resource;
}
}
if (gResource == null)
return;
ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer glayer = null;
foreach (System.Data.DataTable dt in gResource.Graphics.Tables)
{
if (dt is ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)
{
glayer = (ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer)dt;
break;
}
}
if (glayer == null)
{
glayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();
gResource.Graphics.Tables.Add(glayer);
}
glayer.Clear();
DataRowCollection drs = datatable.Rows;
int shpind = -1;
if (Session["shapeid"] == null)
{
for (int i = 0; i < datatable.Columns.Count; i++)
{
if (datatable.Columns[i].DataType == typeof(ESRI.ArcGIS.ADF.Web.Geometry.Geometry))
{
shpind = i;
Session["shapeid"] = i;
break;
}
}
}
else
shpind = Convert.ToInt16(Session["shapeid"]);
if (Session["gqpbhcolum"] == null)
{
for (int i = 0; i < datatable.Columns.Count; i++)
{
if (datatable.Columns[i].ColumnName.Contains("高切坡编号"))
{
Session["gqpbhcolum"] = datatable.Columns[i].ColumnName;
break;
}
}
}
StringBuilder strb = new StringBuilder();
try
{
foreach (DataRow dr in drs)
{
ESRI.ArcGIS.ADF.Web.Geometry.Geometry geom = (ESRI.ArcGIS.ADF.Web.Geometry.Geometry)dr[shpind];
ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement ge = new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(geom,System.Drawing.Color.Yellow);
ge.Symbol.Transparency = 50.0;
strb.Append(dr[Session["gqpbhcolum"].ToString()] + "&");
glayer.Add(ge);
}
}
catch (InvalidCastException ice)
{
throw new Exception("未选中");
}
if (mapctrl.ImageBlendingMode == ImageBlendingMode.WebTier)
{ mapctrl.Refresh(); }
else if (mapctrl.ImageBlendingMode == ImageBlendingMode.Browser)
{ mapctrl.RefreshResource(gResource.Name); }
if (strb.Length > 0)
Session["index"] = strb.Remove(strb.Length - 1,1);
else
Session["index"] = null;
}
#endregion
}
相关文章推荐
- (转)ArcGIS Server .NET ADF中的AJAX之深入浅出/CallbackResult详解
- ArcGIS Server .Net Web ADF体系结构
- ArcGIS Server .Net Web ADF体系结构(转)
- Esri中国社区 » GIS大讲堂:ArcGIS Server .Net ADF中的AJAX
- ArcGIS Server .Net ADF中的AJAX
- Arcgis Server .NET ADF 异步刷新方法(非ADF控件)
- ArcGIS Server .Net Web ADF体系结构
- ArcGIS Server .Net Web ADF体系结构
- ArcGIS Server .Net Web ADF体系结构
- ArcGIS Server .Net Web ADF体系结构
- ArcGIS Server .Net Web ADF的类库简介(转载)
- ArcGIS Server .NET ADF中的AJAX之深入浅出/CallbackResult详解
- ArcGIS.Server.9.2.DotNet实现类似GoogleMap的操作工具条(ADF的Toolbar太丑)
- ArcGIS Server .Net Web ADF的类库简介
- ArcGIS Server .Net Web ADF之几何类型的相互转换(转)
- ArcGIS Server .Net ADF中的编辑功能(一)
- ArcGIS Server .Net Web ADF体系结构
- ArcGIS Server .Net Web ADF之几何类型的相互转换
- ArcGIS Server ADF for .net 参数错误
- ArcGIS Server ADF for .net 参数错误