Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

MapApp Class Reference

Inheritance diagram for MapApp:

Inheritance graph
List of all members.

Detailed Description

Combine a SmartyApp with MapManager functionality.

This class combines the MapServer functionality found within the MapManager class with the ControlBox controls of a SmartyApp. As such it provides a means for interactive online maps to be created.

In order to create custom applications, the MapApp class must be extended. The following example demonstrates how to do this by creating a custom application that will draw the point that the user clicked on the map.

<?php

require_once('webapp/mapapp.php');

class ClickMap extends MapApp {

    function ClickMap(&$map_manager) 
        {
            $this->MapApp($map_manager);
        }

    // override the init() method to register a layer renderer
    function init() 
        {
            // ensure base initialisations are performed
            parent::init();

            // register our layer renderer with the appropriate layer
            $this->setLayerRenderer('click_point', array(&$this, 'doRenderClickPoint'));
        }

    // define a layer renderer (which receives an imageObj) to draw the click point
    function doRenderClickPoint($imageObj) 
        {
            // we need the map manager to interact with the map
            $map_manager =& $this->getMapManager();

            // try and get the click point, exiting the function if it isn't found
            if (!$click_point = $map_manager->getMapClick()) {
                return false;
            }

            // draw the point on the layer 
            $mapObj = $map_manager->getCObj(); // the PHP MapScript mapObj
            $layerObj = $map_manager->getLayerByName('click_point'); // the PHP MapScript layerObj
            $class_index = 0;   // the classObj index for the layer
            $label = 'You clicked here';

            $click_point->draw($mapObj, $layerObj, $imageObj, $class_index, $label);
        }
}


?>

The ClickMap class extends the MapApp class to register a layer renderer which uses the MapManager to help draw the click point on the layer. The layer renderer will be called automatically when MapApp::draw() is called. This example assumes a ClickMap is instantiated with a MapManager using a map file containing a layer definition along the following lines:

    LAYER
        NAME "click_point"
        TYPE POINT
        STATUS ON
        CLASS
            NAME "Clicked point"
            STYLE
                OUTLINECOLOR 255 0 0
                COLOR 0 255 0
                SIZE 12
                SYMBOL "circle"
            END
            LABEL
                COLOR 255 0 0
                SIZE SMALL
                TYPE BITMAP
                OUTLINECOLOR 255 255 255
                POSITION AUTO
                OFFSET 6 0
            END
        END
    END

In addition to customising the rendering of layers, MapApp can be extended to customise existing controls and register new controls. Looking at how the existing controls are implemented provides a starting point. The 'zoom to maximum extent' button, for example, is implemented in MapApp::initZoomAll(). Note that this is called from MapApp::init() when a MapApp instance is initialised.

Definition at line 170 of file mapapp.php.

Public Member Functions

 MapApp (&$map_manager)
 The MapApp constructor.

 assign ()
 Assign controls to the Smarty object.

 setMapManager (&$map_manager)
 Set the MapManager.

getMapManager ()
 Get the MapManager.

 getTemplate ()
 Get the Smarty template.

 setTemplate ($template)
 Set the Smarty template.

 initMapExt ()
 Initialise the map extent control.

 initMainMap ()
 Initialise the main map control.

 initRefMap ()
 Initialise the reference map control.

 initZoomLevel ()
 Initialise the zoom level control.

 initMapTools ()
 Initialise the map tools.

 initZoomIn ()
 Initialise the zoom in control.

 initZoomOut ()
 Initialise the zoom out control.

 initPan ()
 Initialise the pan control.

 initZoomAll ()
 Initialise the zoom all control.

 initRefresh ()
 Initialise the refresh control.

 initLayerChoice ()
 Initialise the layer choice control.

 init ()
 Initialises controls by calling various init* methods.

 updateZoomControls ()
 Update the zoom controls.

 doSetExtent (&$control)
 Set the map extent using a ControlElement.

 doToggleAllLayersState (&$control)
 Toggle the visibility of all layers using a ControlElement.

 doToggleLayerState (&$control)
 Toggle the visibility of a single layer using a ControlElement.

 doSetZoomAll (&$control)
 Zoom out to the maximum map extents.

 doSetZoomLevel (&$control)
 Set the zoom level using a ControlElement.

 doDefineMapClick (&$image_input)
 Define the main map click point using an ImageInput.

 doDefineRefMapClick (&$image_input)
 Define the reference map click point using an ImageInput.

 doSetRefMapZoom (&$image_input)
 Set the zoom type when the reference map is used.

 doSetZoomPanOn (&$control)
 Set the zoom type to pan.

 doSetZoomPanOff (&$control)
 Unset the zoom type from a pan.

 doSetZoomInOn (&$control)
 Set the zoom type to zoom in.

 doSetZoomInOff (&$control)
 Unset the zoom type from zoom in.

 doSetZoomOutOn (&$control)
 Set the zoom type to zoom out.

 doSetZoomOutOff (&$control)
 Unset the zoom type from zoom out.

 imageObjToImage (&$imageObj, &$image)
 Assign an imageObj to an ImageInput control.

 drawToImage (&$image)
 Renders the main map to an ImageInput.

 drawReferenceMapToImage (&$image)
 Renders the reference map to an ImageInput.

 draw ($return=true)
 Render the main map.

 drawReferenceMap ($return=true)
 Render the reference map.

 version ()
 Get the version of the class.

 toString ()
 Get the result of rendering the map to the Smarty template.

 __sleep ()
 Prepare object for serialisation.


Public Attributes

 $map_manager
 A MapManager instance.


Constructor & Destructor Documentation

MapApp::MapApp &$  map_manager  ) 
 

The MapApp constructor.

Parameters:
$map_manager a reference to a MapManager instance

Definition at line 179 of file mapapp.php.

References $map_manager.


Member Function Documentation

MapApp::__sleep  ) 
 

Prepare object for serialisation.

This method is automatically called just before the object is serialised to carry out clean-up operations. See the PHP documentation at http://www.php.net/manual/en/language.oop.magic-functions.php for more information.

Returns:
an array of object property names to be serialised.

Reimplemented from SmartyApp.

Definition at line 982 of file mapapp.php.

MapApp::assign  ) 
 

Assign controls to the Smarty object.

Assigns all controls in the ControlBox to the Smarty object. Only objects which are allowed to be displayed are assigned. The ID of each control is the name with which it should be referenced in the template.

Returns:
void

Reimplemented from SmartyApp.

Definition at line 196 of file mapapp.php.

References $map_manager, and rectToString().

MapApp::doDefineMapClick &$  image_input  ) 
 

Define the main map click point using an ImageInput.

Uses the click coordinates from an ImageInput representing the main map to create a pointObj. This is used to set the click point using MapManager::setMapClick().

Parameters:
$image_input the ImageInput
Returns:
void

Definition at line 718 of file mapapp.php.

References $map_manager, and MM_CLICK_MAIN.

Referenced by initMainMap().

MapApp::doDefineRefMapClick &$  image_input  ) 
 

Define the reference map click point using an ImageInput.

Uses the click coordinates from an ImageInput representing the reference map to create a pointObj. This is used to set the click point using MapManager::setMapClick().

Parameters:
$image_input the ImageInput
Returns:
void

Definition at line 738 of file mapapp.php.

References $map_manager, and MM_CLICK_REF.

Referenced by initRefMap().

MapApp::doSetExtent &$  control  ) 
 

Set the map extent using a ControlElement.

Assumes the control's value is a serialised rectObj and uses it to set the extent of the map.

Parameters:
$control the ControlElement
Returns:
void

Definition at line 622 of file mapapp.php.

References $map_manager, and stringToRect().

Referenced by initMapExt().

MapApp::doSetRefMapZoom &$  image_input  ) 
 

Set the zoom type when the reference map is used.

Designed to be set as an action to an ImageInput, this method will be called when a reference map is clicked. It sets the zoom type to MM_ZOOM_PAN.

Parameters:
$image_input the ImageInput
Returns:
void

Definition at line 758 of file mapapp.php.

References $map_manager, and MM_ZOOM_PAN.

Referenced by initRefMap().

MapApp::doSetZoomAll &$  control  ) 
 

Zoom out to the maximum map extents.

Designed to be set as an action of a ControlElement, this method sets the map extents to the maximum allowed.

Parameters:
$control the ControlElement
Returns:
void

Definition at line 690 of file mapapp.php.

References $map_manager, and MM_ZOOM_EXTENT.

Referenced by initZoomAll().

MapApp::doSetZoomInOff &$  control  ) 
 

Unset the zoom type from zoom in.

Designed to be set as an action to a ControlElement, this method should be called when a control representing zooming in is deselected. It sets the zoom type to MM_ZOOM_NONE.

Parameters:
$control the ControlElement
Returns:
void

Definition at line 821 of file mapapp.php.

References $map_manager, MM_ZOOM_IN, and MM_ZOOM_NONE.

Referenced by initZoomIn().

MapApp::doSetZoomInOn &$  control  ) 
 

Set the zoom type to zoom in.

Designed to be set as an action to a ControlElement, this method should be called when a control representing zooming in is selected. It sets the zoom type to MM_ZOOM_IN.

Parameters:
$control the ControlElement
Returns:
void

Definition at line 805 of file mapapp.php.

References $map_manager, and MM_ZOOM_IN.

Referenced by initZoomIn().

MapApp::doSetZoomLevel &$  control  ) 
 

Set the zoom level using a ControlElement.

Uses the value of a control to set the zoom level.

Parameters:
$control the ControlElement
Returns:
void

Definition at line 704 of file mapapp.php.

References $map_manager.

Referenced by initZoomLevel().

MapApp::doSetZoomOutOff &$  control  ) 
 

Unset the zoom type from zoom out.

Designed to be set as an action to a ControlElement, this method should be called when a control representing zooming out is deselected. It sets the zoom type to MM_ZOOM_NONE.

Parameters:
$control the ControlElement
Returns:
void

Definition at line 854 of file mapapp.php.

References $map_manager, MM_ZOOM_NONE, and MM_ZOOM_OUT.

Referenced by initZoomOut().

MapApp::doSetZoomOutOn &$  control  ) 
 

Set the zoom type to zoom out.

Designed to be set as an action to a ControlElement, this method should be called when a control representing zooming out is selected. It sets the zoom type to MM_ZOOM_OUT.

Parameters:
$control the ControlElement
Returns:
void

Definition at line 838 of file mapapp.php.

References $map_manager, and MM_ZOOM_OUT.

Referenced by initZoomOut().

MapApp::doSetZoomPanOff &$  control  ) 
 

Unset the zoom type from a pan.

Designed to be set as an action to a ControlElement, this method should be called when a control representing panning is deselected. It sets the zoom type to MM_ZOOM_NONE.

Parameters:
$control the ControlElement
Returns:
void

Definition at line 788 of file mapapp.php.

References $map_manager, MM_ZOOM_NONE, and MM_ZOOM_PAN.

Referenced by initPan().

MapApp::doSetZoomPanOn &$  control  ) 
 

Set the zoom type to pan.

Designed to be set as an action to a ControlElement, this method will be called when a control representing panning is selected. It sets the zoom type to MM_ZOOM_PAN.

Parameters:
$control the ControlElement
Returns:
void

Definition at line 772 of file mapapp.php.

References $map_manager, and MM_ZOOM_PAN.

Referenced by initPan().

MapApp::doToggleAllLayersState &$  control  ) 
 

Toggle the visibility of all layers using a ControlElement.

Uses the control's value to determine which layers should be visible. The control element can be either a MultipleSelect or SingleSelect.

Parameters:
$control the ControlElement
Returns:
void

Definition at line 637 of file mapapp.php.

References $map_manager.

Referenced by initLayerChoice().

MapApp::doToggleLayerState &$  control  ) 
 

Toggle the visibility of a single layer using a ControlElement.

Assumes the control's value is a layer name and uses it to select a layer. If the layer is on it is turned off, otherwise it is turned on.

Parameters:
$control the ControlElement
Returns:
void

Definition at line 671 of file mapapp.php.

References $map_manager.

MapApp::draw return = true  ) 
 

Render the main map.

Parameters:
$return if true, return the HTML fragment for displaying the map
Returns:
void

Definition at line 916 of file mapapp.php.

MapApp::drawReferenceMap return = true  ) 
 

Render the reference map.

Parameters:
$return if true, return the HTML fragment for displaying the map
Returns:
void

Definition at line 932 of file mapapp.php.

MapApp::drawReferenceMapToImage &$  image  ) 
 

Renders the reference map to an ImageInput.

Parameters:
$image the ImageInput
Returns:
void

Definition at line 902 of file mapapp.php.

References $map_manager.

MapApp::drawToImage &$  image  ) 
 

Renders the main map to an ImageInput.

Parameters:
$image the ImageInput
Returns:
void

Definition at line 890 of file mapapp.php.

References $map_manager.

& MapApp::getMapManager  ) 
 

Get the MapManager.

Returns:
the MapManager

Definition at line 256 of file mapapp.php.

MapApp::getTemplate  ) 
 

Get the Smarty template.

Returns:
the Smarty template

Reimplemented from SmartyApp.

Definition at line 261 of file mapapp.php.

References $map_manager.

MapApp::imageObjToImage &$  imageObj,
&$  image
 

Assign an imageObj to an ImageInput control.

Saves an imageObj to a URL and sets this URL as the source for the ImageInput.

Parameters:
$imageObj the imageObj
$image the ImageInput
Returns:
void

Definition at line 874 of file mapapp.php.

MapApp::init  ) 
 

Initialises controls by calling various init* methods.

This method controls the order in which controls are initialised. This interface is used to initialise all the controls, assigning them actions and triggers.

Returns:
void

Reimplemented from WebApp.

Definition at line 535 of file mapapp.php.

MapApp::initLayerChoice  ) 
 

Initialise the layer choice control.

Adds a CheckboxChoice control to the ControlBox which contains all selectable layers. It is used to define which layers are turned on or off.

Returns:
void

Definition at line 499 of file mapapp.php.

References $map_manager, doToggleAllLayersState(), and FC_EVENT_UPDATE.

MapApp::initMainMap  ) 
 

Initialise the main map control.

Add an image control to the ControlBox. This represents the main map and is used to determine when and where a user clicks on the map.

Returns:
void

Definition at line 308 of file mapapp.php.

References doDefineMapClick(), and FC_EVENT_CLICK.

MapApp::initMapExt  ) 
 

Initialise the map extent control.

Adds a hidden control to the ControlBox which contains the current extent of the map. This is used to reset the map's extent to what a user would expect when they press the back button in their browser to view past maps but then submit one of those cached pages.

Returns:
void

Definition at line 287 of file mapapp.php.

References $map_manager, doSetExtent(), FC_EVENT_UPDATE, and rectToString().

MapApp::initMapTools  ) 
 

Initialise the map tools.

Adds a RadioChoice control to the ControlBox. This represents the various functions that are available when clicking on the map and manages which function the user has currently selected.

Returns:
void

Definition at line 376 of file mapapp.php.

MapApp::initPan  ) 
 

Initialise the pan control.

Adds actions to the pan control that specifies what happens when a user selects or deselects this tool.

Returns:
void

Definition at line 440 of file mapapp.php.

References doSetZoomPanOff(), doSetZoomPanOn(), FC_EVENT_DESELECT, and FC_EVENT_SELECT.

MapApp::initRefMap  ) 
 

Initialise the reference map control.

Add an image control to the ControlBox. This represents the reference map and is used to determine when and where a user clicks on the reference map.

Returns:
void

Definition at line 328 of file mapapp.php.

References doDefineRefMapClick(), doSetRefMapZoom(), and FC_EVENT_CLICK.

MapApp::initRefresh  ) 
 

Initialise the refresh control.

Adds a submit button to the ControlBox to deal with refreshes. No actions are assigned because form submission should automatically update the application.

Returns:
void

Definition at line 484 of file mapapp.php.

MapApp::initZoomAll  ) 
 

Initialise the zoom all control.

Adds actions to the zoom all control that specifies what happens when a user selects or deselects this tool.

Returns:
void

Definition at line 462 of file mapapp.php.

References doSetZoomAll(), and FC_EVENT_CLICK.

MapApp::initZoomIn  ) 
 

Initialise the zoom in control.

Adds actions to the zoom in tool that specify what happens when a user selects or deselects this tool.

Returns:
void

Definition at line 398 of file mapapp.php.

References doSetZoomInOff(), doSetZoomInOn(), FC_EVENT_DESELECT, and FC_EVENT_SELECT.

MapApp::initZoomLevel  ) 
 

Initialise the zoom level control.

Adds a SingleSelect control to the ControlBox. This represents the amount that a map is zoomed in or out to.

Returns:
void

Definition at line 350 of file mapapp.php.

References doSetZoomLevel(), and FC_EVENT_UPDATE.

MapApp::initZoomOut  ) 
 

Initialise the zoom out control.

Adds actions to the zoom out control that specify what happens when a user selects or deselects this tool.

Returns:
void

Definition at line 418 of file mapapp.php.

References doSetZoomOutOff(), doSetZoomOutOn(), FC_EVENT_DESELECT, and FC_EVENT_SELECT.

MapApp::setMapManager &$  map_manager  ) 
 

Set the MapManager.

Returns:
void

Definition at line 247 of file mapapp.php.

References $map_manager.

MapApp::setTemplate template  ) 
 

Set the Smarty template.

Parameters:
$template the template
Returns:
void

Reimplemented from SmartyApp.

Definition at line 269 of file mapapp.php.

References $map_manager.

MapApp::toString  ) 
 

Get the result of rendering the map to the Smarty template.

Returns:
string

Reimplemented from SmartyApp.

Definition at line 956 of file mapapp.php.

References $map_manager.

MapApp::updateZoomControls  ) 
 

Update the zoom controls.

Update the various controls dealing with zooming and set whether they should be selected/disabled etc. depending on the current zoom state of the map.

Returns:
void

Definition at line 560 of file mapapp.php.

References $map_manager, MM_ZOOM_IN, MM_ZOOM_OUT, and MM_ZOOM_PAN.

MapApp::version  ) 
 

Get the version of the class.

Returns:
the version string

Reimplemented from SmartyApp.

Definition at line 947 of file mapapp.php.

References MAPAPP_VERSION.


Member Data Documentation

MapApp::$map_manager
 

A MapManager instance.

Definition at line 173 of file mapapp.php.

Referenced by assign(), doDefineMapClick(), doDefineRefMapClick(), doSetExtent(), doSetRefMapZoom(), doSetZoomAll(), doSetZoomInOff(), doSetZoomInOn(), doSetZoomLevel(), doSetZoomOutOff(), doSetZoomOutOn(), doSetZoomPanOff(), doSetZoomPanOn(), doToggleAllLayersState(), doToggleLayerState(), drawReferenceMapToImage(), drawToImage(), getTemplate(), initLayerChoice(), initMapExt(), MapApp(), setMapManager(), setTemplate(), toString(), and updateZoomControls().


The documentation for this class was generated from the following file:
Generated on Mon Feb 14 10:55:55 2005 for MapApp by doxygen 1.3.5