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, it provides an interface to generate a GET_SERVICE_INFO request and store information returned in the SERVICE_INFO response. The MapService constructor requires an IMSServerConnection object, InitializationParameters objects, and a boolean to determine if MapService object should be initialized upon construction. InitializationParameters is a simple container class and stores values associated with GET_SERVICE_INFO attributes. For example, setting the InitializationParameters.LoadFields property to true will add the attribute "field= 'true'" 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 will be 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.
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 API interaction with an ArcIMS image 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. The MapView also maintains its state as long as it
is available. Thus, changes to the MapView, such as changing
layer visibility or adding dynamic layers, will be maintained for
you.
To simply create a map image and return the url using a MapView:
MapView mapview = mapservice.CreateMapView(); mapview.Draw(); string mapurl = mapview.Image.Url;
Calling the Draw() method on the MapView sends a GET_IMAGE request to ArcIMS. The Draw() method is overloaded to support providing a extent at which to draw a map or the spatial reference (projection) to use. Convenience methods for navigating a map will call the Draw() method implicitly. They 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.
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.
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.
mapview.Drawn += new DrawEventHandler(mapview_Drawn);
void mapview_Drawn(object sender, EventArgs e) { //do something when MapView drawn }
The event handler can be added to a MapView at any time. Frequently, a
single MapView is created upon page load and managed for the user
session. The event method may be used to do a variety of tasks, such
as checking if a dynamic layer has been added to the MapView since the
previous draw. If so, the content of the event method requests a new
legend image containing the dynamic layer.