Map.php


Posted on 16th Feb 2014 07:03 pm by admin

I am a complete beginner to PHP and am looking for some help with a program I am messing around with.

I found this incomplete source code, and I wanted to finish it, but I have no idea what I am doing.
It looks like all you need to do to complete it is write the Set functions in the 3rd file. I have been searching the internet for hours and cant find anything that seemed to help.
If someone could show me how to set these functions up that would be so great!


Code: [Select]//map.php
<html><title>
CS-430: Map
</title>
<style type=text/css>
.radH1 {
border-right:1px solid black;
border-bottom:1px solid black;
color:#0000BB;
font-family:serif;
font-size:larger;
font-weight:bolder;
}
.radH2 {
border-bottom:1px solid black;
color:#880000;
font-weight:bold;
}
.radH3 {
border-bottom:1px solid black;
color:#0000BB;
}
.radDiv {
text-align:left;
padding-right:3px;
white-space:nowrap;
}
.radE2 {
color:#880000;
font-weight:bold;
}
.radE3 {
color:#0000BB;
}
.radTab {
padding-right:1px;
padding-left:1px;
padding-top:0px;
padding-bottom:0px;
background-color:#FFFFBB;
border:1px solid black;
margin-top:0px;
margin-bottom:0px;
font-size:small;
}
.pad0 {
margin:0;
padding:0;
border:0;
}
.divAll {
margin-top:0px;
overflow:hidden;
padding:0px;
border: 1px solid black;
}
.divDot {
margin:0;
padding:0;
border:0;
position:relative;
width:7px;
height:7px;
line-height:1px;
font-size:1px;
z-index:4;
background-repeat:no-repeat;
}
.divImg {
position:relative;
top:-7;
left:0;
z-index:1;
}
.imgMap {
margin:0px;
}
.smll {
font-size:small;
}
</style>
<body>
<TABLE class=pad0>
<TR><TD VALIGN=TOP ALIGN=CENTER>
<h2>CS-430: Map </h2>

<?php
//-------------------------------------------------------------
// Locations are a value-pair, often stored in an array of two values:
// [0] Longitude: East/West location (pixel column in an image)
// [1] Latitude: North/South Location (pixel row in an image)
//
// Terms used for various ways of expressing locations:
// Mix A pixel value within a map.
// Tix A pixel value within a tile of a map.
// UTM A location expressed as UTM value (in zone 15).
// Rad A location expressed in radians.
// Deg A location expressed in degrees.
// All locations use WGS-84/NAD87 (which are very close) .
//
// Abbreviations used for image/tile corners:
// ul UpperLeft
// ur UpperRight
// lr LowerRight
// ll LowerLeft
//-------------------------------------------------------------

//------------------------------------------------------------------
// Uncomment the following two lines to have PHP error messages
// display on the web page. Use only for debugging.
//------------------------------------------------------------------
error_reporting(E_ALL);
ini_set("display_errors", 1);

//--------------------------------------------------------------------------
// Global variables:
// ICON_URL: URL of directory containing all icons
// IMAGES_URL: URL of directory containing all images
// TILE_URL_FORMAT: An sprintf format string for generating
// the URL of a "tile" image file given the
// following four paramters:
// zoom, type, upper-left-pix-col, upper-left-pix-row
// DISP_SZ: Size in pixels of the image display window
// TILE_INC: Size in pixels of the interval between tiles
// MAP_DATA: Size and georeferencing data for each
// complete image, set in function SetMapData
//--------------------------------------------------------------------------
$ICON_URL = "http://w3.cs.jmu.edu/arch/crs/cs430-php/icons";
$IMAGES_URL = "http://w3.cs.jmu.edu/arch/crs/cs430-php/images";
$TILE_URL_FORMAT = "$IMAGES_URL" . '/%2$s-%1$s-tiles/%2$s-%1$s-%3$sx%4$s.png';
$DISP_SZ = array(832, 608);
$TILE_INC = array(64, 64);

include 'lib/data.php';
include 'lib/util.php';
include 'lib/guts.php';
include 'lib/loc.php';
include 'lib/utm.php';

SetMapData();

$rtrn = SetMap("t", "64mp");
$mapType = $rtrn[0];
$mapZoom = $rtrn[1];
$mapData = $MAP_DATA[$mapType][$mapZoom];

$curDeg = SetDeg($mapData);

$rtrn = GetTileInfo($curDeg, $mapType, $mapZoom);
$tileUrl = $rtrn[0];
$mixTile = $rtrn[1];

OutputZoomTable($mapType, $mapZoom, $curDeg);

echo ("<span class=smll>mp:meters/pixel</span>n");
echo ("<p><b>Location</b>
Lon: $curDeg[0]
Lat: $curDeg[1]n");

echo ("</TD><TD>n");

GotoIsmap($curDeg, $mapData, $mapType, $mapZoom, $mixTile, $tileUrl);

echo ("$tileUrl
n");
?>


</TD></TR></TABLE>
</body></html>
Code: [Select]
// lib/data.php
<?php

//=====================================================================
// The global variable MAP_DATA defines data about the complete
// images for each type/zoom. $MAP_DATA is a 3d array.
// * The first index indicates a map type (currently there is only one map
// type: 't').
// * The second index specifies an image file by its zoom.
// * The third index specifies an array of 2 values as follows:
// 0: size of map in pixels (mix) (width, length)
// 1: upper-left degree (longitude, latitude) (e/w, n/s)
// 2: upper-right degree (longitude, latitude)
// 3: lower-right degree (longitude, latitude)
// 4: lower-left degree (longitude, latitude)
// 5: upper-left utm (longitude, latitude)
// 6: upper-right utm (longitude, latitude)
// 7: lower-right utm (longitude, latitude)
// 8: lower-left utm (longitude, latitude)
// This function initializes the array.
// The code at the end of this function computes entries 1-4 from 5-8.
//=====================================================================
function SetMapData()
{
global $MAP_DATA;

$MAP_DATA['t']['32mp'] = array(
0 => array(3328,2432),
5 => array(550996.855, 5397000.883),
6 => array(657567.642, 5397000.883),
7 => array(657567.642, 5319176.883),
8 => array(550996.855, 5319176.883),
0);
$MAP_DATA['t']['64mp'] = array(
array(1664,1216),
5 => array(550996.855, 5397000.883),
6 => array(657567.642, 5397000.883),
7 => array(657567.642, 5319176.883),
8 => array(550996.855, 5319176.883),
0);
$MAP_DATA['t']['128mp'] = array(
array(832,608),
5 => array(550996.855, 5397000.883),
6 => array(657567.642, 5397000.883),
7 => array(657567.642, 5319176.883),
8 => array(550996.855, 5319176.883),
0);

$tKeys = array_keys($MAP_DATA);
foreach ($tKeys as $tKey)
{
$zKeys = array_keys($MAP_DATA[$tKey]);
foreach ($zKeys as $zKey)
{
for ($jj=1; $jj<=4; $jj++)
$MAP_DATA[$tKey][$zKey][$jj] = UTM2deg($MAP_DATA[$tKey][$zKey][$jj+4]);
}
}
}
Code: [Select]
// lib/guts.php
<?php

//=========================================================================
// The web page uses two map parameters as follows:
//
// $_GET['type'] The type of the current map (a string).
// $_GET['zoom'] The zoom of the current map (a string).
//
// This function returns an array of two containing the type and zoom
// values of the current map. If set, the values specified by the GET
// parameters are used. If a GET parameter is not specified, the
// default values are used.
//
// Return:
// $result: An array of two strings, the type and zoom values
//=========================================================================

function SetMap
(
$defaultType, // Default type (string)
$defaultZoom // Default zoom (string)
) {
global $_GET;

// Replace this line with the code that implements this function.
}


//=========================================================================
// The web page uses two location parameters as follows:
//
// $_GET['new'] The location that should be the display's new location. The value
// is specified in the form 'col1,row1?col2,row2' where
// 'col1'/'row1' are the pixel in the map (mix) of
// the upper-left corner of a tile and 'col2'/'row2' are the pixel
// location within the tile (tix).
//
// $_GET['loc'] The maps previous location in the form 'long,lat' where
// 'long' is the longitude in degrees and 'lat' is the latitude
// in degrees.
//
// This function returns an array of two containing the degree
// location for the dot on the map. If 'new' is specifed, the dot is set
// to be the value specified by 'new' (the mix/tix value must be converted
// to degrees). If 'new' is not specified, the value specified for 'loc' is
// used. If neither is specified, the center of the current map is used
// (the degree location is computed from the mix value of the center of
// the map).
//
// Each returned degree value should be truncated to be at most 10 characters.
//
// Return:
// $deg The degree location (array of 2).
//=========================================================================

function SetDeg
(
$mapData // The map data (array of 9).
) {
global $_GET;

// Replace this line with the code that implements this function.
}

//============================================================================
// Return the URL and "tix" of the tile for this degree location for
// the specified map.
// The correct "tile" is the tile that best centers the current location
// in itself. Tiles are found on $TILE_INC boundaries of the complete map.
//
// Return:
// $rtrn[0] = URL of the "tile" file.
// $rtrn[1] = pixel location in the map of the upper left corner of the tile.
//============================================================================

function GetTileInfo
(
$deg, // Get tile for this degree location (array of 2)
$type, // Map type
$zoom // Map zoom
) {
global $TILE_URL_FORMAT;
global $MAP_DATA;
global $DISP_SZ;
global $TILE_INC;

// Replace this line with the code that implements this function.
}

//---------------------------------------------------------------------------
// Output HTML of the following form:
//
// <table class=radTab>
// <tr>
// <th align=left class=radH1>Zoom</th>
// <td align=center class=RADH>TYPE</td>
// ...
// </tr>
// <div class=radDiv><tr>
// <td class=RADE>ZOOM</td>
// <td><a href='?type=TYPE&zoom=ZOOM&loc=LON,LAT' class=pad0>
// <img src=RADIO class=pad0>
// </a></td>
// ...
// </tr></div>
// ...
// </table>
//
// The first row of the table has labels for the map types.
// The first column of the table has labels for the zoom levels.
// The first and second ... above indicates the <td>...</td> above it
// is repeated for each type of map. The last ... indicates there is a
// <div>...</div> entry for each zoom level.
//
// The ITEMS in all uppercase above represent the following:
//
// TYPE The type for that column.
// ZOOM The zoom for that row.
// RADH The string "radH2" if the current type matches the column type,
// otherwise the string "radH3".
// RADE The string "radE2" if the current zoom matches the row zoom,
// otherwise the string "radE3".
// LON The current degree longitude
// LAT The current degree latitude
// RADIO The string "$ICON_URL/radio-on.png" if the current type and
// zoom match the col/row type/zoom, otherwise
// "$ICON_URL/radio-off.png".
//---------------------------------------------------------------------------
function OutputZoomTable
(
$mapType,
$mapZoom,
$curDeg
) {
global $MAP_DATA;
global $ICON_URL;

// Replace this line with the code that implements this function.
}


//---------------------------------------------------------------------------
// Output HTML of the following form:
//
// <Div align=left valign=top class=divAll style='width:WIDTH; height:HEIGHT; max-height:HEIGHT;'>
// <!-- Center Dot -->
// <div class=divDot
// style='left:DOTCOL; top:DOTROW; background-image:url($ICON_URL/mark-dot.png);' ><!----></div>
// <!-- Map Image -->
// <div class=divImg style='width:WIDTH; height:HEIGHT;'>
// <a href=?type=TYPE&zoom=ZOOM&new=TILECOL,TILEROW>
// <img ismap border=0 src=TILE_URL
// alt='[TILE_URL]' class=imgMap style='width:WIDTH; height:HEIGHT;'></a>
// </div></Div>

// The ITEMS in all uppercase above represent the following:
//
// WIDTH Width in pixels of the display area.
// HEIGHT Height in pixels of the display area.
//
// DOTCOL The pixel location within the tile of the upper left corner
// DOTROW of the dot that indicates the current location. The dot is
// 8 pixels square. So for example, if the center of the dot
// should be at pixel 100,150 of the tile, the upper left corner
// of the pixel should at at 96,146.
// TILECOL The pixel location within the map of the upper left corner of
// TILEROW the tile.
//
// TILEURL The URL of the tile to be displayed.
// TYPE The type of this map.
// ZOOM The zoom of this map.
//---------------------------------------------------------------------------
function GotoIsmap
(
$deg, // The current location in degrees
$mapData, // The array of data about the current map
$mapType, // The current map type.
$mapZoom, // The current map zoom
$mixTile, // The pixel location in the map of this tile.
$tileUrl // The URL of the tile image
) {
global $ICON_URL;
global $DISP_SZ;

$dotSz = 8;

// Replace this line with the code that implements this function.
}
?>
There are 3 other files that come with this code. I didn't think they were important to the set functions, but if anyone would like to see them, let me know.

No comments posted yet

Your Answer:

Login to answer
86 Like 37 Dislike
Previous forums Next forums
Other forums

Regarding accessing SQL query issued by any user in Oracle 10g
Hi all,
i want to know the queries issued by various users accessing a database...

Problem with PHP code- simple contact form
I'm relativily new to PHP; I know HTML and CSS stuff but I have a problem- I have a contact form wit

Calculating a rating by adding number of points and dividing by number of items
I have a site that users can post links to files to download. They can rate these files on a 1-5 sca

Hotlinking Picasa as the image folder of a website
Hi there PHP freaks, I would like to create a private album in Picasa to use it as the image folder

Need help with some php code :)
Hey! I'm quite new to this whole thing, so please don't fire me with shait on this one =D

I'm

php title problem
Hi,

I am having a problem managing my page title with PHP.

Currently I have my <

PHP Code To Change Font Color in Table Cell
I would appreciate help with the following snippet of my php code. I am just trying to change the f

Breaking results into week blocks
I have a set of dates (and times), which are returned from a mySQL query.

These usually span

Code working in IE but not FireFox
I created a dynamic navigation list for my website based off of a table in my database. The code is

how to export excel file in same server
My first post - php newbie, so appreciate your support.

I'm currently using headers to save w

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash