width = $printSize->width - $legendWidth;
}
// 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, $printDpi)."&HEIGHT=".InToPx($printSize->height, $printDpi);
} 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;
// Create new PDF document, the default "PDF_UNIT" value is "mm"
$pdf = new TCPDF($orientation, PDF_UNIT, $paperType, true, "UTF-8", false);
$font = "dejavusans";
// Set margins
$pdf->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();
// 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 Map first, so if the margin is not enough for the Text, the Text will be displayed about the image
$pdf->Image($filelocation, ($margin[2] + $legendWidth), $margin[0], $printSize->width, $printSize->height, "PNG", "", "", false, $printDpi, "", false, false, 1, false, false, false);
// Draw Title
DrawTitle();
if ($showCoordinates) {
// Draw Extent coordinates
DrawExtentCS();
}
if ($showScaleBar) {
// Draw Scale
DrawScale();
}
// Draw declaration
DrawDeclaration();
// Close and output PDF document
$pdf->Output($title.'.pdf', 'I');
?>
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;
//