[mapserver-users] [Fwd: Zoom to queried poly using PHP Mapscript]

Daniel Morissette morissette at dmsolutions.ca
Thu May 24 08:46:56 EDT 2001


"David Kriske" wrote:
> 
> Can anyone provide me with info or a code snippet of how to implement a
> "zoom to extent" function using PHP Mapscript that would zoom to a
> queried
> polygon?  Basically I am able to set up a querymap that, based on a
> click of
> the mouse, will highlight whatever polygon(s) the user clicks on.  What
> I
> would like to do is not only highlight, but pan/zoom the map to the
> extent
> of the higlighted polygon(s).  I know it is possible using the CGI
> version,
> but I can't seem to implement it in PHP Mapscript.  How would one
> retrieve
> the extents of the highlighted polygons??
> 

David,

You can open the shapefiles that contain the selected polygons, read the
extent of each selected shape, and use that to compute the MBR of all
the selected polygons.

Your code should look roughly like this (inspired of the function
GMapDumpQueryResults() in the GMap PHP demo source code):

  // Perform query
  $query_res = $map->queryUsingPoint(...)

  // Scan all results and compute mbr of selected shapes
  $cur_layer = -1;
  for($i=0; $i<$query_res->numresults; $i++)
  {
    $result = $query_res->next();

    if ($result->layer == -1)  break;

    if ($cur_layer != $result->layer)
    {
      if ($cur_layer != -1)
        $shapefile->free();
      $cur_layer = $result->layer;
      $layer = $map->getLayer($cur_layer);

     
$shapefile=ms_newShapeFileObj($map->shapepath."/".$layer->data,-1);
    }   

    $shp_ext = $shapefile->getExtent($result->shape);

    // $shp_ext is a rectObj... use it to compute MBR of selected
    // polygons
    ...
  }

  if ($cur_layer != -1)
    $shapefile->free();

-- 
------------------------------------------------------------
 Daniel Morissette               morissette at dmsolutions.ca
 DM Solutions Group              http://www.dmsolutions.ca/
------------------------------------------------------------
  Don't put for tomorrow what you can do today, because if 
      you enjoy it today you can do it again tomorrow.




More information about the mapserver-users mailing list