mapscript - map query based on points from mysql

lex_berman (sent by Nabble.com) lists at NABBLE.COM
Wed Jan 11 15:56:59 EST 2006


hi folks,

i've used the mapserver cgi for about 4 years, and only started using mapscript recently.  although i managed to grab some points from a mysql table and throw them on top of a map (along with labels from the same table), i have no idea how to save that query for subsequent zooming in / out / panning or trying to do an nquery.

what i did was to cobble together the mapscript call to mysql and draw new objects then put them into the old CGI template along with JBOX.   needless to say, I can draw the first map with my points retreived from mysql, but if i click on the map to zoom or query the database points are lost.

there must be a sort of mapscript - integrated way of doing this, isn't there?  can anyone help me to get to the next step?   what i am hoping to do somehow is to be able to query both the items from mysql points layer and the shapefiles called from the mapfile at the same time, or if that is impossible then at least to preserve and to SEE the layer from the database for reference purposes while being able to browse and query the shapefiles in the mapserver.

>>>apologies for code that follows (& "img src" is changed to "image src")>>>

<?php

/* factor for query */
$beg_yr = "800";
$end_yr = "1000";

/* connect to mysql */
$connect = @mysql_connect("$host", "$user", "$password");

/* grab the point data from mysql table */
@mysql_select_db("$dbase");
$query = " SELECT * FROM table WHERE beg_yr>$beg_yr and end_yr<$end_yr ";

$result = mysql_query($query) or die(mysql_error());
$numrows = mysql_num_rows($result);

/* fire up mapscript */
dl('php_mapscript.so'); 
		
/* set default variables */
$val_zsize=3;
$check_pan="CHECKED";
$map_path="/path/to/mapfile/";
$host="http://blah.foo.edu";

/* start up the mapscript process */
$map = ms_newMapObj($map_path."mapfile.map");
$image=$map->draw();

$this_layer = $map->getLayerByName('sites');
$this_layer->set('status', MS_ON);

while ($site = mysql_fetch_assoc($result)){ 

   $mypoint = ms_newPointObj();
   $mypoint->setXY($site['point_x_coord'],$site['point_y_coord']);
   $pt_id = $site['point_id'];
   $mypoint->draw($map, $this_layer, $image, 0, "$pt_id");
} 

mysql_free_result($result);

/* get the extents and set up drawing objects*/
if ( isset($HTTP_POST_VARS["mapa_x"]) && isset($HTTP_POST_VARS["mapa_y"])
      && !isset($HTTP_POST_VARS["full"]) ) {
		
      $extent_to_set = explode(" ",$HTTP_POST_VARS["extent"]); 
		
      $map->setextent($extent_to_set[0],$extent_to_set[1],
                      $extent_to_set[2],$extent_to_set[3]);
		
      $my_point = ms_newpointObj();
      $my_point->setXY($HTTP_POST_VARS["mapa_x"],$HTTP_POST_VARS["mapa_y"]);
		
      $my_extent = ms_newrectObj();
		
      $my_extent->setextent($extent_to_set[0],$extent_to_set[1],
                              $extent_to_set[2],$extent_to_set[3]);
		
      $zoom_factor = $HTTP_POST_VARS["zoom"]*$HTTP_POST_VARS["zsize"];
      if ($zoom_factor == 0) {
              $zoom_factor = 1;
              $check_pan = "CHECKED";
              $check_zout = "";
              $check_zin = "";
      } else if ($zoom_factor < 0) {
              $check_pan = "";
              $check_zout = "CHECKED";
              $check_zin = "";
      } else {
              $check_pan = "";
              $check_zout = "";
              $check_zin = "CHECKED";
      }
		
      $val_zsize = abs($zoom_factor);
		
      $map->zoompoint($zoom_factor,$my_point,$map->width,$map->height,
                      $my_extent);
		
 }


/* draw the images to cache */
$map->drawLabelCache($image); 
$image_url=$image->saveWebImage();

 $extent_to_html = $map->extent->minx." ".$map->extent->miny." "
              .$map->extent->maxx." ".$map->extent->maxy;

$scale_img = $map->drawScaleBar();
$scale_url = $scale_img->saveWebImage();

$ref_img = $map->drawReferenceMap();
$ref_url = $ref_img->saveWebImage();

$leg_img = $map->drawLegend();
$leg_url = $leg_img->saveWebImage();


?>
		

point mapping from database 

/* set up jbox */
      





/* falling back on CGI template */



    ">
    ">
    
    
    


            
              ">
        
        
        
        

            


scalebar: 
">



      

	select mode: 

         zoom 
         query feature 


   	select zoom factors: 

       Recenter (click on map)  [zoomdir_0_check]> 
       Zoom In (click or drag box)   [zoomdir_1_check]> 
       Zoom Out  [zoomdir_-1_check]> 
       Zoom Size ">




">


">



--
View this message in context: http://www.nabble.com/mapscript---map-query-based-on-points-from-mysql-t898123.html#a2328043
Sent from the Mapserver - User forum at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-users/attachments/20060111/52dd3428/attachment.html


More information about the mapserver-users mailing list