[Chameleon-dev] [Bug 1402] New: Proposed new widget for Chameleon - LegendGraphic

bugzilla-daemon at bugzilla.maptools.org bugzilla-daemon at bugzilla.maptools.org
Wed Apr 5 10:07:12 EDT 2006


http://bugzilla.maptools.org/show_bug.cgi?id=1402

           Summary: Proposed new widget for Chameleon - LegendGraphic
           Product: Chameleon
           Version: 2.4
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Widget
        AssignedTo: chameleon-dev at lists.maptools.org
        ReportedBy: mcgrawj at agr.gc.ca
                CC: godwinl at agr.gc.ca


Liz Godwin created a LegendGraphic widget that displays the Legend Graphic 
returned by MapServer's Map object's drawLegend() (e.g., $oMap->drawLegend()),
At her suggestion, I am including the code for the widget below as a proposed 
addition to Chameleon. It supports JSAPI apps.

An example of the tag to include it on the page is:
<cwc2 type="LegendGraphic" visible="true" />

Besides the widget code itself (below), the only other change required is to 
add graphic legend support to the drawmap.php (around line 492, although the 
main if block starts around line 425) file as follows:

// run query if necessary
if (isset($http_form_vars["run_query"]) &&
      $http_form_vars["run_query"] == 1 )
{
    :

}
//keymap
else if (isset($http_form_vars["REQUEST"]) &&
         (strcasecmp($http_form_vars["REQUEST"],"KEYMAP") == 0))
{
    :
}
//scalebar
else if (isset($http_form_vars["REQUEST"]) &&
         strcasecmp($http_form_vars["REQUEST"],"SCALEBAR") == 0)
{
    :
}
// graphic legend
else if (isset($http_form_vars["REQUEST"]) &&
         strcasecmp($http_form_vars["REQUEST"],"LEGEND") == 0)
{
    $oImage = @$oMapSession->oMap->drawLegend();
}
else
{
    :
}


Widget code: LegendGraphic.widget.php
=====================================

<?php
/**
 * LegendGraphic Widget class
 *
 */
include_once($_SESSION['gszCorePath']."widgets/Widget.php");

/**
 * LegendGraphic
 *
 * @desc LegendGraphic widget class
 */
class LegendGraphic extends CWCWidget
{

    function LegendGraphic()
    {
        parent::CWCWidget();

        $this->szWidgetDescription = <<<EOT
The LegendGraphic widget displays a graphic legend.
EOT;

        $this->mnMaturityLevel = MATURITY_BETA;
    }

    function InitDefaults()
    {
        parent::InitDefaults();

        if (isset($this->maParams["VISIBLE"]))
            $this->mbVisible = ((strcasecmp($this->maParams["VISIBLE"], "TRUE")
==0) ? true : false);
    }

    function GetJavascriptFunctions()
    {
        $aReturn = array();

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

        if (isset($this->maSharedResourceWidgets["CWCJSAPI"]))
        {
            $url = WEBCOMMON."/wrapper/drawmap.php?
map_session_mode=1&run_query=0&REQUEST=LEGEND&".SID;
            $url .= "&dummy=".urlencode(microtime());

            $szJsFunctionName = "LegendGraphicWRegisterForEvent";
            $szFunction = <<<EOT
/**
 * {$szJsFunctionName}
 * called to register and even when the map extents chnages (JSAPI)
 */
function {$szJsFunctionName}()
{
    goCWCJSAPI.RegisterEvent(MAP_EXTENT_CHANGED, "LegendGraphicWMapChanged");
    goCWCJSAPI.RegisterEvent(LAYER_STATUS_CHANGED, "LegendGraphicWMapChanged");
}
EOT;

           $aReturn[$szJsFunctionName] = $szFunction;

       $szJsFunctionName = "LegendGraphicWMapChanged";
           $szFunction = <<<EOT
/**
 * {$szJsFunctionName}
 * called when the mapextents and layer status are changed to update the legend 
images(JSAPI)
 */
function {$szJsFunctionName}()
{
     var sImgName = "LegendGraphicImg";
     var url = "{$url}";
     var d = new Date();
     var unique = d.getTime() + '' + Math.floor(1000 * Math.random());
     url = url + "&UniqId="+unique;
     document.images[sImgName].src = url;
}
EOT;
           $aReturn[$szJsFunctionName] = $szFunction;

           return $aReturn;
        }
    }

    function GetJavascriptOnLoadFunctions()
    {
        $aReturn = parent::GetJavascriptOnLoadFunctions();

        if (isset($this->maSharedResourceWidgets["CWCJSAPI"]))
        {
             $szJsFunctionName = "LegendGraphicWRegisterForEvent";
             $szFunction = "$szJsFunctionName();\n";
             $aReturn[$szJsFunctionName] = $szFunction;
        }

        return $aReturn;
    }

    /**
     * DrawPublish
     *
     * Return the HTML code to display the legendgraphic
     */
    function DrawPublish()
    {
        if (!$this->mbVisible)
            return "<!-- LegendWidget is hidden -->";

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

        $oLegendImage = $oMap->drawLegend();
        $url = $oLegendImage->saveWebImage();

        $szResult = "<img src=\"$url\" name=\"LegendGraphicImg\" border=\"0\">";
        return $szResult;

    }
}
?>



------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.


Please do NOT reply to this email, use the link above instead to 
login to bugzilla and submit your comment. Any email reply to this
address will be lost.


More information about the Chameleon-dev mailing list