Highlight selected features like ArcMap in ArcGIS Server using WEBADF

In the below code I'm going to show how to highlight the selected features on ArcGIS Server Map with aqua color like you do in ArcMap. In here I'm highlighting the features that are output of a Attribute query. But you can get the features to highlight from spatial query or anyother methods.




Copy & Paste :



int resourceIndex = 0;
System.Data.DataTable datatable = null;
ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mf =
(ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality)Map1.GetFunctionality(resourceIndex);
ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceBase ags_mrb =
(ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceBase)mf.Resource;
ESRI.ArcGIS.ADF.ArcGISServer.LayerDescription[] layerdescs = ags_mrb.MapDescription.LayerDescriptions;
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;
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);
ESRI.ArcGIS.ADF.Web.SpatialFilter spatialfilter = new ESRI.ArcGIS.ADF.Web.SpatialFilter();
spatialfilter.ReturnADFGeometries = false;
spatialfilter.MaxRecords = 1000;
spatialfilter.WhereClause = "USECODE = '101'";
datatable = qfunc.Query(null, lids[0], spatialfilter);
}
ESRI.ArcGIS.ADF.ArcGISServer.RgbColor irgbc = new ESRI.ArcGIS.ADF.ArcGISServer.RgbColor();
irgbc.Red = 50;
irgbc.Green = 255;
irgbc.Blue = 255;
irgbc.AlphaValue = 255;
//build the array of objectids, could perform a query but since we already know id we don't have to.
ESRI.ArcGIS.ADF.ArcGISServer.FIDSet fids = new ESRI.ArcGIS.ADF.ArcGISServer.FIDSet();
int[] ids = new int[datatable.Rows.Count];
for (int i = 0; i < datatable.Rows.Count; i++)
{
DataRow dr = datatable.Rows[i];
ids[i] = Convert.ToInt32(dr[0]);
}
fids.FIDArray = ids;
layerdescs[0].SelectionColor = irgbc;
layerdescs[0].SelectionFeatures = fids.FIDArray;
Map1.Refresh();
response = Map1.CallbackResults.ToString();

The views and content on my site are my own and do not represent those of my employer. All content is provided "AS-IS" with no warranties and confers no rights.