All pastes #794411 Raw Edit

Miscellany

public text v1 · immutable
#794411 ·published 2007-11-23 03:01 UTC
rendered paste body
<?
//version: 1195772503

$db['hostname'] = 'localhost';
$db['username'] = 'user';
$db['password'] = 'pass';
$db['database'] = 'opensim';

mysql_connect($db['hostname'],$db['username'],$db['password']);
@mysql_select_db($db['database']) or die( "Unable to select database");
$query = "SELECT regionName, locX, locY FROM regions ORDER BY locX ASC, locY DESC, regionName DESC;";
$result = mysql_query($query);


while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
{
	$regions[$row['regionName']] = array('locX' => $row['locX'], 'locY' => $row['locY']);
}

mysql_close();

//Width and height of each region
$regionSize = 75;

//Center on a coordinate
$centerX = 9994;
$centerY = 10007;

//set X, Y upper bounds
$maxX = 10010;
$maxY = 10007;

//set X, Y lower bounds
$minX = 9994;
$minY = 9993;

//Create an image, properly sized
$imageWidth = (($maxX-$minX)*$regionSize);
$imageHeight = (($maxY-$minY)*$regionSize);

$heading = '<?xml version="1.0" encoding="UTF-8" standalone="no"?> <svg 

xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.0" 

width="'.$imageWidth.'" height="'.$imageHeight.'" id="svg2">';

//foreach region, plot square at position in image multiplied by region width
foreach($regions as $regionName => $coords)
{
	if($coords['locX'] > $minX AND $coords['locX'] < $maxX)
	{
		if($coords['locY'] > $minY AND $coords['locY'] < $maxY)
		{
			$rectangles .= '<rect width="'.$regionSize.'" height="'.$regionSize.'" x="'.

($coords['locX']-$centerX)*$regionSize.'" y="'.(($coords['locY']-$centerY)*$regionSize*(-1)).'" 

style="opacity:1;fill:#00ff00;fill-opacity:1;stroke:#000000;stroke-width:1.00430417;stroke-

linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" 

id="'.$regionName.'_rectangle" />';

			$text .= '<text id="'.mt_rand().'"><tspan x="'.((($coords['locX']-$centerX)

*$regionSize)).'" y="'.(((($coords['locY']-$centerY)*$regionSize*(-1)))+($regionSize/2)).'" 

style="font-size:9px;font-family:Serif" id="'.$regionName.'_text">'.$regionName.'</tspan></text>';
		}
	}
}

$ending = '</svg>';

$stringData = $heading.$rectangles.$text.$ending;
$fh = fopen('map2.svg', 'w');
fwrite($fh, $stringData);
fclose($fh);

echo '<body bgcolor="#666666"><center><EMBED SRC="map2.svg" width="95%" height="95%">'


?>