ArcGIS Server 9.2 中的属性查询
该例子可动态设置图层,调整查询要素,基本代码如下:
protected void Button1_Click(object sender, EventArgs e)
{
ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mf = (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality)Map1.GetFunctionality(2);
ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisresource = mf.Resource;
bool supported = gisresource.SupportsFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality));
if (supported)
{
ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality qfunc = (ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)gisresource.CreateFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.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] == "sde_DBO_xiangzheng")
{
layer_index = i;
break;
}
}
ESRI.ArcGIS.ADF.Web.SpatialFilter spatialfilter = new ESRI.ArcGIS.ADF.Web.SpatialFilter();
spatialfilter.ReturnADFGeometries = true;
spatialfilter.MaxRecords = 1000;
spatialfilter.WhereClause = "BJAREA=13";
System.Data.DataTable datatable = qfunc.Query(null, lids[layer_index], spatialfilter);
//*** To use the ADF Converter to create a Graphics layer from DataTable, use the following code
ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicsLayer graphicslayer = ESRI.ArcGIS.ADF.Web.UI.WebControls.Converter.ToGraphicsLayer(datatable, System.Drawing.Color.Yellow, System.Drawing.Color.Green);
IEnumerable gfc = Map1.GetFunctionalities();
ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource gResource = null;
foreach (ESRI.ArcGIS.ADF.Web.DataSources.IGISFunctionality gfunc in gfc)
{
if ((gfunc.Resource is ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource) && (gfunc.Resource.Name == "Selection"))
{
gResource = (ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource)gfunc.Resource;
gResource.Graphics.Tables.Clear();
}
}
if (gResource == null)
return;
gResource.Graphics.Tables.Add(graphicslayer);
if (Map1.ImageBlendingMode == ImageBlendingMode.WebTier)
{
Map1.Refresh();
}
else if (Map1.ImageBlendingMode == ImageBlendingMode.Browser)
{
Map1.RefreshResource(gResource.Name);
}
}
}
实现效果: