[mapserver-users] Simple ItemQuery with QueryMap & php MapScr ipt
Hankley, Chip
Chip.Hankley at GASAI.Com
Fri Aug 9 14:34:08 PDT 2002
Dana -
I would go about reproducing that in two steps. To begin with, you'll need
to make some changes to the mapfile in order to support the PHP/MapScript
functions.
1) The map on the left shows the counties, with the county in question
highlighted. The map is presumably at the extent specified in the mapfile.
You can have a particular county highlight by using EXPRESSION in the class
definition.
$Layer = $map->getlayerbyname("county");
$Object = $Layer->getClass(0);
$Object->setexpression($some_co_value);
In this case, $some_co_value would be a value that would be passed from a
form...i.e. the drop down box that has all the counties.
When you go to draw the map, it should draw the selected county RED, and the
rest white.
2) The map on the right is zoomed into the particular county. This will
require that you figure out the extents of that county, then reset the map
extent to that county, and redraw the map. This is kind of a generic
function...
function sel_extent($map, $layername, $value, $db_field) {
//RESET the extent of the map based on the value of a record. For
// example, we might want to zoom to DANE county in WISCONSIN based
// the response to some event.
//
//PARAMETERS passed:
//$map: the map object
//$layername: the name of the layer that contains the feature
// you want to zoom to
//$value: the value of the field that you are querying against
// e.g. the name of the county
//$db_field: the name of the field in the shapefile's dbf
// e.g. 'county_nm'
//
//Figure out which layer we will be working with, and
// retrieve some basic info on it (paths to data)
$lyr = $map->getlayerbyname($layername);
$src = $lyr->data;
$path = $map->shapepath;
$shp_path = $path . $src;
$db_path = $shp_path . ".dbf";
//Create a new shapefile object based on the path information
$nShpFile = ms_newShapefileObj($shp_path, -1);
//open the dbase file for the shapefile loop through the records
// searching for the first record that matches the
// search criteria.
if ($dbi = dbase_open($db_path, 0)) {
$nr = dbase_numrecords ($dbi);
$q_result = array();
$x = 0;
for ($i=1; $i <= $nr; $i++) {
$cur_row = dbase_get_record_with_names ($dbi, $i);
if (trim($value) == trim($cur_row[$db_field])) {
$row_id = $i;
break;
}
}
}
//Query the shapefile object for that particular record
// to get the extent. Note that row-id is base 0 for mapscript
// but base 1 for the dbf.
$row_id = $row_id - 1;
$shapeExtObj = $nShpFile->getExtent($row_id);
$minx = $shapeExtObj->minx;
$miny = $shapeExtObj->miny;
$maxx = $shapeExtObj->maxx;
$maxy = $shapeExtObj->maxy;
//Add a buffer around the map extent returned for the shape
$border = 200;
$minx = $minx - $border;
$miny = $miny - $border;
$maxx = $maxx + $border;
$maxy = $maxy + $border;
//set the map's extent to the values returned by the shape + the buffer
$map->setExtent($minx, $miny, $maxx, $maxy);
}
In both these cases, after running these commands, you would redraw the map
using something like this:
$img = $map->draw();
$url = $img->saveWebImage(MS_PNG, $map->transparent, $map->interlace, 50);
/* NEW MAPFILE ************************/
NAME test
SHAPEPATH ../data
SIZE 300 300
EXTENT 74000 4775000 798000 5499000
WEB
IMAGEPATH "/usr/local/www/docs/tmp/"
IMAGEURL "/tmp/"
END
LAYER
NAME county
DATA county
STATUS DEFAULT
TYPE POLYGON
#The METADATA section allows you to retrieve information from MapScript
# about a particular layer
METADATA
"DESCRIPTION" "County Info"
"RESULT_FIELDS" "COUNTY_NM POPULATION AREA"
END
CLASSITEM "County_Name" <= Where "County_Name" is the field in the
shapefile specifying county names.
CLASS
NAME 'Selected County'
TEMPLATE "ttt_query.html" <= This line is ESSENTIAL for MapScript
queries
EXPRESSION ''
COLOR 255 0 0
OUTLINECOLOR 0 0 0
END
CLASS
NAME 'All Others'
TEMPLATE "ttt_query.html" <= This line is ESSENTIAL for MapScript
queries
EXPRESSION /./
COLOR 255 255 255
OUTLINECOLOR 0 0 0
END
END
END
-----Original Message-----
From: Dana Coe [mailto:thesquid at FriedBaloney.com]
Sent: Friday, August 09, 2002 3:06 PM
To: mapserver
Subject: [mapserver-users] Simple ItemQuery with QueryMap & php
MapScript
Hello,
Can anyone give me any hints / demos on how to reproduce the MapServer Test
Suite - ItemQuery (Case 3: Simple ItemQuery With QueryMap
http://maps.dnr.state.mn.us/mapserver_demos/tests/itemquery/test.html ) with
Mapserver 3.6.1 & Mapscript?
I've pored over the mailing list, and can find nothing that addresses this.
I've got the gmap demo up and running with my own data & some modifications,
I just want to be able to give it a county name (or a list of zip codes) and
then have these displayed as a map. Case 3 seems to do exactly what I need,
but it seems not to run on current versions.
Any ideas?
Thanks,
Dana L Coe
More information about the MapServer-users
mailing list