SetMargins(0, 0, 0);
$pdf->SetHeaderMargin(0);
$pdf->SetFooterMargin(0);
// Prevent adding page automatically
$pdf->SetAutoPageBreak(false);
// Remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// Set default font size
$pdf->SetFont($font, "", 16, "", true);
// Add a page
$pdf->AddPage();
// The print size determines the size of the PDF, not the size of the map and legend images
// we want to request back to put into this PDF.
//
// What that means is that we should draw the surrounding print elements first (title, scale, disclaimer),
// then adjust the image request sizes to ensure they (and element drawn on top like coordinates) will fit
// correctly in the remaining space.
//
// Title, scale and disclaimer rendering will all return Metrics objects that will give us the information
// needed for the size adjustments
// Draw Title
$mTitle = DrawTitle();
$mScale = NULL;
if ($showScaleBar) {
// Draw Scale
$mScale = DrawScale();
}
// Draw declaration
if ($showDisclaimer)
$mDec = DrawDeclaration(($mScale != NULL) ? ($mScale->x + $mScale->w) : 0);
else
$mDec = new Metrics(0, 0, 0, 0);
// Adjust width and height of the images we want to request to compensate for surrounding print elements that have been rendered
// Check the size of the disclaimer and adjust height
$idealHeight = $pdf->getPageHeight() - ($mDec->h - ($mScale != NULL ? $mScale->h : 0)) - $margin[0] - $margin[1];
//var_dump($idealHeight);
//var_dump($printSize);
//die;
if ($idealHeight < $printSize->height);
$printSize->height = $idealHeight;
$idealWidth = $pdf->getPageWidth() - $margin[2] - $margin[3];
if ($idealWidth < $printSize->width);
$printSize->width = $idealWidth;
// Construct the querysting which can be used to generate the Map image
$query_string = "session_id=".$_POST['sessionId']."&map_name=".$_POST['mapName']."&print_size=".$printSize->width.",".$printSize->height.
"&print_dpi=".$_POST['dpi']."&box=".$_POST['box']."&normalized_box=".$_POST['normalizedBox'].
"&scale_denominator=".$_POST['scaleDenominator']."&rotation=".$_POST['rotation']."&northarrow=".($showNorthArrow ? "1" : "0");
// Construct the querystring which can be used to generate the legend
if ($showLegend) {
if (strcmp($legendType, "original") == 0) {
$legend_query_string = "OPERATION=GETMAPLEGENDIMAGE&VERSION=1.0.0&FORMAT=PNG&SESSION=".$_POST["sessionId"]."&MAPNAME=".$_POST["mapName"]."&WIDTH=".InToPx($legendWidth, $legendDpi)."&HEIGHT=".InToPx($printSize->height, $legendDpi);
} else {
$legend_query_string = "session_id=".$_POST['sessionId']."&map_name=".$_POST['mapName']."&width=".InToPx($legendWidth, $printDpi)."&height=".InToPx($printSize->height, $printDpi);
}
}
$filelocation = "";
$legendfilelocation = "";
if("80" === $port)
{
$filelocation = $protocol.$host.$pathString.$generatePage.$query_string;
if ($showLegend)
$legendfilelocation = $protocol.$host.$legendPathString.$generateLegend.$legend_query_string;
}
else
{
$filelocation = $protocol.$host.":".$port.$pathString.$generatePage.$query_string;
if ($showLegend)
$legendfilelocation = $protocol.$host.":".$port.$legendPathString.$generateLegend.$legend_query_string;
}
//Uncomment to see the legend and map image urls
//var_dump($filelocation);
//var_dump($legendfilelocation);
//die;
// Draw Map
$pdf->Image($filelocation, ($margin[2]), $margin[0], $printSize->width, $printSize->height, "PNG", "", "", false, $printDpi, "", false, false, 1, false, false, false);
// Draw legend if specified
if ($showLegend) {
$pdf->Image($legendfilelocation, $margin[2], $margin[0], $legendWidth, $printSize->height, "PNG", "", "", false, $printDpi, "", false, false, 1, false, false, false);
}
// Draw coordiates if specified
$mExt = NULL;
if ($showCoordinates) {
// Draw Extent coordinates
$mExt = DrawExtentCS();
}
// Close and output PDF document
if (strlen($title) == 0)
$pdf->Output('Map.pdf', 'I');
else
$pdf->Output($title.'.pdf', 'I');
?>
x = $x;
$this->y = $y;
$this->w = $w;
$this->h = $h;
}
}
class Size
{
public $width;
public $height;
public function __construct($width, $height)
{
$this->width = $width;
$this->height = $height;
}
}
function ParseLocaleDouble($stringValue)
{
$lc = localeconv();
$result = str_replace(".", $lc["decimal_point"], $stringValue);
return doubleval($result);
}
function InToPx($in, $dpi) {
return ($in * $dpi) / 25.4;
}
function PxToIn($px, $dpi) {
return ($px * 25.4) / $dpi;
}
//This function try to get a more elegant number for the scale bar display.
//For example, convert 5.3 to 5, 5.5 to 6, 13 to 10, 230 to 200 and 1234 to 1200.
//Basically no number will execced 9999 in scale bar display, however we support that situation
//the minimum number for the return value is 0
function GetRoundNumber($number)
{
$number = abs($number);
$temp = $number = round($number);
$len = 0;
while($temp > 0)
{
$len++;
$temp /= 10;
$temp = floor($temp);
}
//10,20,30,40,50,60,70,80,90
if( 2 === $len )
{
$number = $number / 10;
$number = round($number);
$number = $number * 10;
}
//100,200,300,400,500,600,700,800,900
if( $len >= 3 )
{
$number = $number / 100;
$number = round($number);
$number = $number * 100;
}
//else, just 1,2,3,4,5,6,7,8,9
return $number;
}
function DrawScale()
{
global $pdf,$margin,$font,$scale;
$pageHeight = $pdf->getPageHeight();
$paddingBottom = 7; $textPadding = 5; $fontSize = 6;
$style = array("width" => 0.4, "cap" => "butt", "join" => "miter", "dash" => 0, "color" => array(0, 0, 0));
$start_x = ParseLocaleDouble($margin[2]);
$start_y = $pageHeight - $paddingBottom;
$lineMark_h = 3;
$textMarkPadding = 1.0;
//