In this topic
Once a connection to an ArcIMS server has been established, information about a map service is available via the MapService object (ESRI.ArcGIS.ADF.IMS.Carto namespace). MapService manages basic interaction with an ArcIMS service and provides general service information to initialize further actions. From the ArcXML perspective, MapService provides an interface to generate a GET_SERVICE_INFO request and store information returned in the SERVICE_INFO response.
The MapService constructor requires IMSServerConnection and InitializationParameters objects and a Boolean to determine if the MapService object should be initialized upon construction. InitializationParameters is a simple container class that stores values associated with GET_SERVICE_INFO attributes. For example, setting the InitializationParameters.LoadFields property to true adds the field= true attribute to the GET_SERVICE_INFO request generated upon initialization of the MapService object. As a result, metadata about field properties for layers in the map service is returned and used to populate objects associated with layer data. By default, all Boolean properties are set to true, and the ScreenDpi property is set to 96.
InitializationParameters is shown in the following code:
[C#]
TCPConnection tcpconnection = new TCPConnection("localhost", 5300);
tcpconnection.ServiceName = "states";
InitializationParameters initparams = new InitializationParameters();
MapService mapservice = new MapService(tcpconnection, initparams, true);
Once a MapService has been created and initialized, it can be used to create a MapView. The MapView object is responsible for managing ArcIMS application programming interface (API) interaction with an ArcIMS image service or ArcMap service. The MapView class provides access to methods and properties to generate a map or legend image, change extent, and work with a collection of layers. MapView also maintains its state as long as it's available. Thus, changes to the MapView, such as changing layer visibility or adding dynamic layers, are maintained for you.
The following code shows how to create a map image and return the uniform resource locator (URL) using a MapView:
[C#]
MapView mapview = mapservice.CreateMapView();
mapview.Draw();
string mapurl = mapview.Image.Url;
Calling the Draw() method on MapView sends a GET_IMAGE request to ArcIMS. The Draw() method is overloaded to provide an extent at which to draw a map for use by the spatial reference (projection). Convenient methods for navigating a map call the Draw() method implicitly. These methods include CenterAt(), Pan(), and Zoom().
To change the extent of a map directly, either pass an extent to the Draw() method as a parameter or set the Extent property of a MapView to an Envelope as shown in the following code:
[C#]
ESRI.ArcGIS.ADF.IMS.Geometry.Envelope envelope = new
ESRI.ArcGIS.ADF.IMS.Geometry.Envelope( - 120, 25, - 100, 45);
mapview.Extent = envelope;
To define the physical size of the map image in pixels, use the MapView.Image property as shown in the following code.
[C#]
ESRI.ArcGIS.ADF.IMS.Carto.ImageDescriptor imgdesc = mapview.ImageDescriptor;
imgdesc.Height = (int)((Image1.Height).Value);
imgdesc.Width = (int)((Image1.Width).Value);
Custom event handlers are provided on the MapView to listen for when the map is drawn and when the scale is changed. To add a new handler for Draw events on the MapView, create a new DrawEventHandler and pass the name of the event method in your application as shown in the following code:
[C#]
mapview.Drawn += new DrawEventHandler(mapview_Drawn);
void mapview_Drawn(object sender, EventArgs e)
{
//Do something when the MapView is drawn. }
The event handler can be added to a MapView at any time. Frequently, a single MapView is created at page load and managed for the user session. The event method can be used for a variety of tasks, such as checking if a dynamic layer has been added to the MapView since the previous draw. If it has, the content of the event method requests a new legend image containing the dynamic layer.