public function Plot($center = NULL, $scale = NULL, $downloadFileName = NULL) { $legendWidthPx = 250; $legendWidthIn = 0; if ($this->showLegend) { $legendWidthIn = MgUtils::PxToIn($legendWidthPx, $this->legendDpi); } // Create new PDF document, the default "PDF_UNIT" value is "mm" $this->pdf = new TCPDF($this->orientation, PDF_UNIT, $this->paperType, true, "UTF-8", false); $this->font = "dejavusans"; $this->pdf->AddFont($this->font); // Set margins $this->pdf->SetMargins(0, 0, 0); $this->pdf->SetHeaderMargin(0); $this->pdf->SetFooterMargin(0); // Prevent adding page automatically $this->pdf->SetAutoPageBreak(false); // Remove default header/footer $this->pdf->setPrintHeader(false); $this->pdf->setPrintFooter(false); // Set default font size $this->pdf->SetFont($this->font, "", 16); // Add a page $this->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 = $this->DrawTitle(); $mScale = NULL; if ($this->showScaleBar) { // Draw Scale $mScale = $this->DrawScale($scale); } // Draw declaration if ($this->showDisclaimer && strlen($this->disclaimer) > 0) { $offX = $mScale != NULL ? $mScale->x + $mScale->w : 0; $mDec = $this->DrawDeclaration($offX, $legendWidthIn); } else { $mDec = new MgPdfPlotMetrics(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 = $this->pdf->getPageHeight() - ($mDec->h - ($mScale != NULL ? $mScale->h : 0)) - $this->margin[0] - $this->margin[1]; //var_dump($idealHeight); //var_dump($printSize); //die; if ($idealHeight < $this->printSize->height) { } $this->printSize->height = $idealHeight; $idealWidth = $this->pdf->getPageWidth() - $this->margin[2] - $this->margin[3]; if ($this->showLegend) { $idealWidth -= $legendWidthIn; } if ($idealWidth < $this->printSize->width) { } $this->printSize->width = $idealWidth; $link = ""; $align = ""; $resize = false; $palign = ""; $ismask = false; $imgmask = false; $border = 1; $fitbox = false; $hidden = false; $fitonpage = false; // Draw legend if specified if ($this->showLegend) { $legendfilelocation = $this->RenderLegend(MgUtils::InToPx($legendWidthIn, $this->legendDpi), MgUtils::InToPx($this->printSize->height, $this->legendDpi)); $this->pdf->Image($legendfilelocation, $this->margin[2], $this->margin[0], $legendWidthIn, $this->printSize->height, MgImageFormats::Png, $link, $align, $resize, $this->dpi, $palign, $ismask, $imgmask, $border, $fitbox, $hidden, $fitonpage); @unlink($legendfilelocation); } if ($this->bLayered) { $layerNames = array(); $tiledGroupNames = array(); $mapLayers = $this->map->GetLayers(); $mapGroups = $this->map->GetLayerGroups(); //Collect all visible layers for ($i = $mapLayers->GetCount() - 1; $i >= 0; $i--) { $layer = $mapLayers->GetItem($i); if ($layer->IsVisible() && $layer->GetLayerType() == MgLayerType::Dynamic) { array_push($layerNames, $layer->GetName()); } } for ($i = $mapGroups->GetCount() - 1; $i >= 0; $i--) { $group = $mapGroups->GetItem($i); if ($group->IsVisible() && $group->GetLayerGroupType() != MgLayerGroupType::Normal) { array_push($tiledGroupNames, $group->GetName()); } } $bgColor = new MgColor("FFFFFF00"); //Turn off all layers and tiled groups first for ($i = 0; $i < $mapGroups->GetCount(); $i++) { $group = $mapGroups->GetItem($i); if ($group->GetLayerGroupType() != MgLayerGroupType::Normal) { $group->SetVisible(false); } } for ($i = 0; $i < $mapLayers->GetCount(); $i++) { $layer = $mapLayers->GetItem($i); if ($layer->GetLayerType() == MgLayerType::Dynamic) { $layer->SetVisible(false); } } //Plot this map background $filelocation = $this->RenderMap(MgUtils::InToPx($this->printSize->width, $this->dpi), MgUtils::InToPx($this->printSize->height, $this->dpi), $center, $scale); // Draw Map background $this->pdf->Image($filelocation, $this->showLegend ? $this->margin[2] + $legendWidthIn : $this->margin[2], $this->margin[0], $this->printSize->width, $this->printSize->height, MgImageFormats::Png, $link, $align, $resize, $this->dpi, $palign, $ismask, $imgmask, $border, $fitbox, $hidden, $fitonpage); @unlink($filelocation); $prevLayerName = NULL; $prevGroupName = NULL; //Plot each tiled group individually foreach ($tiledGroupNames as $groupName) { if ($prevGroupName != NULL) { $mapGroups->GetItem($prevGroupName)->SetVisible(false); } $mapGroups->GetItem($groupName)->SetVisible(true); $print = true; $view = true; $lock = false; $this->pdf->startLayer($groupName, $print, $view, $lock); $filelocation = $this->RenderMap(MgUtils::InToPx($this->printSize->width, $this->dpi), MgUtils::InToPx($this->printSize->height, $this->dpi), $center, $scale, $bgColor); // Draw Map $this->pdf->Image($filelocation, $this->showLegend ? $this->margin[2] + $legendWidthIn : $this->margin[2], $this->margin[0], $this->printSize->width, $this->printSize->height, MgImageFormats::Png, $link, $align, $resize, $this->dpi, $palign, $ismask, $imgmask, $border, $fitbox, $hidden, $fitonpage); @unlink($filelocation); $prevGroupName = $groupName; $this->pdf->endLayer(); } //Now plot each layer individually foreach ($layerNames as $layerName) { if ($prevLayerName != NULL) { $mapLayers->GetItem($prevLayerName)->SetVisible(false); } $mapLayers->GetItem($layerName)->SetVisible(true); $print = true; $view = true; $lock = false; $this->pdf->startLayer($layerName, $print, $view, $lock); $filelocation = $this->RenderMap(MgUtils::InToPx($this->printSize->width, $this->dpi), MgUtils::InToPx($this->printSize->height, $this->dpi), $center, $scale, $bgColor); // Draw Map $this->pdf->Image($filelocation, $this->showLegend ? $this->margin[2] + $legendWidthIn : $this->margin[2], $this->margin[0], $this->printSize->width, $this->printSize->height, MgImageFormats::Png, $link, $align, $resize, $this->dpi, $palign, $ismask, $imgmask, $border, $fitbox, $hidden, $fitonpage); @unlink($filelocation); $prevLayerName = $layerName; $this->pdf->endLayer(); } } else { $filelocation = $this->RenderMap(MgUtils::InToPx($this->printSize->width, $this->dpi), MgUtils::InToPx($this->printSize->height, $this->dpi), $center, $scale); // Draw Map $this->pdf->Image($filelocation, $this->showLegend ? $this->margin[2] + $legendWidthIn : $this->margin[2], $this->margin[0], $this->printSize->width, $this->printSize->height, MgImageFormats::Png, $link, $align, $resize, $this->dpi, $palign, $ismask, $imgmask, $border, $fitbox, $hidden, $fitonpage); @unlink($filelocation); } // Draw coordiates if specified $mExt = NULL; if ($this->showCoordinates) { // Draw Extent coordinates $mExt = $this->DrawExtentCS($legendWidthIn); } $this->app->response->header("Content-Type", "application/pdf"); $mode = 'I'; $name = 'Map.pdf'; if (strlen($this->title) > 0) { $name = $this->title . '.pdf'; } if ($downloadFileName != NULL) { $mode = 'D'; $name = $downloadFileName; } // Close and output PDF document $this->pdf->Output($name, $mode); }