Web ADF MapControl


Summary The MapControl provides the display functionality of a map document served using GIS Server. With the map control, you can navigate the map using, for example, ZoomIn, ZoomOut, Pan, and so forth. The MapControl works with the WebMap object. The MapRenderer class renders the control to the appropriate markup, and the MapTag class exposes the control as a JavaServer Pages (JSP) custom tag named map. In addition, events are exposed through MapEvent, and various map tool actions can be performed on the control.

The Model View Controller pattern

The MapControl is a visual JavaServer Faces (JSF) component that renders a view, controls events, and implements business logic. To help you understand the architecture of the Map Control, the Model View Controller (MVC) design pattern is described here and shown in the following diagram. 
The Java Web Application Developer Framework (ADF) controls follow the MVC design pattern. Knowing this pattern will help you understand how the MapControl responds to tool actions and listeners, accesses the business logic, and renders the map. You can then apply your knowledge to customize the Java Web ADF and plug in your own tools and listeners. 
The MVC pattern distinctly separates the different behaviors of the view, controller, and model components in the following ways:
  • The view provides a visual representation of the component. The client interacts with this view and submits events to the controller. 
  • The controller delegates business processing to the other entities, which make use of the model objects to carry out tasks. When events are queued on a component, the component can delegate the handling of these events to the listeners registered on it.  The listeners, in turn, communicate with the business objects to process these events.
  • The model objects maintain the data and provide methods that aid in the actual business processing. 
  • Once the business task is finished, the view once again renders the control to the client. 

Working with the WebMap

The WebMap is an attribute of the WebContext and it defines the properties of the map, including extent, size, image DPI, etc.  A WebMap object generally is defined in the faces-config.xml file of a Web ADF application.  The following shows how it can be configured as an attribute of the WebContext
[XML]
<managed-bean>
    <managed-bean-name>mapContext</managed-bean-name>
    <managed-bean-class>com.esri.adf.web.data.WebContext</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>    
    <managed-property>
        <property-name>attributes</property-name>
        <map-entries>
            <map-entry>
                <key>map</key>
                <value>#{webappMap}</value>
            </map-entry>
         ...
The object gets instantiated web WebContext initializes. The default settings for a WebMap are: 
[XML]
<managed-bean>
  <managed-bean-name>webappMap</managed-bean-name>
  <managed-bean-class>com.esri.adf.web.data.WebMap</managed-bean-class>
  <managed-bean-scope>none</managed-bean-scope>
  <managed-property>
    <property-name>imageFormat</property-name>
    <value>PNG</value>
  </managed-property>
</managed-bean>
A WebMap can have a set of functionalities which can be either of type MapFunctionality or TileFunctionality.  When the resource is cached, it can have a TileFunctionality, otherwise, it is a dynamic resource and has a MapFunctionality.  A set of pre-defined Web ADF controls, e.g. MapControl, can work with WebMap to provide functions on a map such as map navigation, zoom, etc.  The MapControl works with the WebMap to render maps.  The MapRenderer class renders the control to the appropriate markup and the MapTag class exposes the control as a JSP custom tag name map.  You can use the WebMap directly without web controls to manipulate maps.  The following code snippet shows how to crate a set of map images with ExportFunctionality
[Java]
// Get WebMap from WebContext
WebMap webMap = webContext.getWebMap();

// Specify export properties
ExportProperties exProp = new ExportProperties();
exProp.setImageFormat(webMap.getImageFormat());
exProp.setDpi(screenDPI); // constant
exProp.setWidth(500);
exProp.setHeight(500);
exProp.setExtent(webMap.getCurrentExtent());

ArrayList < InputStream > imageStreams = new ArrayList < InputStream > ();
Collection < MapFunctionality > mapFunctions = webMap.getMapFunctionalities();
InputStream is = null;

// Create images for each MapFunctionality
for (MapFunctionality mf: mapFunctions){
    if (mf.isDisabled()){
        continue;
    }
    if (mf.instanceof ExportFunctionality){
        ExportFunctionality exf = (ExportFunctionality)mf;

        // Create the image byte array
        is = exf.export(exProp);
        if (is != null){
            imageStreams.add(is);
        }
    }
}
Similarly, you can change a layer's visibilty, or other map definitions, with the MapFunctionality Interface.  The MapFunctionality interface is implemented by functionalities to provide mapping capabilities for the resource.  For instance, the AGSMapFunctionality provides mapping for ArcGIS Server resources, the AIMSMapFunctionality provides mapping for ArcIMS resources, etc.  
The WebMap works with several map functionalities referenced by the resources by the name FUNCTIONALITY_NAME.  The WebMap fused the map images exported by these map functionalities, applies the correct transparencies, sets and gets the extents, etc.