In this topic
- Handle layer initialization failure
- Use layer definition expressions
- Multiple MapResourceManager controls
Handle layer initialization failure
Sometimes a layer (map resource item) fails to initialize when an application loads, or during a user session. By default, resource items fail silently to allow the application to continue to function without interruption.
To be notified when a resource item fails to initialize and determine the reason for the failure, handle the ResourceInit event on the MapResourceManager control. Each time a resource initializes, the event fires. The argument to the event handler contains a reference to the resource item. Select the FailedToInitialize property on the resource item to determine if a failure has occurred. If it has, the InitializeFailure property contains a reference to the exception and error message.
For more information about the MapResourceManager control, see MapResourceManager control. See the following code example:
[C#]
protected void MapResourceManager1_ResourceInit(object sender, EventArgs e)
{
ResourceInitEventArgs riea = (ResourceInitEventArgs)e;
if (riea.GISResourceItem.FailedToInitialize)
{
string message = riea.GISResourceItem.InitializationFailure.Message;
}
}
}
Use layer definition expressions
It can be necessary to show only a subset of features in a feature layer to display. Each map resource can contain many feature layers. The Web Application Developer Framework (ADF) common application programming interface (API) does not provide a generic way to filter and subset layer content. Rules for applying a definition to a layer on a map resource depend on the data source type.
A layer definition affects the display of features in the feature layer, but will not restrict queries. To restrict queries, change the properties of the service or modify the Web ADF application to verify query content before they are initiated.
If a feature layer definition must be applied for the entire user session, set the definition during the Page Load or MapResourceManager Load event. See the following code example:
[C#]
void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Set initial definition properties here.
}
}
The following discusses each data source. A MapResourceManager (MapResourceManager1) is assumed to be available on the Web page.
ArcGIS for Server SOAP API
Local and Internet data source types utilize the ArcGIS for Server Simple Object Access Protocol (SOAP) API; therefore, both can apply a definition to a feature layer using the LayerDescription.DefinitionExpression property. The definition is maintained in state by the Web ADF for the session's duration. The state of the server object will not be changed. See the following code example:
[C#]
if (!MapResourceManager1.Initialized)
MapResourceManager1.Initialize();
ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceBase mrb =
(ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceBase)
MapResourceManager1.GetResource(0);
ESRI.ArcGIS.ADF.ArcGISServer.MapDescription mapdesc = mrb.MapDescription;
ESRI.ArcGIS.ADF.ArcGISServer.LayerDescription layerdesc =
mapdesc.LayerDescriptions[0];
layerdesc.DefinitionExpression = "OBJECTID IN (3,5)";
When working with non-pooled map services, use a stateful change to the server object. This guarantees that a layer definition successfully limits the display and query of layer features. An ArcGIS for Server local data source is required to make a stateful change to a server object. For more information on making stateful changes to a map service, see Data source-specific APIs. See the following code example:
[C#]
if (!MapResourceManager1.Initialized)
MapResourceManager1.Initialize();
ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal mrl =
(ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal)
MapResourceManager1.GetResource(0);
IMapServer ms = (IMapServer)mrl.ServerContextInfo.ServerContext.ServerObject;
IMapServerObjects2 mso = (IMapServerObjects2)ms;
IMap map = mso.get_Map(ms.DefaultMapName);
IFeatureLayer2 layer = (IFeatureLayer2)map.get_Layer(0);
IFeatureLayerDefinition2 definition = (IFeatureLayerDefinition2)layer;
definition.DefinitionExpression = "OBJECTID IN (3,5)";
mrl.RefreshServerObjects();
ArcIMS API
The ArcIMS API provides the necessary classes and properties to apply a layer definition to a feature layer in an ArcIMS service. A Filter object can store the definition expression and be associated with a layer via the FeatureLayer.Filter property. The definition is maintained in state by the Web ADF for the session's duration. See the following code example:
[C#]
if (!MapResourceManager1.Initialized)
MapResourceManager1.Initialize();
ESRI.ArcGIS.ADF.Web.DataSources.IMS.MapResource mr =
(ESRI.ArcGIS.ADF.Web.DataSources.IMS.MapResource)MapResourceManager1.GetResource
(0);
ESRI.ArcGIS.ADF.IMS.Carto.MapView mapview = mr.MapView;
ESRI.ArcGIS.ADF.IMS.Carto.Layer.FeatureLayer featurelayer =
(ESRI.ArcGIS.ADF.IMS.Carto.Layer.FeatureLayer)mapview.Layers[0];
ESRI.ArcGIS.ADF.IMS.Carto.Layer.Filter filter = new
ESRI.ArcGIS.ADF.IMS.Carto.Layer.Filter("#ID# < 10");
featurelayer.Filter = filter;
OGC and WMS
Layer definitions are not available for Open Geospatial Consortium (OGC) and Web Mapping Service (WMS) specifications.
Multiple MapResourceManager controls
If you add multiple MapResourceManager controls to a page, set the map resource item names to be unique across all MapResourceManager controls on the page. This prevents confusion at runtime between resources with identical names.
See Also:
MapResourceManager controlData source-specific APIs