Chameleon    Home  |  Docs  |  Support  |  Bugs  |  CVS  |  Downloads 

MapTools.org

How Chameleon framework works

This page explains how Chameleon framework works. The order the functions are executed in the widget goes like this:
  • Constructor
  • InitDefault
  • ParseURL
  • All the JS functions
  • DrawPublish

Server side (PHP)

-Chameleon Widget Constructor

In the constructor, you set the attributes available in the widget declaration.

A standard attribute creation will be like that:

$this->maAttributes"FORMINDEX" = new IntegerAttribute( "FORMINDEX", false, 0 );

* Key of the array is the Attribute name in uppercase. * Type of the attribute is defined by the class used to create the object. * First argument will be the name of the attribute in uppercase. * Second argument is the mandatory status of the argument. *The attributes are: StringAttribute, IntegerAttribute, FloatAttribute, HexColorAttribute,RGBColorAttribute or BooleanAttribute. *All attributes must be added in the widget constructor and are case-insensitive.

You need to set the maturity level in order for the widget to appear in the template.

 $this->mnMaturityLevel = MATURITY_TECHNICALRELEASE;
Note 1:

Code maturity indicates the stability and completeness of a widget. It is to be maintained by the widget developer in conjunction with the QA and documentation team. Every widget, by default, will inherit an UNKNOWN maturity level. Widgets that are undergoing active development should be marked as ALPHA. When a widget is considered functionally complete and free of major errors, it should be marked as BETA. Once QA has verified the widget functionality to be stable, the widget can be marked as RELEASECANDIDATE. When a widget has full documentation (English) it can be changed to a RELEASE level. Any changes to a widget after marking as RELEASE must be accompanied by a corresponding change in maturity level. For changes related to bug fixes, it is sufficient to drop one level to RELEASECANDIDATE until the bug fix has been verified. Any new development will require that the widget be marked as BETA until the new functionality has been tested.

Code maturity level will be reflected in the widget documentation for each widget. In addition, it can affect whether the widget is available in a given installation. The Chameleon configuration file now contains a code maturity level item that allows the administrator to define the minimum maturity level available to all applications.

In addition, individual applications can set a maturity level separately, but will be restricted to the administratively configured minimum. Only widgets ator above the minimum maturity level will be available in an application.

-function InitDefaults

This function is used to initialize all widget member variable with parameters present in the widget tag.

Note:

If a user wants to use the same widget attribute with different values, he will need to extract this attribute values from the maszContents variable.

example:

<cwc2 type="QuickZoom" ENABLED="TRUE" labelclass="label" widgetclass="inputBox3">
  <view name="Public Building"/>
  <view name="------------------"/>
  <view name="Fire Dept" minx="697940" miny="2991178"
           maxx="698519" maxy="2991622" SRS="epsg:88888"/>
  <view name="Planning Dept" minx="695045" miny="2993440" 
           maxx="695950" maxy="2994133" SRS="epsg:88888"/>
  <view name="Police Dept" minx="697940" miny="2991178" 
           maxx="698519" maxy="2991622" SRS="epsg:88888"/>
  <view name="Public Works" minx="695045" miny="2993440" 
           maxx="695950" maxy="2994133" SRS="epsg:88888"/>
  <view name="Town House" minx="696582" miny="2992823" 
           maxx="697487" maxy="2993516" SRS="epsg:88888"/>
</cwc2>

The view name will became available through maszContents variable.

if (isset( $this->maszContents["VIEW"] ))
{
    foreach( $this->maszContents["VIEW"] as $aView )
    {
        if (isset($aView["MINX"]) && isset($aView["MINY"]) &&
            isset($aView["MAXX"]) && isset($aView["MAXY"]) &&
            isset($aView["NAME"]) && isset($aView["SRS"]))
        {
            code
        }
            code
    }
}   

-function ParseURL

This is were all processing will be done. All user PHP code goes here. It should return true on success, false otherwise.

Useful tips:

*The following functions allow a user to use the URL variables.

  • function isVarSet( $szVar )
  • Check if a URL variable is set.

  • function getVar( $szVar )
  • Get the value of a URL variable.

  • function setVar( $szVar, $szValue )
  • Set a value in the form variables array

    example:

           if ($this->isVarSet('myVariable1') &&
               $this->getVar('myVariable1s') != "")
    

*To get the map object do the following:

$oMap = $this->moMapObject->oMap;

*The session variables can be used to pass on value.

example:

        isset($_SESSION['gszAppPath'])&&
        $_SESSION['gszAppPath'] != "") 

-function DrawPublish

All string (which will contain HTML most of the time), returned by this function will be printed in the output template result at the place the widget declaration was. If a user wants to add a text field or a button this is the a good place.

example:

function DrawPublish()
{
  if (!$this->mbVisible)
      return;

  $szLabel = '';
  if ($this->mszLabelClass != '')
  {
      $szLabelClass = " class='".$this->mszLabelClass."'";
  }

  $nSize = $this->mnDefaultTextFieldSize;
  $nId = $this->mnId;

  if ($this->isVarSet('myInputName1'))
      $szValue = $this->getVar('myInputName1);
  else
      $szValue = "";


  $szResult = <<<EOT
<tr>
  <td><input type="text" name="myInputName1" size="{$nSize}" value="{$szValue}"></td>
  <td align="right"><input type="button" name="myButtonName1}" value="Go"      
  onClick="myFunctionToCall"></td>
</tr>
EOT;

  return $szResult;
}

Client side

-function GetJavascriptInitFunctions

This is a where we initialize the javascript variables if necessary.

Function calls can also be placed here. This will be called after the onLoad event. This code appears at the end of the applicatoin HTML page (view source in the browser).

example:

$aReturnMapNotesInit['MapNotesInit'] = "MapNotesInit();";

-function GetJavascriptVariables

This is where we declare the global JavaScript variables used by this widget.

Key is the variable name and value the variable declaration of the JavaScript code.

example:

      $szVariable = "goCWCJSAPI";
      $szValue = " var $szVariable = '';";
      $aReturn[$szVariable] = $szValue;

-function GetJavascriptIncludeFunctions

This is where we put the include statements for the javascript files to be included if addition functions or libraries are necessary.

Key is the included file and value the include statement. The function should be declared in GetJavaScriptFunction().

example:

   $szJsIncludeName = $_SESSION["gszCoreWebPath"]."/widgets/js/cwcjsapi.js";
   $szInclude = "<script language=\"JavaScript\" 
src=\"".$_SESSION["gszCoreWebPath"]."/widgets/js/cwcjsapi.js\" 
type=\"text/javascript\"></script>";
   $aReturn[$szJsIncludeName] = $szInclude;

-function GetHTMLHiddenVariables

This is where we declare all HTML hidden variables used by this widget. Key is the variable name and value the HTML variable declaration.

example:

      $szVariable = "myVariable1";
      $szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"\">";
      $aReturn[$szVariable] = $szValue;

-function GetJavascriptOnLoadFunctions

This is where we put the functions that need to be called in the form onLoad event.

The functions should be declared in GetJavaScriptFunction().

example:

      $szJsFunctionName = "myFunction1";
      $szFunction = "$szJsFunctionName();\n";
      $aReturn[$szJsFunctionName] = $szFunction;

-function GetJavascriptFunctions

This is where you put the user functions to be accessible through all the page.

The key is the function name and the value the javascript function declaration.

Note:

Take care to follow the heredoc ("<<<") rules. One should provide an identifier("EOT") (followed by new line) after <<<, then the string, and then the same identifier to close the quotation. It is very important to note that the line with the closing identifier contains no other characters, except /possibly/ a semicolon (;).

example:

      $szJsFunctionName = "myFunction2";
      $szFunction = <<<EOT
function {$szJsFunctionName}( index )
{
  ...
  your code here
  ...
}

EOT;
      $aReturn[$szJsFunctionName] = $szFunction;
Note:
  1. If a user wants to use the value of a PHP variable he will need to put it between {}.
  2. example:

    {$this->mszVariable12}
  3. A user can access an HTML variable by typing {$this->mszHTMLForm} before the name of the variable:
  4. {$this->mszHTMLForm}.myHTMLHiddenVariable1.value

-JavaScript Events

Events allows function to be executed on user or system actions.

To attach a new events to a widget, the registerEventID method must be called in GetJavascriptInitFunctions() method.

example:

     $aResultQueryRegisterEvent['QueryRegisterEvent'] = 
"goEventManager.registerEventID( 'ON_QUERY' );\n";

A widget or an application that needs to listen for this new event will call registerForEvent method. The parameters for this method are the name of the event to listen and a function to call when this event is propagated.

    * function myOnLoad()
    * {
    * CWC2OnLoadFunction();
    * goEventManager.registerForEvent( 'ON_QUERY', 'myOnQuery' );
    * }
    *
    * function myOnQuery( nX, nY)
    * {
    * alert( 'myOnQuery: ' + nX + ',' + nY );
    * } 

To trigger this new event the triggerEvent method must be called.

example:

goEventManager.triggerEvent( 'ON_QUERY', nX, nY ); 

-CWCJSAPI

The CWCJSAPI mode allows an application to execute a request without submitting the page.



Printer Friendly

 
 

Contact Information

Chameleon Users List