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

MapTools.org

Basic:

When an application is run in JSAPI mode UpdateMap.php is called via the CWCJSAPI CWCCallServerFromStack() method. A user may pass on some variables to UpdateMap.php by using an array named "aHiddenVars". At least one variable must be passed to act as a condition for the code to be executed in UpdateMap.php. The CallServer() method calls CWCCallServerFromStack() method. There are two parameters: the array of hidden variables "aHiddenVars" and the function to call when returning from UpdateMap.php for further processing.

The PHP code to be executed follows these steps:

  • include the widget
  • create a widget object
  • execute InitDefaultsto initialize the variables
  • execute SetMap that will set the map object from a MapSession object
  • execute SetURL that will in turn execute the widget ParseURL

example:

JavaScript code that will call UpdateMap.php which will in turn execute the related PHP code. LegendTemplateProcessed is the JavaScript method that will be executed when returning from UpdateMap.php. "PROCESS_L_TEMPLATE" is the variable that makes the PHP code to be executed.

function CWCProcessLegendTemplate(nID)
{
    CWCDHTML_ShowLayer("ActivityLayer");

    aHiddenVars = new Array(2);
    aHiddenVars[0] = new Array(2);
    aHiddenVars[0][0] =  "PROCESS_L_TEMPLATE";
    aHiddenVars[0][1] = "1";
    aHiddenVars[1] = new Array(2);
    aHiddenVars[1][0] =  "PROCESS_L_TEMPLATE_ID";
    aHiddenVars[1][1] = nID;


    szOnLoad = 'goCWCJSAPI.LegendTemplateProcessed()';

    this.CallServer(szOnLoad, aHiddenVars);
    return true;
}

Related PHP code in UpdateMap.php:

// Process the legend template
if (isset( $HTTP_FORM_VARS["PROCESS_L_TEMPLATE"]) &&
$HTTP_FORM_VARS["PROCESS_L_TEMPLATE"] == "1")

{
    include("widgets/LegendTemplate/LegendTemplate.widget.php");
    $oWidget = new LegendTemplate();
    $oWidget->mnId = $HTTP_FORM_VARS["PROCESS_L_TEMPLATE_ID"];
    $oWidget->InitDefaults();
    $oWidget->SetMap($oMapSession);
    $oWidget->SetURL($oHttpFormVars, $HTTP_FORM_VARS);


    other code to execute
}
function CWCLegendTemplateProcessed()
{
    var doc = this.GetDocumentObject();//(this.bIE ) ? this.oContainer.document : this.oContainer.contentDocument;

    if(doc.forms[0].UPDATE_LEGEND_TEMPLATE_RESULTS)
    {
        checkString = doc.forms0.getElementById('UPDATE_LEGEND_TEMPLATE_RESULTS');
        var newString = "";

        ....
        this.GetDocumentDivObject("legendTemplateDiv").innerHTML =
               "<table>" + newString + "</table>";

    }
    return true;
}

Userfull tip:

*If a user needs to execute a Javascript function apart from the one called by CallServer() method and passed on some parameters, he will need to add this function call in szOnLoadFunc string. This is usefull when the parameter values changed.

example:

in UpdateMap.php:
$szOnLoadFunc .= ";myfunction3(".$myPHPVariable.")";

in myfunction3() (this function may be found in GetJavaScriptFunction):

$szJsFunctionName = "myfunction3";
$szFunction = <<<EOT
/*
{$szJsFunctionName}
called when the layers are changed(JSAPI)
*/

function {$szJsFunctionName}(myParameter)
{
   code here
}

EOT;
          $aReturn[$szJsFunctionName] = $szFunction;

*After the page is loaded all the PHP variables and objects do not exist anymore. If a user needs to pass on a PHP variable value to UpdateMap.php that is needed by ParseURL() (via SetURL()), he can use a session variable.

example:


       in ParseURL:
                     if(isset($_SESSION["bCWCJSAPI"]) &&
                     ($_SESSION['bCWCJSAPI']) &&
                     isset($_SESSION['gszAppPath'])&&
                     $_SESSION['gszAppPath'] != "")


       in GetJavaScriptFunction:
               $_SESSION['bCWCJSAPI'] = $bCWCJSAPI;

CWCJSAPI events:

The following events are available:
  • MAP_EXTENT_CHANGED = gnLastEventId ++;
  • MAP_PROJECTION_CHANGED = gnLastEventId ++;
  • MAP_NEW_LAYER_ADDED = gnLastEventId ++;
  • MAP_NEW_ELEMENT_ADDED = gnLastEventId ++;
  • MAP_SIZE_CHANGED = gnLastEventId ++;

  • LAYER_STATUS_CHANGED = gnLastEventId ++;
  • LAYER_STYLE_CHANGED = gnLastEventId ++;
  • LAYER_ORDER_CHANGED = gnLastEventId ++;

  • MOUSE_CLICKED = gnLastEventId ++;

  • ERROR_OCCURRED = gnLastEventId ++;

If a user needs to listen for an event he will have to register for this event with RegisterEvent() method.

example:

     goCWCJSAPI.RegisterEvent(LAYER_STATUS_CHANGED, "LegendTemplateWLayersChanged");

To trigger an event a user will have to call TriggerEvent() method.

example:

    goCWCJSAPI.TriggerEvent(MAP_EXTENT_CHANGED);

CWCJSAPI methods:

The following JSAPI methods are available. To call one of them use "goCWCJSAPI.methodname(parametername);".

Layer methods:

  • GetStatus
  • SetStatus
  • GetStyle
  • GetStyleList
  • SetStyle
  • GetType
  • SetProjection
  • Promote
  • Demote

Map methods:

  • AddLayer //private
  • GetLayer
  • GetLayerByName
  • AddWMSLayer
  • AddGridLayer
  • CreateNewLayer
  • GetProjection
  • SetProjection //private
  • ChangeProjection
  • ReprojectPoint
  • SetZoomFactor
  • ZoomIn
  • ZoomOut
  • ZoomInPos
  • ZoomOutPos
  • ZoomRect
  • ZoomFull
  • ZoomScale
  • Recenter
  • SetExtents
  • Refresh
  • SetViewSize
  • SetLayerDrawingOrder
  • GetLayerDrawingOrder
  • AddPointWidget //private
  • AddRectangleWidget //private
  • AddPoint
  • AddRectangle
  • Geo2Pix
  • Pix2Geo
  • GetDistance
  • ConvertUnit
  • ConvertFromMeter //private
  • ConvertToMeter //private
  • GetUnitIndice //private
  • GetUnitString //private

MLT (language) methods:

  • Get
  • LoadResource
  • SetLanguage

ErrorManager methods:

  • Error
  • PopLastError
  • GetServerErrors

Application methods:
  • GetProperty
  • RegisterEvent
  • DeRegisterEvent
  • TriggerEvent
  • MouseClicked
  • CallServer
  • CallServerFromStack
  • CheckCallStack
  • UpdateNavTools
  • UpdateScaleZoom
  • UpdateCompassPan
  • UpdateNavQuickZoom
  • RefreshMap
  • ZoomToScale
  • LayerStatusUpdated
  • LayerOrderUpdated
  • LayerStyleUpdated
  • AddWMSLayer
  • NewLayerAdded
  • AddPointWidget
  • AddRectangleWidget
  • NewElementAdded = CWNewElementAdded;
  • MapExtentsUpdated
  • UpdateExtentsFromContainer
  • ProcessLegendTemplate
  • LegendTemplateProcessed
  • UpdateProjection
  • ProjectionUpdated
  • UpdateProjectionFromContainer
  • PointReprojected
  • ContainerSetVisibility
  • GetDocumentObject
  • GetDocumentDivObject
  • CreateDHTMLLayer
  • ResourceLoaded
  • ServerErrorsLoaded
  • LoadContext
  • SaveContext
  • ContextSaved
  • UpdateExpressionBuilder

Created by: last modification: Tuesday 13 of November, 2007 [20:23:21 UTC] by nsavard


Printer Friendly

 
 

Contact Information

Chameleon Users List