Mapscript Zoom Level Help

Christopher Harris docterrobert at MSN.COM
Sun Sep 16 22:20:57 EDT 2007


Hello,

I have an HTML form (for now for testing purposes) called Larrandy.php that passes some user-defined parameters to another .php file called index3.php.  Everything works as planned except the zoom level.  What I'm attempting to do is: where it says Zoompoint on the form, I'll enter in the level it should be zoomed in or out (e.g. 1, 2, 3, -1, etc.), and then it should either zoom in or out according to the integer entered in the form.

I've looked at the API of course.  Under the mapObj Class I see zoompoint, zoomrectangle, and zoomscale.  I've selected zoompoint, being as I just simply want to take the center point of the generated image and zoom in or out while focused on that point.  The pointObj is defined toward the top of index3.php.  I have a current rectObj extent set also.  I will be receiving an extent in Latitude and Longitude projection.  That projection will have to get converted to a UTM projection.  Otherwise, the image that I want to display on the US map won't show.   I achieved this via a world file which uses UTM projection.  Keep in mind that before I attempted to add the zooming capability, everything worked and still does (except the zoom of course).

I enter in different values on the form, but the generated pic never changes.  What exactly am I doing wrong here?

My .php file with the form - Larrandy.php
<html>
    <head>
        <title>Mapserver "University of Illinois"</title>
    </head>
    <body>
        <p>Give me ma SPECS, FOOL!!@!@</p><hr><br>
        <form action="index3.php" method="get">
            Width: <input type="text" name="width" />
            Height: <input type="text" name="height" /><br><br><br>
            Zoompoint: <input type="text" name="zoompoint" /><br><br><br>
            Lower Left Corner:<br><br>
            Latitude #1: <input type="text" name="y1" />
            Longitue #1: <input type="text" name="x1" /><br><br><br>
            Upper Right Corner:<br><br>
            Latitude #2: <input type="text" name="y2" />
            Longitue #2: <input type="text" name="x2" /><br><br><br>
            Lat/Long need to be decimal degrees.<br><br>
            Example: <br>40.071888 -88.244698 <br>40.094110 -88.217468<br><br>
        <input type="submit" value="Send Request"/>
        </form>        
    </body>
</html>



My .php file that executes all the map rendering - index3.php
<?php
//dl("php_mapscript.so");

//width, height parameters
//$mapwidth = 750;    //These are hard-coded "parameters"
//$mapheight = 500;
$mapwidth = $_GET['width'];
$mapheight = $_GET['height'];

$centerpoint = ms_newPointObj();
$centerX = $mapwidth/2;
$centerY = $mapheight/2;
$centerpoint->setXY($centerX, $centerY);
echo $centerpoint->x.", ".$centerpoint->y."<br>";

$zoompoint = $_GET['zoompoint'];
echo $zoompoint."<br>";

$x1 = $_GET['x1'];
$y1 = $_GET['y1'];
$x2 = $_GET['x2'];
$y2 = $_GET['y2'];
//parameters will be decimal degrees.  example: -88.244698 40.071888 -88.217468 40.094110
//$x1 = -88.244698;    //These are the hard-coded "parameters"
//$y1 = 40.071888;
//$x2 = -87.527468;
//$y2 = 40.094110;
echo "Before Conversion to UTM: ".$x1." ".$y1." ".$x2." ".$y2."<br>";

//The lat/long conversion to UTM process
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Create a new Rect Obj to be the new, converted EXTENT
$ddextent = ms_newRectObj();
//Set the extent with the "parameters"
$ddextent->setextent($x1, $y1, $x2, $y2);
//Create 2 new Proj Objects to be used for the conversion (latitude/longitude and Universal Transverse Mercator)
$latlongProj = ms_newProjectionObj("+proj=latlong +ellps=GRS80 +datum=NAD83");
$utmProj = ms_newProjectionObj("+proj=utm +ellps=GRS80 +datum=NAD83 +zone=16 +units=m +north +no_defs");
//Convert the lat/long to UTM
$ddextent->project($latlongProj, $utmProj);
//Set converted lat/long x,y's to new UTM x,y's
$x1 = $ddextent->minx;
$y1 = $ddextent->miny;
$x2 = $ddextent->maxx;
$y2 = $ddextent->maxy;

//$y1=$y1+32;  THESE +-32's are to possibly compensate for something odd going on with the y's.
//$y2=$y2-32;
echo "After Conversion to UTM: minX=$x1, minY=$y1, maxX=$x2, maxY=$y2<br>";
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//The mapfile path and map file itself
$map_path = "/var/www/mapserver/basic/";
$map_file = "index3.map";
$map = ms_newMapObj($map_path.$map_file);

//The size of the window set by mapserver
$map->setSize($mapwidth, $mapheight);

$map->zoompoint($zoompoint, $centerpoint, $mapwidth, $mapheight, $ddextent);

//The name of the map
$map->set(name, "GENERIC");

//The type of image produced (Will need to be changed for later)
$map->selectOutputFormat("PNG");

//The color of the background
$map->imagecolor->setRGB(140, 140, 140);

//Sets the output format type
$map->outputformat->setOption(name, "png");
$map->outputformat->setOption(driver, "GD/PNG");
$map->outputformat->setOption(mimetype, "image/png");
$map->outputformat->setOption(imagemode, MS_IMAGEMODE_PC256);
$map->outputformat->setOption(extension, "png");

/*
FOR LATER WHEN DISTINGUISHING WHETHER LARRY OR RANDY REQUESTS THIS
$map->outputformat->setOption(name, "gif");
$map->outputformat->setOption(driver, "GD/GIF");
$map->outputformat->setOption(mimetype, "image/gif");
$map->outputformat->setOption(imagemode, MS_IMAGEMODE_RGB);
$map->outputformat->setOption(extension, "gif");
*/

$map->set(shapepath, "/var/www/mapserver/basic/data/statesp020/");
$map->setProjection("+proj=utm +ellps=GRS80 +datum=NAD83 +zone=16 +units=m +north +no_defs");
//$map->setExtent(393897.50, 4437029.50, 465644.50, 4438945.50);
//sets the EXTENT.  -.5 is there due to some subtraction going on with the world file
$map->setExtent($x1-.5, $y1-.5, $x2-.5, $y2-.5);
$map->set(units, MS_METERS);
$map->set(debug, MS_ON);

//Web Object which specifies the image path and the image url for the image Maperver generates
$map->web->set(imagepath, "/var/www/mapserver/basic/images/");
$map->web->set(imageurl, "/mapserver/basic/images/");

//The United States layer
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$us = ms_newLayerObj($map);
$us->set(name, "US state polygons");
$us->set(type, MS_LAYER_POLYGON);
$us->set(status, MS_DEFAULT);
$us->set(data, "statesp020");
$us->setProjection("+proj=latlong +ellps=GRS80 +datum=NAD83");
//The United States layer class
$usclass = ms_newClassObj($us);
//The United States layer class style
$usstyle = ms_newStyleObj($usclass);
$usstyle->color->setRGB(240, 230, 140);
$usstyle->set(symbol, 0);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//The United States Boundaries Layer
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$usbounds = ms_newLayerObj($map);
$usbounds->set(name, "US state boundaries");
$usbounds->set(type, MS_LAYER_LINE);
$usbounds->set(status, MS_DEFAULT);
$usbounds->set(data, "statesp020");
$usbounds->setProjection("+proj=latlong +ellps=GRS80 +datum=NAD83");
//The US Boundaries layer class
$usboundsclass = ms_newClassObj($usbounds);
//The US Boundaries layer class style
$usboundsstyle = ms_newStyleObj($usboundsclass);
$usboundsstyle->color->setRGB(50, 50, 50);
$usboundsstyle->set(size, 3);
$usboundsstyle->set(symbol, 0);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//University Map Layer
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$university = ms_newLayerObj($map);
$university->set(name, "University of Illinois");
$university->set(type, MS_LAYER_RASTER);
$university->set(status, MS_DEFAULT);
$university->set(data, "colorUofIllinois.gif");
$university->setProjection("+proj=utm +ellps=GRS80 +datum=NAD83 +zone=16 +units=m +north +no_defs");
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Draws the image
$image=$map->draw();
//Produces a url to reference the image by
$image_url=$image->saveWebImage();
echo $image_url;
?>
<html>
    <head>
        <title>Mapserver "University of Illinois"</title>
    </head>
    <body>
        <img src="<?php echo $image_url?>">
        <p>University of Illinois</p>
        <a href="Larrandy.php">Go Back</a>
    </body>
</html>

My map file - index3.map
MAP 
    
END



I wanted the .php file to handle all the mapping commands for learning purposes, that's why it's empty.

Thanks in advance!

 - Chris


_________________________________________________________________
Kick back and relax with hot games and cool activities at the Messenger Café.
http://www.cafemessenger.com?ocid=TXT_TAGLM_SeptWLtagline
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-users/attachments/20070916/deed64a9/attachment.html


More information about the mapserver-users mailing list