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. |
|
The MapApp constructor.
Definition at line 179 of file mapapp.php. References $map_manager. |
|
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.
Reimplemented from SmartyApp. Definition at line 982 of file mapapp.php. |
|
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.
Reimplemented from SmartyApp. Definition at line 196 of file mapapp.php. References $map_manager, and rectToString(). |
|
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().
Definition at line 718 of file mapapp.php. References $map_manager, and MM_CLICK_MAIN. Referenced by initMainMap(). |
|
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().
Definition at line 738 of file mapapp.php. References $map_manager, and MM_CLICK_REF. Referenced by initRefMap(). |
|
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.
Definition at line 622 of file mapapp.php. References $map_manager, and stringToRect(). Referenced by initMapExt(). |
|
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.
Definition at line 758 of file mapapp.php. References $map_manager, and MM_ZOOM_PAN. Referenced by initRefMap(). |
|
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.
Definition at line 690 of file mapapp.php. References $map_manager, and MM_ZOOM_EXTENT. Referenced by initZoomAll(). |
|
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.
Definition at line 821 of file mapapp.php. References $map_manager, MM_ZOOM_IN, and MM_ZOOM_NONE. Referenced by initZoomIn(). |
|
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.
Definition at line 805 of file mapapp.php. References $map_manager, and MM_ZOOM_IN. Referenced by initZoomIn(). |
|
Set the zoom level using a ControlElement. Uses the value of a control to set the zoom level.
Definition at line 704 of file mapapp.php. References $map_manager. Referenced by initZoomLevel(). |
|
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.
Definition at line 854 of file mapapp.php. References $map_manager, MM_ZOOM_NONE, and MM_ZOOM_OUT. Referenced by initZoomOut(). |
|
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.
Definition at line 838 of file mapapp.php. References $map_manager, and MM_ZOOM_OUT. Referenced by initZoomOut(). |
|
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.
Definition at line 788 of file mapapp.php. References $map_manager, MM_ZOOM_NONE, and MM_ZOOM_PAN. Referenced by initPan(). |
|
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.
Definition at line 772 of file mapapp.php. References $map_manager, and MM_ZOOM_PAN. Referenced by initPan(). |
|
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.
Definition at line 637 of file mapapp.php. References $map_manager. Referenced by initLayerChoice(). |
|
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.
Definition at line 671 of file mapapp.php. References $map_manager. |
|
Render the main map.
Definition at line 916 of file mapapp.php. |
|
Render the reference map.
Definition at line 932 of file mapapp.php. |
|
Renders the reference map to an ImageInput.
Definition at line 902 of file mapapp.php. References $map_manager. |
|
Renders the main map to an ImageInput.
Definition at line 890 of file mapapp.php. References $map_manager. |
|
Get the MapManager.
Definition at line 256 of file mapapp.php. |
|
Get the Smarty template.
Reimplemented from SmartyApp. Definition at line 261 of file mapapp.php. References $map_manager. |
|
Assign an imageObj to an ImageInput control. Saves an imageObj to a URL and sets this URL as the source for the ImageInput.
Definition at line 874 of file mapapp.php. |
|
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.
Reimplemented from WebApp. Definition at line 535 of file mapapp.php. |
|
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.
Definition at line 499 of file mapapp.php. References $map_manager, doToggleAllLayersState(), and FC_EVENT_UPDATE. |
|
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.
Definition at line 308 of file mapapp.php. References doDefineMapClick(), and FC_EVENT_CLICK. |
|
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.
Definition at line 287 of file mapapp.php. References $map_manager, doSetExtent(), FC_EVENT_UPDATE, and rectToString(). |
|
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.
Definition at line 376 of file mapapp.php. |
|
Initialise the pan control. Adds actions to the pan control that specifies what happens when a user selects or deselects this tool.
Definition at line 440 of file mapapp.php. References doSetZoomPanOff(), doSetZoomPanOn(), FC_EVENT_DESELECT, and FC_EVENT_SELECT. |
|
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.
Definition at line 328 of file mapapp.php. References doDefineRefMapClick(), doSetRefMapZoom(), and FC_EVENT_CLICK. |
|
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.
Definition at line 484 of file mapapp.php. |
|
Initialise the zoom all control. Adds actions to the zoom all control that specifies what happens when a user selects or deselects this tool.
Definition at line 462 of file mapapp.php. References doSetZoomAll(), and FC_EVENT_CLICK. |
|
Initialise the zoom in control. Adds actions to the zoom in tool that specify what happens when a user selects or deselects this tool.
Definition at line 398 of file mapapp.php. References doSetZoomInOff(), doSetZoomInOn(), FC_EVENT_DESELECT, and FC_EVENT_SELECT. |
|
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.
Definition at line 350 of file mapapp.php. References doSetZoomLevel(), and FC_EVENT_UPDATE. |
|
Initialise the zoom out control. Adds actions to the zoom out control that specify what happens when a user selects or deselects this tool.
Definition at line 418 of file mapapp.php. References doSetZoomOutOff(), doSetZoomOutOn(), FC_EVENT_DESELECT, and FC_EVENT_SELECT. |
|
Set the MapManager.
Definition at line 247 of file mapapp.php. References $map_manager. |
|
Set the Smarty template.
Reimplemented from SmartyApp. Definition at line 269 of file mapapp.php. References $map_manager. |
|
Get the result of rendering the map to the Smarty template.
Reimplemented from SmartyApp. Definition at line 956 of file mapapp.php. References $map_manager. |
|
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.
Definition at line 560 of file mapapp.php. References $map_manager, MM_ZOOM_IN, MM_ZOOM_OUT, and MM_ZOOM_PAN. |
|
Get the version of the class.
Reimplemented from SmartyApp. Definition at line 947 of file mapapp.php. References MAPAPP_VERSION. |
|
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(). |