private function DrawScale($ovScale = NULL) { $pageHeight = $this->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 = MgUtils::ParseLocaleDouble($this->margin[2]); $start_y = $pageHeight - $paddingBottom; $lineMark_h = 3; $textMarkPadding = 1.0; //<editor-fold defaultstate="collapsed" desc="print the scale bar with meter"> $unit = "m"; $imageSpan = 20; // the 20 is a suggested scale bar length $scale = $this->scaleDenominator; if ($ovScale != NULL) { $scale = $ovScale; } $realSpan = $scale * 0.02; // $imageSpan / 1000 if ($realSpan >= 1000) { $unit = "km"; $realSpan /= 1000; $realSpan = MgUtils::GetRoundNumber($realSpan); $imageSpan = $realSpan * 1000000 / $scale; } else { $realSpan = MgUtils::GetRoundNumber($realSpan); $imageSpan = $realSpan * 1000 / $scale; } $end_x = $start_x + $imageSpan; $end_y = $start_y; $meterTextMark = $realSpan . " " . $unit; $this->pdf->SetFont($this->font, "", $fontSize, "", true); $this->pdf->Line($start_x, $start_y, $end_x, $end_y, $style); $this->pdf->Line($start_x, $start_y, $start_x, $start_y - $lineMark_h, $style); $this->pdf->Line($end_x, $end_y, $end_x, $end_y - $lineMark_h, $style); $fontSize = 7; $textHeight = 4; $this->pdf->SetFont($this->font, "", $fontSize, "", true); $this->pdf->Text($start_x + $textMarkPadding, $start_y - $textHeight, $meterTextMark); $textStart_x = $end_x; //</editor-fold> //<editor-fold defaultstate="collapsed" desc="print the scale bar with feet"> $unit = "ft"; $aFeetPerMeter = 3.2808; $aFeetPerMile = 5280; $aMeterPerFeet = 0.3048; $imageSpan = 20; // the 20 is a suggested scale bar length, in "mm" $realSpan = $scale * $imageSpan / 1000 * $aFeetPerMeter; if ($realSpan > $aFeetPerMile) { $unit = "mi"; $realSpan /= $aFeetPerMile; $realSpan = MgUtils::GetRoundNumber($realSpan); $imageSpan = $realSpan * $aFeetPerMile * $aMeterPerFeet * 1000 / $scale; } else { $realSpan = MgUtils::GetRoundNumber($realSpan); $imageSpan = $realSpan * $aMeterPerFeet * 1000 / $scale; } $end_x = $start_x + $imageSpan; $end_y = $start_y; $feetTextMark = $realSpan . ' ' . $unit; $this->pdf->Line($start_x, $start_y, $end_x, $end_y, $style); $this->pdf->Line($start_x, $start_y, $start_x, $start_y + $lineMark_h, $style); $this->pdf->Line($end_x, $end_y, $end_x, $end_y + $lineMark_h, $style); $this->pdf->SetFont($this->font, "", $fontSize, "", true); $this->pdf->Text($start_x + $textMarkPadding, $start_y + 1, $feetTextMark); //</editor-fold> //determine where to begin to print the absolute scale and date info if ($end_x > $textStart_x) { $textStart_x = $end_x; } $textStart_x += $textPadding; //write the scale $fontSize = 8; $this->pdf->SetFont($this->font, "", $fontSize, "", true); $scaleText = "Scale 1:" . $scale; $this->pdf->Text($textStart_x, $end_y + 0.2, $scaleText); //write the date $date = date("M/d/Y"); $this->pdf->Text($textStart_x + 0.3, $end_y - 3.8, $date); return new MgPdfPlotMetrics($this->margin[2], $start_y, $textStart_x, $end_y + 0.2 - $start_y); }