[Chameleon] Help on Widget Development...
Julien-Samuel Lacroix
jlacroix at mapgears.com
Tue Sep 4 14:03:08 EDT 2007
Hi,
This kind of error happens if a curly bracket ('}') is missing or if you
have a comment line that is not commented correctly.
Julien
Nolte, Tim wrote:
> Norm,
>
> Thanks for the help. I think I'm pretty close to getting there however
> when I try to include this widget the whole thing breaks with the
> following error:
>
> Parse error: syntax error, unexpected $end in
> /usr/local/chameleon-2.4.1/htdocs/widgets/ZoomToPoint/ZoomToPoint.widget
> .php on line 231
>
> I've went through the code and I can't seem to find where the problem
> lies. Perhaps someone can see the error?
>
> Here's my code:
>
> /**
> * ZoomToPoint Widget class
> *
> * @project CWC2
> * @revision $Id: ZoomToPoint.widget.php,v 1.0 2007/09/04 12:00:00
> tnolte Exp $
> * @purpose Zoom To Point Widget class
> * @author Tim Nolte (tnolte at ilpcs.com) / Normand Savard
> (nsavard at ...)
> * @copyright
> * <b>Copyright (c) 2007, iPCS Wireless Inc.</b>
> */
> include_once(dirname(__FILE__)."/../Widget.php");
> include_once(dirname(__FILE__)."/../Button.php");
> include_once(dirname(__FILE__)."/../Label.php");
>
> /**
> * ZoomToPoint
> *
> * @desc ZoomToPoint widget.
> */
> class ZoomToPoint extends CWCWidget {
> var $mnImageWidth=400;
> var $mnImageHeight=300;
> var $mnScaleZoom=2;
> var $mszLabelClass = '';
> var $mszWidgetClass = '';
>
> function ZoomToPoint() {
> parent::CWCWidget();
>
> $this->szWidgetDescription = <<<EOT
> The Zoom To Point widget plots a know lat/long coordinate or a geocoded
> address.
> EOT;
>
> //Create your require attributes
> $this->maAttributes["SCALEZOOM"] = new
> StringAttribute("SCALEZOOM", false);
> $this->maAttributes["IMAGEWIDTH"] = new
> StringAttribute("IMAGEWIDTH", false);
> $this->maAttributes["IMAGEHEIGHT"] = new
> StringAttribute("IMAGEHEIGHT", false);
> $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["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 = "str_addr";
> $szValue = "<INPUT TYPE=HIDDEN NAME=$szVariable
> VALUE=\"\">";
> $aReturn[$szVariable] = $szValue;
>
> $szVariable = "city";
> $szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable
> VALUE=\"\">";
> $aReturn[$szVariable] = $szValue;
>
> $szVariable = "state_cd";
> $szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable
> VALUE=\"\">";
> $aReturn[$szVariable] = $szValue;
>
> $szVariable = "zip_cd";
> $szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable
> VALUE=\"\">";
> $aReturn[$szVariable] = $szValue;
>
> $szVariable = "plot_lat";
> $szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable
> VALUE=\"\">";
> $aReturn[$szVariable] = $szValue;
>
> $szVariable = "plot_long";
> $szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable
> VALUE=\"\">";
> $aReturn[$szVariable] = $szValue;
>
> return $aReturn;
> }
>
> function ParseURL() {
> //Your processing should be placed here
> if ($this->isVarSet('plot_lat') &&
> $this->getVar('plot_lat') != "" &&
> $this->isVarSet('plot_long') &&
> $this->getVar('plot_long') != "") {
> $nPointX = $this->getVar('plot_long');
> $nPointY = $this->getVar('plot_lat');
>
> // new geocoded point layer name
> $layer_name = "Lat/Long Point";
> } elseif ( ( ($this->isVarSet('city') &&
> $this->getVar('city') != "") &&
> ($this->isVarSet('state_cd') &&
> $this->getVar('state_cd') != "") ) ||
> ($this->isVarSet('zip_cd') &&
> $this->getVar('zip_cd') != "") ) {
>
> // geocode address information
> $googleAPIKey = "...";
> $googleAPIUrl =
> "http://maps.google.com/maps/geo?output=xml&key=".$googleAPIKey;
>
> # Instantiate a new SOAP object, pointing to the
> Perl Web service
> $client = new SoapClient(null,
> array('location' =>
> "http://mapserver.ilpcs.com/cgi-bin/geocode.pl",
> 'uri' =>
> "http://mapserver.ilpcs.co/geocode"));
>
> # address to geocode
> $data =
> explode(",",$this->getVar('str_addr').",".$this->getVar('city').",".$thi
> s->getVar('state_cd').",".$this->getVar('zip_cd'));
> foreach ($data as $element) {
> if ($element != NULL && $element != '')
> {
> $address .= $element.", ";
> }
> }
>
> # Execute the remote call
> $result = $client->geocode($address);
>
> # Remove the latitudinal value from the returned
> array
> $lat = array_shift($result);
>
> # Remove the longitudinal value from the
> returned array
> $long = array_shift($result);
>
> if ($lat == '' || $long == '') {
> $address = "q=".str_replace('
> ','+',$address);
> $url = $googleAPIUrl."&".$address;
>
> // Retrieve the URL contents
> $page = file_get_contents($url);
>
> // Parse the returned XML file
> $xml = new SimpleXMLElement($page);
>
> // Parse the coordinate string
> list($long, $lat, $altitude) =
> explode(",", $xml->Response->Placemark->Point->coordinates);
> }
>
> $nPointX = $long;
> $nPointY = $lat;
>
> // new geocoded point layer name
> $layer_name = "Address";
> } else {
> return;
> }
>
> $oMap = $this->moMapObject->oMap;
> $margin = .025;
>
> $oMap->setExtent($long-$margin,$lat-$margin,$long+$margin,$lat+$margin);
>
> //create your layer (add your php script code to create
> a layer)
> $line = ms_newLineObj();
> $line->addXY($long,$lat);
>
> $shape = ms_newShapeObj(MS_SHAPE_POINT);
> $shape->add($line);
>
> //plot address lat/lon
> $gpoint_layer = $oMap->getLayerByName("Geocoded Point");
> $point_layer = ms_newLayerObj($oMap, $gpoint_layer);
> $point_layer->addFeature($shape);
> $point_layer->set("group", "Geocoded Points");
> $point_layer->set("name", $layer_name);
> $point_layer->set("status",MS_ON);
>
> $oPixelPos = ms_newPointObj();
> $oPixelPos->setXY($nPointX, $nPointY);
>
> $oMap->zoomscale($this->mnScaleZoom, $oPixelPos,
> $this->mnImageWidth, $this->mnImageHeight);
> }
>
> function GetJavascriptFunctions() {
> parent::GetJavascriptFunctions();
>
> $aReturn = array();
> $szJsFunctionName = "ZoomToPointQuery";
> $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 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
> <div style="margin-bottom:8px;padding-bottom:8px;border-bottom:1px solid
> #CCCCCC;">
> <span{$szLabelClass}>Address:</span><br>
> <input{$szWidgetClass} type="text" name="str_addr"><br>
> <span{$szLabelClass}>City</span><br>
> <input{$szWidgetClass} type="text" name="city"><br>
> <span{$szLabelClass}>State:</span><br>
> <input{$szWidgetClass} type="text" name="state_cd" size="2"
> maxlength="2"><br>
> <span{$szLabelClass}>Zip:</span><br>
> <input{$szWidgetClass} type="text" name="zip_cd" maxlength="5">
> </div>
> <div style="margin-bottom:8px;">
> <span{$szLabelClass}>Lat:</span><br>
> <input{$szWidgetClass} type="text" name="plot_lat"><br>
> <span{$szLabelClass}>Long:</span><br>
> <input{$szWidgetClass} type="text" name="plot_long">
> </div>
> <input type="button" name="ZoomToPointQuery" value="Submit Query"
> onClick="ZoomToPointQuery();">
> EOT;
>
> return $szResult;
> }
> }
>
>
> ----
> Timothy J Nolte - tnolte at ilpcs.com
> Associate Network Planning Engineer
>
> iPCS Wireless, Inc.
> 4717 Broadmoor Ave, Suite G
> Kentwood, MI 49512
>
> Office: 616-656-5163
> PCS: 616-706-2438
> Fax: 616-554-6484
> Web: www.ipcswirelessinc.com
>
> _______________________________________________
> Chameleon mailing list
> Chameleon at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/chameleon
>
--
Julien-Samuel Lacroix
Mapgears
http://www.mapgears.com/
More information about the Chameleon
mailing list