RV: [Chameleon] Custom Widget, problem showing Point Layer
Ines
mleonsoft at yahoo.com.ar
Wed Jan 3 20:52:25 EST 2007
Hello, thank for your answer. I added that line but my widget does not even
work. Simply don't do nothing. When I click the button of the widget my
application don't do nothing. The map don't update. I send you the complete
code of my widget.
I´m sending you The point Layer in the file.map, The cwc2 tag in the
template.html, and The code complete in the UUW.widget.php
1)
LAYER
NAME "pointlatlon"
PROJECTION
"init=epsg:4326"
END
TYPE POINT
STATUS ON
FEATURE
POINTS
-80 8
END
TEXT "My Place"
END
CLASS
COLOR 255 0 0
OUTLINECOLOR 255 255 255
SYMBOL "circle"
SIZE 10
LABEL
POSITION AUTO
COLOR 98 223 45
OUTLINECOLOR 255 255 255
END
END
END
2) The cwc2 tag in the template.html
<cwc2
type="UUW"
coords="aa"
imagetip="Info"
image="icons/icon_query.png"
styleresource="NavButtons"
imagewidth="25"
toolset="nav">
<image state="normal"/>
<image state="hover"/>
<image state="selected"/>
</cwc2>
3)UUW.widget.php:
<?php
// inherit from the NavTool
include_once(dirname(__FILE__)."/../NavTool.php");
include( 'utils.inc.php' );
/**
____________________________________________________________________________
_
|
| "UUW" Widget Class
|___________________________________________________________________________
__
**/
class UUW extends NavTool
{
// define member vars
// i.e. var $mszMyVariable;
var $x;
var $y;
var $mszCoords;
var $poLayer;
var $pt;
var $ln;
var $shp;
var $pt;
var $ln;
var $shp;
/**
_________________________________________________________________________
|
| Constructor: "UUW" Widget Class
|_________________________________________________________________________
**/
function UUW()
{
// set the language file
$this->mszLanguageResource = dirname(__FILE__).'/UUW.dbf';
// invoke constructor of parent
parent::NavTool();
$this->SetNavCommand('UUW');
$this->maAttributes['COORDS'] =
new StringAttribute( 'COORDS', true, array( 'aa' ) );
// set the description for this widget
$this->szWidgetDescription = <<<EOT
This is the UUW.
EOT;
// set the maturity level
$this->mnMaturityLevel = MATURITY_ALPHA;
// end constructor
}
function InitDefaults()
{
// init defaults for parent
parent::InitDefaults();
$this->mszCoords = isset( $this->maParams['COORDS'] )?
$this->maParams['COORDS'] : '';
// end InitDefaults function.
}
function ParseURL()
{
// execute parent function
parent::ParseURL();
// work some magic
if ( $this->isVarSet( "NAV_CMD" ) &&
$this->getVar( "NAV_CMD" ) == 'UUW' )
{
$this->x = -85;
$this->y = 13;
if ( $this->mszCoords == 'aa')
{
$poLayer = $this->moMapObject->oMap->getLayerByName('pointlatlon');
$pt = ms_newPointObj();
$ln = ms_newLineObj();
$shp = ms_newShapeObj(MS_SHAPE_POINT);
$pt->setXY($this->x,$this->y);
$ln->add($pt);
$shp->add($ln);
$poLayer->addFeature($shp);
}
}
// return success
return true;
}
function DrawPublish()
{
// init vars
$szReturn = "Search by scientific name <input type='text'
name='textfield'>";
// execute parent
$szReturn .= parent::DrawPublish();
// return
return $szReturn;
// end DrawPublish() function
}
/**
_________________________________________________________________________
|
| GetHTMLHiddenVariables()
|
| OPTIONAL - Use this function to define any hidden html form
variables
| required by the widget.
|
| Postcondition: This function defines html form variables and adds
| them to the array.
|
| Example:
|
| $szVariable = "MY_HIDDEN_VAR";
| $szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"0\">";
| $aReturn[$szVariable] = $szValue;
|
| @return Array - Array of html form variables.
| @desc Defines html form variables.
|_________________________________________________________________________
**/
/** REMOVE THIS LINE TO USE THIS FUNCTION
function GetHTMLHiddenVariables()
{
// init vars
$aReturn = parent::GetHTMLHiddenVariables();
///////// ADD CODE HERE IF NECESSARY /////////
// return
return $aReturn;
// end GetHTMLHiddenVariables() function
}
/**
_________________________________________________________________________
|
| GetJavascriptIncludeFunctions()
|
| OPTIONAL - Use this function to include any external javascript
files
| that are required by the widget.
|
| Postcondition: This function defines the javascript include
statements.
|
| Example:
|
| $szVar = "myjavascript.js";
| $aReturn[$szVar] = '<script src="http://myjavascript.js"
|
type="text/javascript"></script>';
|
|
| @return Array - Array of include statements.
| @desc Defines javascript include statements.
|_________________________________________________________________________
**/
/** REMOVE THIS LINE TO USE THIS FUNCTION
function GetJavascriptIncludeFunctions()
{
// init vars
$aReturn = parent::GetJavascriptIncludeFunctions();
///////// ADD CODE HERE IF NECESSARY /////////
// return
return $aReturn;
// end GetJavascriptIncludeFunctions() function
}
/**
_________________________________________________________________________
|
| GetJavascriptVariables()
|
| OPTIONAL - Use this function to define any javascript variables that
| are required by this widget.
|
| Postcondition: This function defines javascript variables and adds
| them to the array.
|
| Example:
|
| $aReturn['MyJSVar'] = 'var szMyJSVar = "Default Value";'."\n";
|
| @return Array - Array of javascript variables.
| @desc Defines javascript variables.
|_________________________________________________________________________
**/
/** REMOVE THIS LINE TO USE THIS FUNCTION
function GetJavascriptVariables()
{
// init vars
$aReturn = parent::GetJavascriptVariables();
///////// ADD CODE HERE IF NECESSARY /////////
// return
return $aReturn;
// end GetJavascriptVariables() function
}
/**
_________________________________________________________________________
|
| GetJavascriptFunctions()
|
| OPTIONAL - Use this function to define all javascript functions
needed
| by this widget
|
| Postcondition: This function defines javascript functions and adds
| them to the array.
|
| Example:
|
| $szJsFunctionName = "myJSFunction";
| $szFunction = <<<EOT
| function {$szJsFunctionName}()
| {
| alert('myJSFunction');
| return true;
| }
| EOT;
| $aReturn[$szJsFunctionName] = $szFunction;
|
|
| @return Array - Array of javascript functions.
| @desc Defines javascript functions.
|_________________________________________________________________________
**/
/**
function GetJavascriptFunctions()
{
// init vars
$aReturn = parent::GetJavascriptFunctions();
///////// ADD CODE HERE IF NECESSARY /////////
/**
// return
return $aReturn;
// end GetJavascriptFunctions() function
}
/**
_________________________________________________________________________
|
| GetJavascriptInitFunctions()
|
| OPTIONAL - Use this function to define a list of functions that need
| to run to initialize this widget's javascript variables.
|
| Postcondition: This function defines the list javascript functions
| and adds them to the array.
|
| Example:
|
| $aReturn['MyInitFunction'] = "MyInitFunction();\n";
|
| @return Array - Array of javascript functions.
| @desc Defines javascript functions.
|_________________________________________________________________________
**/
/** REMOVE THIS LINE TO USE THIS FUNCTION
function GetJavascriptInitFunctions()
{
// call parent function
$aReturn = parent::GetJavascriptInitFunctions();
///////// ADD CODE HERE IF NECESSARY /////////
// return
return $aReturn;
// end GetJavascriptInitFunctions() function
}
/**
_________________________________________________________________________
|
| GetJavascriptOnLoadFunctions()
|
| OPTIONAL - Use this function to define the list of javascript
functions
| to execute in the onload function of the widget.
|
| Postcondition: This function defines javascript functions and adds
| them to the array.
|
| Example:
|
| $aReturn['MyOnloadFunction'] = "MyOnloadFunction();\n";
|
| @return Array - Array of javascript functions.
| @desc Defines javascript functions.
|_________________________________________________________________________
**/
/**
function GetJavascriptOnLoadFunctions()
{
// init vars
$aReturn = parent::GetJavascriptOnLoadFunctions();
///////// ADD CODE HERE IF NECESSARY /////////
// return
return $aReturn;
// end GetJavascriptOnLoadFunctions() function
}
/**
_________________________________________________________________________
|
| GetJavascriptOnMouseMoveFunctions()
|
| OPTIONAL - Use this function to define the list of javascript
functions
| to execute on a mouse move event.
|
| Postcondition: This function defines mouse move functions and adds
| them to the array.
|
| Example:
|
| $szJsFunctionName = "MyMouseMove";
| $szFunction = "$szJsFunctionName(e);\n";
| $aReturn[$szJsFunctionName] = $szFunction;
|
| @return Array - Array of mouse move functions.
| @desc Defines mouse move functions.
|_________________________________________________________________________
**/
/** REMOVE THIS LINE TO USE THIS FUNCTION
function GetJavascriptOnMouseMoveFunctions()
{
// init vars
$aReturn = parent::GetJavascriptOnMouseMoveFunctions();
///////// ADD CODE HERE IF NECESSARY /////////
// return
return $aReturn;
// end GetJavascriptOnMouseMoveFunctions() function
}
/** **/
// end "UUW"
}
?>
Thank you again and very much
Ines
-----Mensaje original-----
De: Julien-Samuel Lacroix [mailto:jlacroix at mapgears.com]
Enviado el: miércoles, 03 de enero de 2007 17:53
Para: Ines
CC: chameleon at lists.maptools.org
Asunto: Re: [Chameleon] Custom Widget, problem showing Point Layer
Hi,
I tested your widget and got it working by adding:
$this->SetNavCommand('UUW');
in the UUW function.:
function UUW()
{
// set the language file
$this->mszLanguageResource = dirname(__FILE__).'/UUW.dbf';
// invoke constructor of parent
parent::NavTool();
$this->SetNavCommand('UUW');
$this->maAttributes['COORDS'] =
new StringAttribute( 'COORDS', true, array( 'aa' ) );
// set the description for this widget
$this->szWidgetDescription = <<<EOT
This is the UUW.
EOT;
// set the maturity level
$this->mnMaturityLevel = MATURITY_ALPHA;
// end constructor
}
Julien
Ines wrote:
> Hello, I'm trying to show a point layer with my custom widget but I have
> problems to do it. My widget don´t do nothing.
> I created a point layer in the file.map with the status "On" or "Default"
> and it is working very well (It apeears in the legend and show me the
point
> on the map). But I need to make this point dynamic with the custom widget,
> because the latitude and longitude will be changing (dynamic).
>
> When I click on the button of my widget, the web page (my application)
don't
> do nothing. I don´t know how to solve this problem. Perhaps I´m doing
> something wrong in the widget but I don´t know what. I'm going crazy with
> the custom widget and I really need to solve this problem. I really need
> your help.
>
> Well, I need to make the point layer appears in the map when I click the
> buttom of the widget. And I need to have the point layer status "Off" when
I
> run the application for first time, and then, set to "On" just when I
click
> the button of the widget.
>
> I´m show you:
> 1) The point Layer in the file.map
> 2) The code in the widget
> 3) The cwc2 tag in the template.html
>
> 1) The point Layer in the file.map
>
> LAYER
> NAME "pointlatlon"
> PROJECTION
> "init=epsg:4326"
> END
> TYPE POINT
> STATUS OFF
> FEATURE
> POINTS
> -85.933333 13
> END
> TEXT "My Place"
> END
> CLASS
> COLOR 255 0 0
> OUTLINECOLOR 255 255 255
> SYMBOL "circle"
> SIZE 10
>
> LABEL
> POSITION AUTO
> COLOR 98 223 45
> OUTLINECOLOR 255 255 255
> END
> END
> END
> --------------------------------------------------------------------------
--
> ------------
>
> 2) The code in the widget
>
>
> a) ------------------"UUW" Widget
> Class--------------------------------------------------
>
> // inherit from the NavTool
> include_once(dirname(__FILE__)."/../NavTool.php");
> include( 'utils.inc.php' );
>
> /**
>
>
____________________________________________________________________________
> _
> |
> | "UUW" Widget Class
>
>
|___________________________________________________________________________
> __
>
> **/
> class UUW extends NavTool
> {
> // define member vars
> // i.e. var $mszMyVariable;
> var $x;
> var $y;
> var $mszCoords;
> var $poLayer;
> var $pt;
> var $ln;
> var $shp;
> var $pt;
> var $ln;
> var $shp;
>
>
> // var $mszReport;
>
> ///////// ADD MEMBER VARS HERE /////////
>
> /**
>
> _________________________________________________________________________
> |
> | Constructor: "UUW" Widget Class
>
> |_________________________________________________________________________
>
> **/
> function UUW()
> {
> // set the language file
> $this->mszLanguageResource = dirname(__FILE__).'/UUW.dbf';
>
> // invoke constructor of parent
> parent::NavTool();
>
>
>
> ///////// ADD ATTRIBUTES HERE /////////
>
>
> $this->maAttributes['COORDS'] =
> new StringAttribute( 'COORDS', true, array( 'aa' ) );
>
> // set the description for this widget
> $this->szWidgetDescription = <<<EOT
> This is the UUW.
> EOT;
> // set the maturity level
> $this->mnMaturityLevel = MATURITY_ALPHA;
>
> // end constructor
> }
>
> b) ------------------function
> InitDefaults()--------------------------------------------
>
> function InitDefaults()
> {
> // init defaults for parent
> parent::InitDefaults();
>
> ///////// ADD CODE HERE IF NECESSARY /////////
>
>
> $this->mszCoords = isset( $this->maParams['COORDS'] )?
>
> $this->maParams['COORDS'] : '';
>
>
>
> // end InitDefaults function.
> }
>
>
> c) ------------------function
> ParseURL()---------------------------------------------------
>
> function ParseURL()
> {
> // execute parent function
> parent::ParseURL();
>
> ///////// ADD CODE HERE IF NECESSARY /////////
> // work some magic
> if ( $this->isVarSet( "NAV_CMD" ) &&
> $this->getVar( "NAV_CMD" ) == 'UUW' )
> {
>
> $this->x = -85;
> $this->y = 13;
>
> if ( $this->mszCoords == 'aa')
> {
> $poLayer = $this->moMapObject->oMap->getLayerByName('pointlatlon');
> $pt = ms_newPointObj();
> $ln = ms_newLineObj();
> $shp = ms_newShapeObj(MS_SHAPE_POINT);
> $pt->setXY($this->x,$this->y);
> $ln->add($pt);
> $shp->add($ln);
> $poLayer->addFeature($shp);
>
> }
>
> }
>
> // return success
> return true;
> }
>
>
> d) ------------------function
> DrawPublish()-----------------------------------------------
>
>
> function DrawPublish()
> {
> // init vars
> $szReturn = "Search by scientific name <input type='text'
> name='textfield'>";
>
> // execute parent
> $szReturn .= parent::DrawPublish();
>
> ///////// ADD CODE HERE IF NECESSARY /////////
>
> // return
> return $szReturn;
>
> // end DrawPublish() function
> }
> --------------------------------------------------------------------------
--
> ------------------
>
>
> 3) The cwc2 tag in the template.html
>
> <cwc2
> type="UUW"
> coords="aa"
> imagetip="Info"
> image="icons/icon_query.png"
> styleresource="NavButtons"
> imagewidth="25"
> toolset="nav">
> <image state="normal"/>
> <image state="hover"/>
> <image state="selected"/>
> </cwc2>
>
>
> Rally thank you very much,
> Ines
>
> _______________________________________________
> 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