[Chameleon] Help on Widget Development...

Normand Savard nsavard at mapgears.com
Wed Aug 29 15:55:18 EDT 2007


Nolte, Tim wrote:

>What I have is a form with 2 sections. One section has Street, City,
>State, Zipcode as input fields, the second section has Lat/Long as input
>fields. The user is going to need to submit one or the other sections.
>If the submit a lat/long then I'll just create a layer using that
>lat/long, however if the enter and address I need to geocode it to get a
>lat/long and then create a layer with the results. Basically, this is
>the start of building in a whole section that the user can use to
>perform various queries to zoom to/pinpoint specific locations.
>
>  
>
Tim,

I suggest to do something like the following.

Norm

class ZoomToPoint extends CWCWidget
{
    var $mnImageWidth=400;
    var $mnImageHeight=300;
    var $mnScaleZoom=2;
    var $mszLabelClass = '';
    var $mszWidgetClass = '';

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

        $this->szWidgetDescription = <<<EOT
Add your description here
EOT;

       //Create your require attributes
        $this->maAttributes["SCALEZOOM"] = new StringAttribute( 
"SCALEZOOM", true);
        $this->maAttributes["IMAGEWIDTH"] = new StringAttribute( 
"IMAGEWIDTH", true);
        $this->maAttributes["IMAGEHEIGHT"] = new StringAttribute( 
"IMAGEHEIGHT", true);
        $this->maAttributes["LABELCLASS"] = new 
StringAttribute("LABELCLASS", false);
        $this->maAttributes["WIDGETCLASS"] = new 
StringAttribute("WIDGETCLASS", false);
    }

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

       //Initialize your parameters here
        if (isset($this->maParams["SCALEZOOM"]))
            $this->mszScaleZoom = $this->maParams["SCALEZOOM"];

        if (isset($this->maParams["IMAGEWIDTH"]))
            $this->mnImageWidth = $this->maParams["IMAGEWIDTH"];
        elseif($this->isVarSet('MAP_WIDTH') && 
$this->getVar('MAP_WIDTH') != "")
           $this->mnImageWidth = $this->getVar('MAP_WIDTH');

        if (isset($this->maParams["IMAGEHEIGHT"]))
            $this->mnImageHeight = $this->maParams["IMAGEHEIGHT"];
        elseif($this->isVarSet('MAP_HEIGHT') && 
$this->getVar('MAP_HEIGHT') != "")
           $this->mnImageHeight = $this->getVar('MAP_HEIGHT');

        if(isset($this->maParams["LABELCLASS"]) && 
$this->maParams["LABELCLASS"] != "")
            $this->mszLabelClass = $this->maParams["LABELCLASS"];

        if(isset($this->maParams["WIDGETCLASS"]) && 
$this->maParams["WIDGETCLASS"] != "")
            $this->mszWidgetClass = $this->maParams["WIDGETCLASS"];
    }


    function GetHTMLHiddenVariables()
    {
        //Create your html variables to pass on your form variables
        $szVariable = "StreetName";
        $szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"\">";
        $aReturn[$szVariable] = $szValue;

        ...

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

        return $aReturn;
    }

    function DrawPublish()
    {
      //This function will create and display your text fields
      if (!$this->mbVisible)
        return;

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

      $szResult = <<<EOT
     <tr>
        <td><div{$szLabelClass}>Street:</div>
        <td><input{$szWidgetClass} type="text" NAME="StreetName" ></td>
    </tr>
   <tr>
        <td><div{$szLabelClass}>City:</div>
        <td><input{$szWidgetClass} type="text" NAME="CityName" ></td>
    </tr>
     ...
     <tr>
        <td><div{$szLabelClass}>ZipCode:</div>
        <td><input{$szWidgetClass} type="text" NAME="ZipCode" ></td>
        <td align="right"><input type="Button" NAME="Query1" VALUE="Go" 
onClick="CustomQuery()"></td>
    </tr>
     <tr>
        <td><div{$szLabelClass}>Lat/Long:</div>
        <td><input{$szWidgetClass} type="text" NAME="LatLong" ></td>
        <td align="right"><input type="Button" NAME="Query2" VALUE="Go" 
onClick="CustomQuery()"></td>
    </tr>
EOT;

      return $szResult;
    }

    function GetJavascriptFunctions()
    {
        parent::GetJavascriptFunctions();

        $aReturn = array();
        $szJsFunctionName = "CustomQuery";
        $szFunction = <<<EOT
/**
 * {$szJsFunctionName}
 * called to submit the form when a user click the go button.
 */
function {$szJsFunctionName}(obj)
{
    {$this->mszHTMLForm}.submit();
    return;
}
EOT;
        $aReturn[$szJsFunctionName] = $szFunction;
        return $aReturn;
    }



    function ParseURL()
    {
        //Your processing should be placed here
        if ($this->isVarSet('LatLong') && $this->getVar('LatLong') != "" )
        {
             extract your latlong values and set the point
             $nPointX = your x coordinate;
             $nPointY = your y coordinate;
       }
        elseif ( ($this->isVarSet('StreetName') && 
$this->getVar('StreetName') != "" ) &&
                  ($this->isVarSet('CityName') && 
$this->getVar('CityName') != "" ) &&
                  ($this->isVarSet('StateName') && 
$this->getVar('StateName') != "" ) &&
                  ($this->isVarSet('ZipCode') && 
$this->getVar('ZipCode') != "" ) )
        {
             do your geocoding stuff and set the point
             $nPointX = your x coordinate;
             $nPointY = your y coordinate;
        }
        else
        {
            return;
        }
 
        $oMap = $this->moMapObject->oMap;

        ...
        create your layer (add your php script code to create a layer)

        ...

   oPixelPos = ms_newPointObj();
   oPixelPos->setXY($nPointX, $nPointY);

        $oMap->zoomscale($this->mnScaleZoom, oPixelPos, 
$this->mnImageWidth, $this->mnImageHeight)


       }
   }








More information about the Chameleon mailing list