Mapscript Zoom Level Help Solved, but new question

Christopher Harris docterrobert at MSN.COM
Mon Sep 17 14:28:09 EDT 2007


Ok.  I figured out my last question.  Apparently, I needed to have a zoomscale instead of a zoompoint.  What I also discovered is that zoomscale needed to be set right before I said map->draw.  If I copied and pasted $map->zoomscale($zoomscale, $centerpoint, $mapwidth, $mapheight, $utmextent); to where I originally had it (right under where I say $map->setSize()), then the zoomscale won't work.  But, if I move it to where I said earlier, it works.  Where I originally had the line was after I had $zoomscale, $centerpoint, $mapwidth, $mapheight, and $utmextent declared and set to something - so why that is I don't know.

If someone knows that would be great help.  I'm just curious that's all.  

Also, what's the point of map->zoompoint()?  From my understanding of the Mapscript API, you could pick a point on the image according to 0, 0 (being the x, y coordinates from the upper left corner), give it the image width and height and the current extent along with an integer representing zoom level and BAM - there you go.  But, nothing happened when I kept giving a different value of zoom level (1, -1, 2, -10, etc.).  If I comment out the zoompoint too, it doesn't change a thing.  I assume I misinterpreted something?

My 2 files of importance:

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" />&nbsp; Ex. - 1, 2, 3, 4, -1, -2, etc.<br><br><br>
            Zoomscale: <input type="text" name="zoomscale" />&nbsp; Ex. - 4000, 8000, 16,000, etc.<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>




index3.php

<?php
//dl("php_mapscript.so");

//width, height parameters
$mapwidth = $_GET['width'];
$mapheight = $_GET['height'];

//New point object for Zooming
$centerpoint = ms_newPointObj();
//Taking the center points of the image
$centerX = $mapwidth/2;
$centerY = $mapheight/2;
$centerpoint->setXY($centerX, $centerY);
echo "The center X coordinate is: ".$centerpoint->x.", The center Y coordinate is: ".$centerpoint->y."<br>";

//The zoompoint and zoomscale parameters
//$zoompoint = $_GET['zoompoint'];
//echo "The Zoom Point is: ".$zoompoint."<br>";
$zoomscale = $_GET['zoomscale'];
echo "The Zoom Scale is: ".$zoomscale."<br>";

//Coordinates passed will be in decimal degrees.  example: -88.244698 40.071888 -88.217468 40.094110
$x1 = $_GET['x1'];
$y1 = $_GET['y1'];
$x2 = $_GET['x2'];
$y2 = $_GET['y2'];
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);
$utmextent = $ddextent;
//Set converted lat/long x,y's to new UTM x,y's
$x1 = $utmextent->minx;
$y1 = $utmextent->miny;
$x2 = $utmextent->maxx;
$y2 = $utmextent->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);

//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");
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//$map->zoompoint($zoompoint, $centerpoint, $mapwidth, $mapheight, $utmextent);
$map->zoomscale($zoomscale, $centerpoint, $mapwidth, $mapheight, $utmextent);
//Draws the image
$image=$map->draw();
//Produces a url to reference the image by
$image_url=$image->saveWebImage();
echo $image_url."<br>";
?>
<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>

 - Chris

_________________________________________________________________
More photos; more messages; more whatever – Get MORE with Windows Live™ Hotmail®. NOW with 5GB storage.
http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_5G_0907
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/mapserver-users/attachments/20070917/588b6841/attachment.html


More information about the mapserver-users mailing list