RV: [Chameleon] Drawing points with latitude and longitude - Please help me

Julien-Samuel Lacroix jlacroix at mapgears.com
Mon Nov 27 07:39:48 EST 2006


Hi,

1) Yes
2 & 3)Yes, but you also need to add the point in there, not in the 
GetJavaScript function.

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' )
{
         // Note that I removed the $ before the x and y
	$this->x = 8.911825673734443;
	$this->y = -79.41222265835958;

	$poLayer = $this->moMapObject->oMap->getLayerByName('modis');
	$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);
}

The getLayerByName('YourPointLayerName') is supposed to be
the layer NAME, not the wms_name.

Here's a mapscript tutorial. I didn't do it myself, but quickly checked 
it and it seems fine:
http://examples.oreilly.de/english_examples/phphks/mapserver/creating_maps.pdf
You may ask the MapServer-Users mailing-list for better examples.

Once you will master MapScript, you will be able to understand more 
easily how Chameleon works. Here's some pointer (Read the following only 
when you understand MapScript):
There's few things to know:
- Every widgets are a class
- The Attributes added in the Constructor are what you may pass to your 
widget XML tag
- In InitDefault, you initialise all your variables with what was passed 
in the XML tag. Everything is available via the Params array.
- The ParseURL is the most important. It is there that all the 
processing is done. Here you can read the URL variables, modify the map, 
modify the session, etc.
- All the GetJavScript... return JavaScript code that will be added to 
the template. You should not do anything else here.
- Everything returned by the DrawPublish function will be printed, in 
the final HTML page, where the widget was placed.


Does that help?
Julien

Ines wrote:
> Hi Julien, I'm trying to make the widget but I have some errors and I think
> I´m making something wrong.
> 
> I created a new widget with the tutorial:
> http://chameleon-tiki.maptools.org/tiki-index.php?page=Developing+a+new+Cham
> eleon+Widget
> 
> That widget is a success. It is working ok.
> 
> Now, I'm making another widget with my needs. But I have some errors in it.
> I'm making something simple. I want click the widget button and when I clik,
> the layer show me a point in the map (in the layer). I'm tying the code you
> send me for draw points:
> 
> 1) In the class UUW extends NavTool I created 2 variables (x and y):
> 
> var $x;
> var $y;
> 
> 
> 2) In this function that will have the code for read XML with php, I put the
> variables x,y that content the lat/long.
> 
> 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 = 8.911825673734443;
> 	$this->$y = -79.41222265835958;
> 
> }
> 
> 3) Show the points in the map: I'm not sure if "GetJavascriptFunctions()" is
> who execute the code to show the point in the map. Or if I have to define a
> function in GetJavascriptFunctions() and what to return.
> 
> And another question: the function: getLayerByName('YourPointLayerName').
> "YourPointLayerName": is it the "wms_name"? In the tag "METADATA" of the
> Layer in the file.map?
> 
> 
> function GetJavascriptFunctions()
>     {
>         // init vars
>         $aReturn = parent::GetJavascriptFunctions();
> 
>         /////////  ADD CODE HERE IF NECESSARY /////////
> 
> 
> 		$poLayer = $oMap->getLayerByName('modis');  -----------------> ERROR IN
> THIS LINE
> 		$pt = ms_newPointObj();
> 	    	$ln = ms_newLineObj();
> 		$shp = ms_newShapeObj(MS_SHAPE_POINT);
> 	    	$pt->setXY($x,$y);
> 	    	$ln->add($pt);
> 	    	$shp->add($ln);
> 	    	$poLayer->addFeature($shp);
> 
> 
>         // return
>         return $aReturn;
> 
>     // end GetJavascriptFunctions() function
>     }
> 
> if you know some tutorial for understand how to program widgets to know more
> about PHP / script used to program the widgets.
> 
> Thank You very much again.
> Ines
> 
> 
> 
> -----Mensaje original-----
> De: Julien-Samuel Lacroix [mailto:jlacroix at mapgears.com]
> Enviado el: martes, 14 de noviembre de 2006 19:03
> Para: Ines
> CC: chameleon at lists.maptools.org
> Asunto: [Bulk] Re: [Chameleon] Drawing points with latitude and
> longitude - Please help me
> 
> 
> Hi,
> Is it possible with Chameleon? Yes and no.
> Yes, but not out of the box. You will need to create a new widget that
> will add the points on the map. I think you already have your custom
> widget, so you already took a big step forward.
> 
> Few hints:
> - Remove the <form> and the submit button. Chameleon should already be
> in a form and your custom widget will add the button automagically.
> - In the ParseURL() function you execute code only when you custom
> widget is clicked. You should add something like this:
> // work some magic
> if ( $this->isVarSet( "NAV_CMD" ) &&
>                             $this->getVar( "NAV_CMD" ) == 'UUW' )
> {
>     // ...
> }
> 
> Betweem the two brakets of this if() statement, you will put the code to
> read the XML and extract the information directly in PHP. There's some
> tools to read XML. Ask if you need pointers.
> 
> Once this will be done, you will have your latitude and longitude in
> variables (I'll call them $x and $y). Simply put this code to add a point:
> 
> $poLayer = $oMap->getLayerByName('YourPointLayerName');
> $pt = ms_newPointObj();
> $ln = ms_newLineObj();
> $shp = ms_newShapeObj(MS_SHAPE_POINT);
> $pt->setXY($x,$y);
> $ln->add($pt);
> $shp->add($ln);
> $poLayer->addFeature($shp);
> 
> Hope that helps
> 
> Julien
> 
> 
> Ines wrote:
> 
>>Hi,
>>
>>Sorry for my late answer. I was waiting for the answer from my partner.
>>Well, there is some several changes for the work I have to do.
>>
>>1)The database will not be a database, it will be an XML file with tabular
>>data, so, I have to exctract the information from this file.
>>
>>2) I don´t have to show the descriptions in a drop down list, I have to
> 
> make
> 
>>a "search", I think in a form. So, in my application, I have to put the
> 
> name
> 
>>of the specie (description) and when I click "submit" it will connect with
> 
> a
> 
>>webservice that will generate the XML file. This XML file will contain the
>>latitude and longitude of that specie.
>>
>>3)Every specie will have just ONE latitude and longitude.
>>
>>4) And then, I have to show this point in the map.
>>
>>* Now I ask, Is it possible with chameleon? Read tabular data from an XML
>>file?
>>
>>I changed some things in my widget for the "search" in the function
>>DrawPublish() but it doesn't work because when I run my application it
> 
> goes
> 
>>directly to "xx":
>>$szReturn = "<form name='form1' method='post' action='xx'>Search by
>>scientific name <input type='text' name='textfield'><input type='submit'
>>name='Submit'></form>";
>>
>>I send you a part of the XML file:
>>
>><record>
>>  <darwin:DateLastModified>2006-10-26TCentral Ame:rica Standard
>>Time</darwin:DateLastModified>
>>  <darwin:InstitutionCode>HULE</darwin:InstitutionCode>
>>  <darwin:CollectionCode>Plantae</darwin:CollectionCode>
>>  <darwin:CatalogNumber>100899</darwin:CatalogNumber>
>>  <darwin:ScientificName>Inga densiflora</darwin:ScientificName>
>>  <darwin:BasisOfRecord>S</darwin:BasisOfRecord>
>>  <darwin:Kingdom xsi:nil="true" />
>>  <darwin:Phylum xsi:nil="true" />
>>  <darwin:Class xsi:nil="true" />
>>  <darwin:Order xsi:nil="true" />
>>  <darwin:Family>Fabaceae</darwin:Family>
>>  <darwin:Genus>Inga</darwin:Genus>
>>  <darwin:Species xsi:nil="true" />
>>  <darwin:Subspecies xsi:nil="true" />
>>  <darwin:ScientificNameAuthor>Benth.</darwin:ScientificNameAuthor>
>>  <darwin:IdentifiedBy />
>>  <darwin:YearIdentified xsi:nil="true" />
>>  <darwin:MonthIdentified xsi:nil="true" />
>>  <darwin:DayIdentified xsi:nil="true" />
>>  <darwin:TypeStatus xsi:nil="true" />
>>  <darwin:CollectorNumber>1322</darwin:CollectorNumber>
>>  <darwin:FieldNumber xsi:nil="true" />
>>  <darwin:Collector />
>>  <darwin:YearCollected>1983</darwin:YearCollected>
>>  <darwin:MonthCollected>4</darwin:MonthCollected>
>>  <darwin:DayCollected>30</darwin:DayCollected>
>>  <darwin:JulianDay xsi:nil="true" />
>>  <darwin:TimeOfDay xsi:nil="true" />
>>  <darwin:ContinentOcean xsi:nil="true" />
>>  <darwin:Country>Nicaragua</darwin:Country>
>>  <darwin:StateProvince xsi:nil="true" />
>>  <darwin:County xsi:nil="true" />
>>  <darwin:Locality>Quipó</darwin:Locality>
>>  <darwin:Longitude>-85.044167</darwin:Longitude>
>>  <darwin:Latitude>13.627778</darwin:Latitude>
>>  <darwin:CoordinatePrecision xsi:nil="true" />
>>  <darwin:MinimumElevation>320</darwin:MinimumElevation>
>>  <darwin:MaximumElevation>320</darwin:MaximumElevation>
>>  <darwin:MinimumDepth xsi:nil="true" />
>>  <darwin:MaximumDepth xsi:nil="true" />
>>  <darwin:Sex xsi:nil="true" />
>>  <darwin:PreparationType xsi:nil="true" />
>>  <darwin:IndividualCount xsi:nil="true" />
>>  <darwin:PreviousCatalogNumber xsi:nil="true" />
>>  <darwin:RelationshipType xsi:nil="true" />
>>  <darwin:RelatedCatalogItem xsi:nil="true" />
>>  <darwin:Notes xsi:nil="true" />
>>  </record>
>>
>>Thank you very much for your help again, if you need another information
>>tell me and I will send you every thing you need.
>>Thank you again
>>Ines
>>
>>
>>
>>
>>-----Mensaje original-----
>>De: Julien-Samuel Lacroix [mailto:jlacroix at mapgears.com]
>>Enviado el: domingo, 05 de noviembre de 2006 20:07
>>Para: Ines
>>CC: chameleon at lists.maptools.org
>>Asunto: [Bulk] Re: [Chameleon] Drawing points with latitude and
>>longitude - Please help me
>>
>>
>>Hi,
>>
>>What is the database where you store your data?
>>
>>Your steps are correct. Now on how to read the data, it depends on what
>>is the database. If you are able to extract the species names, you
>>should be able to extract the Lat/Lon too from the same place.
>>
>>Once you have extracted the lat/lon, you will be able to plots points on
>>the map fairly easily. There's several method to do that, but we must
>>know what is the data format before. I would  say that the easiest way
>>would be to use OGR directly from the mapfile, otherwise use inline
>>features.
>>
>>Once we'll know the data format, we may be able to help more.
>>
>>List of OGR supported data format:
>>http://ogr.maptools.org/ogr_formats.html
>>Plus ODBC
>>
>>How to add an inline feature:
>>                    $pt = ms_newPointObj();
>>                    $ln = ms_newLineObj();
>>                    $shp = ms_newShapeObj(MS_SHAPE_POINT);
>>                    $pt->setXY($x,$y);
>>                    $ln->add($pt);
>>                    $shp->add($ln);
>>                    $poLayer->addFeature($shp);
>>
>>Hope that help
>>
>>Julien
>>
>>Ines wrote:
>>
>>
>>>Julien, thank you for your help again. I created the drop down list and I
>>>saw the Gmap example. But I´m not sure if I´m in the correct way. Now I
>>>explain exactly what I have to do.
>>>
>>>I have this information:
>>>
>>>Species(Description)	Latitude1	longitude1	Latitude2	longitude2	Latitude3
>>>longitude3
>>>
>>>fish species           xxxxxx	       xxxxxxx	xxxxxxx	 xxxxxxx	  xxxxxx
>>>xxxxxxxx
>>>bird species           xxxxxxx	 xxxxxxx	xxxxxxx	xxxxxxx	  xxxxxx	 xxxxxxxx
>>>........etc
>>>
>>>
>>>I have to show in a map the places where is every specie. Every specie are
>>>located in several places of the map. Like "Parks" in the GMap example. In
>>>the Gmap example, the parks are in several points of the map drawn with
>>>green color. I have to make the same. But, every specie have several
>>>latitudes and longitudes for indicate every point of the map where I have
>>
>>to
>>
>>
>>>draw every point (circle or another image) where is located the specie.
>>>
>>>My idea is to place every specie (description) in a drop down list, and
>>
>>when
>>
>>
>>>I select one specie, draw in the map all the points where is located that
>>>specie. For example with a circle or another image.
>>>
>>>I think It could be:
>>>
>>>1) Select the specie of the drop down list
>>>2) Read all latitudes and longitudes of that specie
>>>3) Take a layer where I will show that points (circles or another image)
>>>4) Show in that layer all the points (latitudes and longitudes) where is
>>>located that specie.
>>>
>>>So, I maked a new widget with the tutorial of chameleon, I have a layer
>>>ready to work in it (I duplicated a layer in the file .map for work in it
>>>without problems) and I maked a drop down list with your help in the new
>>>widget where I show the species (descriptions).
>>>
>>>But I don't know how to read the latitudes and longitudes and from where.
>>>And how to draw the circles or another images to put in the map (or layer)
>>>that corresponds to every latitude and longitude of a specific specie (the
>>>specie I selected)
>>>
>>>Again thank you very much!
>>>
>>>Ines
>>>
>>>
>>>
>>>-----Mensaje original-----
>>>De: Julien-Samuel Lacroix [mailto:jlacroix at mapgears.com]
>>>Enviado el: miércoles, 01 de noviembre de 2006 13:00
>>>Para: Ines
>>>CC: chameleon at lists.maptools.org
>>>Asunto: [Bulk] Re: [Chameleon] Add layers drawing points (circles) with
>>>latitude and longitude
>>>
>>>
>>>Hi,
>>>I'm not sure I understand everything you need so I'll give you some
>>>pointers and hope they are helpful. If not, do not hesitate to post some
>>>more details. BTW here's the mapscript documentation:
>>>http://mapserver.gis.umn.edu/docs/reference/phpmapscript-class
>>>
>>>You can also look at the GMap demo which I think may be included in
>>>MS4W. If not, you can find it here:
>>>http://www.maptools.org/ms4w/index.phtml?page=downloads.html
>>>under PHP/MapScript Sample Application
>>>
>>>1) If you want to display a drop down listsimply add in your
>>>DrawPublish() function the following:
>>>$szReturn = "<select
>>>name='myselect'><option>value1</option><option>value2</option></select>";
>>>return $szReturn;
>>>
>>>2) The following code is not tested and need to be adapted to your needs
>>>and application. In the ParseURL():
>>>if($this->isVarSet('myselect'))
>>>{
>>>    $oMap = $this->moMapObject->oMap;
>>>    $oLayer = $oMap->getLayerByName('myLayer');
>>>    $oLayer->set('status', MS_ON);
>>>    $oClass = $olayer->getClass(0);
>>>    $oClass->setExpression($this->getVar('myselect'));
>>>}
>>>
>>>I hope it gives you an idea of how to do things.
>>>
>>>Julien
>>>
>>>Ines wrote:
>>>
>>>
>>>
>>>>Normand, thank you very very much for your help. I created successfully
> 
> my
> 
>>>>new widget!!! I'm very happy really.
>>>>
>>>>Now, I need to add descriptions in the widget to display as a list, drop
>>>>down list or something to continue with my work. I'm making the steps
> 
> that
> 
>>>>Julien tell me to do it.
>>>>
>>>>I have my widget and I have the layer ready. Now I need to know how to do
>>>>this:
>>>>
>>>>1) display the descriptions in the widgets
>>>>2) set the EXPRESSION and status of the layer in the
>>>>mapfile with the description column value
>>>>
>>>>
>>>>In this mail (below) I explain what I have to do.
>>>>
>>>>
>>>>Thank you very much again
>>>>
>>>>Ines
>>>>
>>>>
>>>>-----Mensaje original-----
>>>>De: Julien-Samuel Lacroix [mailto:jlacroix at mapgears.com]
>>>>Enviado el: viernes, 20 de octubre de 2006 11:25
>>>>Para: Ines
>>>>Asunto: [Bulk] Re: [Chameleon] Add layers drawing points with latitude
>>>>and longitude
>>>>
>>>>
>>>>Hello,
>>>>There's no widget that do exactly that I think, but creating a new one
>>>>would be easy. I suggest you add a layer in your mapfile to display this
>>>>information. You can create widget that will display the descriptions
>>>>and once done will set the EXPRESSION and status of the layer in the
>>>>mapfile with the description column value.
>>>>
>>>>Check this link to create your own widget:
>>>>
>>>
>>>
> http://chameleon-tiki.maptools.org/tiki-index.php?page=Developing+a+new+Cham
> 
>>>>eleon+Widget
>>>>
>>>>Julien
>>>>
>>>>
>>>>Ines wrote:
>>>>
>>>>
>>>>
>>>>
>>>>>Hello, I have a database with some latitudes and longitudes and
>>>>
>>>>description
>>>>
>>>>
>>>>
>>>>
>>>>>and I have to show that points in a layer (map).
>>>>>
>>>>>For example, the columns of the database:
>>>>>
>>>>>latitude		longitude	Description
>>>>>xxxxxxxxx         xxxxxxx     bird species
>>>>>xxxxxxxxx         xxxxxx      shark species
>>>>>
>>>>>I need to make that the people can select the description in some place
>>
>>of
>>
>>
>>>>>my aplication and the aplication show the map with a "circle" for
> 
> example
> 
>>>>>lacated in that latitude and longitude, and then, add that image (or
>>>>
>>>>layer)
>>>>
>>>>
>>>>
>>>>
>>>>>with that point in the main map. I saw an aplication that have a
> 
> "button"
> 
>>>>>called "WMS layers" that make some similar with the Map Browser but I
>>>>
>>>>don't
>>>>
>>>>
>>>>
>>>>
>>>>>know how it works.
>>>>>
>>>>>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/
>>>>
>>>>_______________________________________________
>>>>Chameleon mailing list
>>>>Chameleon at lists.maptools.org
>>>>http://lists.maptools.org/mailman/listinfo/chameleon
>>>
>>>
>>>--
>>>Julien-Samuel Lacroix
>>>Mapgears
>>>http://www.mapgears.com/
>>>
>>>_______________________________________________
>>>Chameleon mailing list
>>>Chameleon at lists.maptools.org
>>>http://lists.maptools.org/mailman/listinfo/chameleon
>>
>>
>>--
>>Julien-Samuel Lacroix
>>Mapgears
>>http://www.mapgears.com/
>>
>>_______________________________________________
>>Chameleon mailing list
>>Chameleon at lists.maptools.org
>>http://lists.maptools.org/mailman/listinfo/chameleon
> 
> 
> --
> Julien-Samuel Lacroix
> Mapgears
> http://www.mapgears.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