[mapserver-users] RE: dynamically allocated points for MAP w/ PHP

E Perik erwin at perik.nu
Fri Apr 5 11:11:00 PST 2002


Pushkar,

What does $HTTP_GET_VARS["layer"] return?
What does the url look like when you use GET ?

Maybe rewrite your select list to PHP, so you can 'make' a url array
like:

LayerArrayString = "a c"

Would look something like:

<select multiple name="LayerList[]" size="5">
<OPTION value="A">A</OPTION>
<OPTION value="B">B</OPTION>
<OPTION value="C">C</OPTION>
</select>

Then you can call the LayerList-array using:

$count=count($LayerList);
for ($i=0; $i<$count; $i++) {
    echo $LayerList[$i];
    $LayerArrayString = $LayerArrayString . " " . $LayerList[$i];
}


Erwin




-----Original Message-----
From: Pushkar Pradhan [mailto:pushkar at ERC.MsState.Edu] 
Sent: Friday, April 05, 2002 8:43 PM
To: E Perik
Cc: mapserver-users at lists.gis.umn.edu
Subject: RE: [mapserver-users] RE: dynamically allocated points for MAP
w/ PHP

Hi Erwin,
I wrote code to implement some of the things you suggested. If I use GET
I
get all the params. like zoomsize, layers etc. in my address window of
IE,
but for POST these params. do not appear in the address window.
But for both these methods when I print out the vals. of layer field I
get
only the last element selected.
Here is the code I use:
if ( isset($HTTP_GET_VARS["layer"]) ) {
   reset($HTTP_GET_VARS);
   $selectLayers = explode(" ", $HTTP_GET_VARS["layer"]);
   echo "here";
   foreach($selectLayers as $val) {
      echo "$val ";
   }
}   // end of if loop
same goes if I try POST.
My html:
      <b>Select Layers to Display: </b><br>
      <select multiple name="layer" size=5>
      <option value="a">a
      <option value="b">b
      <option value="c">c
      <option value="d">d
      <option value="e">e

      <!-- comment php code for now
      <?php
      foreach($layerNames as $layerName) {
      switch($layerName) {
         case 'six_cnty':
            break;
         case '6cnty_quad':
            break;
         default:
            printf("<option value=$layerName> $layerName");
         }
      }
      ?>
      -->
      </select>
If anybody knows what's wrong?
> Hi Pushkar, >
> Just to check the obvious,....
>
> 1) Does it echo the layername?
> 2) Should you not use 'explode' for $layer when multiple are selected?
> 3) Is the layername an existing one and not too long?
> 4) Is the layer STATUS set to: DEFAULT or ON ?
> 5) Is the layer set in your url like:
>    http://localhost/.../name.php?zoom=1&layer="layer1 layer2 layer3"
> 6) You sure POST is correct? Did you check GET ?
>
> Option 2) should use a string like "layer1 layer2 layer3" (see option
5)
> and then you explode it using the space so you then use $layer[0] for
> your first layer of the 'original-string-array'
>
> For exploding use something like:
>
> $LayerArray = explode(" ", $HTTP_GET_VARS["layer"]);
>
> Then from the example above you get:
>
> $LayerArray[0] would be "layer1"
> $LayerArray[1] would be "layer2"
> $LayerArray[2] would be "layer3"
>
> Erwin
>
>
> -----Original Message-----
> From: owner-mapserver-users at lists.gis.umn.edu
> [mailto:owner-mapserver-users at lists.gis.umn.edu] On Behalf Of Pushkar
> Pradhan
> Sent: Thursday, April 04, 2002 7:56 PM
> To: mapserver-users at lists.gis.umn.edu
> Subject: Re: [mapserver-users] RE: dynamically allocated points for
MAP
> w/ PHP
>
> I have a related question, in php/mapscript I show the user a html
list
> from which he/she can select layers to add to the current view, I am
> writing some code but it doesn't work can somebody provide me with the
> algorithm if not the code like the one given below:
> if ( isset($HTTP_POST_VARS["layer"]) ) {
>    echo $HTTP_POST_VARS["layer"];
>    $layer = $map->getLayerByName($HTTP_POST_VARS["layer"]);
>    $image = $map->prepareImage();
>    $layer->draw($image);
>    $image_url = $image->saveWebImage(MS_PNG,1,1,0);
> }   // end of if loop
> The above code doesn't work it creates a blank image, moreover if one
> selects multiple layers to display then only the last one selected is
> chosen.
> Thanks,
>
> > Hi Scott, >
> > There is nothing wrong with the PHP code, except it does not create
a
> > layer, but it creates a new shapefile ;-)
> >
> > So you want to create a layer, dynamicly, or .....
> >
> > Example of creating a layer from a shapefile:
> >
> > 0) Create map-object
> > 1) Get object/points from existing-shapefile or from database
> > 2) Put it in new-shapefile (as you did in your php-script)
> > 3) Create dbf-file with name of new-shapefile
> > 4) Clear new-shapefile (as you did)
> > 5) Add new-layer to map-object (default of this layer is set to OFF)
> > 6) Show new-layer (turn it ON)
> > 7) Draw the map (now includes newly created shapefile ;-) )
> >
> > Explanation:
> >
> > *** In 0) you use like: $Map = ms_newMapObj("blabla.map");
> >
> > *** In 1) you determine input. This could be the 3 points you have
in
> > your example, but also could be a shape or lat/lon from a database
> (eg.
> > dbf/MySQL)
> >
> > *** Option 2) and 3) and 4) you have in your mapscript. This creates
a
> > shapefile + corresponding dbf-file.
> >
> > *** Option 5) and 6) is best done using a dummy-layer which is set
to
> > OFF in your map-file. You turn it on AND attach the new
shapefile-data
> > from by using:
> > 	$Dummylayer = ms_newLayerObj($Map);  // a new layerobject
> > 	$Dummylayer = $Map->getLayerByName("MapLayer");
> > 	$Dummylayer->set("status", 1);	       // Turn it on
> > 	$Dummylayer->set("data", $shpFname);       // Add your created
> > data
> >
> > 	While your map-layer looks something like:
> >
> > 	LAYER
> > 	  NAME "MapLayer"
> > 	  TYPE POINT
> > 	  STATUS OFF
> > 	  CLASS
> > 	    SYMBOL 'circle'
> > 	    COLOR 0 0 0
> > 	    SIZE 3
> > 	  END
> > 	END
> >
> > *** Option 7) is something like:
> >
> > $ImgMap = $Map->draw();
> >
> > This should do the trick.
> >
> > Erwin
> >
> >
> >
> > -----Original Message-----
> > From: Scott D Cogan [mailto:cogansco at msu.edu]
> > Sent: Wednesday, April 03, 2002 10:28 PM
> > To: Consult IT!, E. Perik; mapserver-users at lists.gis.umn.edu
> > Subject: dynamically allocated points for MAP w/ PHP
> >
> > what is wrong with this PHP code?  i am trying to create a layer of
> > points
> > using mapscript.  i had this working previously, then somehow
deleted
> > the
> > file.  now i cant figure it out again:
> >
> > if ($init==1) {
> > // recreate the site layer
> >   $shpFname = "C:\\Program
> Files\\Apache\\htdocs\\mich\\data\\shptest";
> >   $shpFile = ms_newShapeFileObj($shpFname, MS_SHP_POINT);
> >   $def =  array(array("PROG_ID", "N", 5, 0));
> >   $dbfFile = dbase_create($shpFname . ".dbf", $def);
> >   createPoint( 14, 34, 111);
> >   createPoint( 33, 14, 222);
> >   createPoint( 10, 20, 333);
> > // done... cleanup
> >   $shpFile->free();
> >   dbase_close($dbfFile);
> > }
> >
> >
> > function createPoint($x, $y, $name){
> >     GLOBAL $shpFile, $dbfFile;
> >     // Create shape
> >     $oShp = ms_newShapeObj(MS_SHP_POINT);
> >     $oLine = ms_newLineObj();
> >     $oLine->addXY($x, $y);
> >     $oShp->add( $oLine );
> >     $shpFile->addShape($oShp);
> >     // Write attribute record
> >     dbase_add_record($dbfFile, array($name));
> > }
> >
>
>
------------------------------------------------------------------------
> ------
> PUSHKAR S. PRADHAN
> Research Assistant
> MISSISSIPPI STATE UNIVERSITY,
> STARKVILLE, MS 39759.
>
> Engineering Research Center
> Box 9627
> Mississippi State, MS 39762-9627
>
------------------------------------------------------------------------
> ------
>

------------------------------------------------------------------------
------
PUSHKAR S. PRADHAN
Research Assistant
MISSISSIPPI STATE UNIVERSITY,
STARKVILLE, MS 39759.

Engineering Research Center
Box 9627
Mississippi State, MS 39762-9627
------------------------------------------------------------------------
------




More information about the MapServer-users mailing list