[Mapbender-commits] r8090 - in trunk/mapbender/http/print: . classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Aug 31 08:17:04 EDT 2011
Author: verenadiewald
Date: 2011-08-31 05:17:04 -0700 (Wed, 31 Aug 2011)
New Revision: 8090
Modified:
trunk/mapbender/http/print/classes/mbMeasureDecorator.php
trunk/mapbender/http/print/print_functions.php
Log:
http://trac.osgeo.org/mapbender/ticket/855
Modified: trunk/mapbender/http/print/classes/mbMeasureDecorator.php
===================================================================
--- trunk/mapbender/http/print/classes/mbMeasureDecorator.php 2011-08-31 12:15:28 UTC (rev 8089)
+++ trunk/mapbender/http/print/classes/mbMeasureDecorator.php 2011-08-31 12:17:04 UTC (rev 8090)
@@ -3,23 +3,23 @@
protected $pageElementType = "measure";
protected $elementId;
-
+
public function __construct($pdfObj, $elementId, $mapConf, $controls) {
parent::__construct($pdfObj, $mapConf, $controls);
$this->elementId = $elementId;
- $this->override();
+ $this->override();
$this->decorate();
}
-
+
public function override() {}
-
+
public function decorate() {
include (dirname(__FILE__)."/../print_functions.php");
-
+
global $mapOffset_left, $mapOffset_bottom, $map_height, $map_width, $coord;
global $yAxisOrientation;
$yAxisOrientation = 1;
-
+
if (isset($_REQUEST["measured_x_values"]) && $_REQUEST["measured_x_values"] != "") {
$x_value_str = $_REQUEST["measured_x_values"];
$y_value_str = $_REQUEST["measured_y_values"];
@@ -29,7 +29,7 @@
else {
return "No measurements found.";
}
-
+
$coord = mb_split(",",$this->pdf->getMapExtent());
$mapInfo = $this->pdf->getMapInfo();
foreach ($mapInfo as $k => $v) {
@@ -39,18 +39,18 @@
$mapOffset_bottom = $mapInfo["y_ul"];
$map_height = $mapInfo["height"];
$map_width = $mapInfo["width"];
-
+
// get the arrays, be aware of the different y-axis values
- $theFullArr = makeCoordPairs($x_value_str, $y_value_str);
+ $theFullArr = makeCoordPairsForFpdi($x_value_str, $y_value_str);
foreach ($theFullArr as $oneFullArr) {
$e = new mb_notice("mbMeasureDecorator: coordinates: ".implode(" ",array_values($oneFullArr)));
}
$thePolyArr = makePolyFromCoord($theFullArr);
$e = new mb_notice("mbMeasureDecorator: coordinates: ".implode(" ",$thePolyArr));
-
+
if (isClosedPolygon($theFullArr)) {
$isClosed = TRUE;
- }
+ }
else {
$isClosed = FALSE;
}
@@ -60,9 +60,9 @@
$this->pdf->objPdf->ClippingRect($mapOffset_left, $mapOffset_bottom, $map_width, $map_height, false);
if ($isClosed) {
$this->pdf->objPdf->Polygon($thePolyArr);
- }
+ }
else {
- $theStrokePointPairs = makeStrokePointPairs($theFullArr);
+ $theStrokePointPairs = makeStrokePointPairs($theFullArr);
for($i = 0; $i < count($theStrokePointPairs); $i++) {
$line = $theStrokePointPairs[$i];
$e = new mb_notice("mbMeasureDecorator: line coordinates: ".implode(" ",$line));
@@ -74,8 +74,8 @@
$this->pdf->objPdf->UnsetClipping();
}
-
+
}
?>
\ No newline at end of file
Modified: trunk/mapbender/http/print/print_functions.php
===================================================================
--- trunk/mapbender/http/print/print_functions.php 2011-08-31 12:15:28 UTC (rev 8089)
+++ trunk/mapbender/http/print/print_functions.php 2011-08-31 12:17:04 UTC (rev 8090)
@@ -1,58 +1,76 @@
<?php
/**
* $Id$
- *
+ *
* converts the coordinates created via the JavaScript
- * functions in 'mod_measure.php' into an array which
+ * functions in 'mod_measure.php' into an array which
* then holds both X- ans Y-values for each point in
- * the formats 'realworld coordinate' and 'pdf_coordinate'
- *
+ * the formats 'realworld coordinate' and 'pdf_coordinate'
+ *
* @param string commaseperated X-values of the points (realworld coordinate)
* @param string commaseperated Y-values of the points (realworld coordinate)
- *
+ *
* @return array Array looking like 0 => array(
* 'real_x' => 1234567,
* 'real_y' => 7654321,
* 'pdf_x' => 451.12,
- * 'pdf_y' => 254.7
+ * 'pdf_y' => 254.7
* )
- *
+ *
* @see transformForPDF
*
* @author M. Jansen <jansen at terrestris.de>, 2006-05-26
*/
function makeCoordPairs($x_values, $y_values) {
- $arr_x = explode(",", $x_values);
+ $arr_x = explode(",", $x_values);
$arr_y = explode(",", $y_values);
$x_elems = count($arr_x);
$y_elems = count($arr_y);
-
+
$the_return_arr = array();
-
+
if ($x_elems == $y_elems) {
for ($i = 0; $i < $x_elems; $i ++) {
- $the_return_arr[$i] = array(
- "real_x" => $arr_x[$i],
- "real_y" => $arr_y[$i],
- "pdf_x" => transformForPDF($arr_x[$i], "x"),
- "pdf_y" => transformForPDF($arr_y[$i], "y")
- );
- }
+ $the_return_arr[$i] = array(
+ "real_x" => $arr_x[$i],
+ "real_y" => $arr_y[$i],
+ "pdf_x" => transformForPDF($arr_x[$i], "x"),
+ "pdf_y" => transformForPDF($arr_y[$i], "y"));
+ }
}
-
+
return $the_return_arr;
} // end of function makeCoordPairs
+function makeCoordPairsForFpdi($x_values, $y_values) {
+ $arr_x = explode(",", $x_values);
+ $arr_y = explode(",", $y_values);
+ $x_elems = count($arr_x);
+ $y_elems = count($arr_y);
+ $the_return_arr = array();
+ if ($x_elems == $y_elems) {
+ for ($i = 0; $i < $x_elems; $i ++) {
+ $the_return_arr[$i] = array(
+ "real_x" => $arr_x[$i],
+ "real_y" => $arr_y[$i],
+ "pdf_x" => transformForPDFFpdi($arr_x[$i], "x"),
+ "pdf_y" => transformForPDFFpdi($arr_y[$i], "y"));
+ }
+ }
+
+ return $the_return_arr;
+} // end of function makeCoordPairsForFpdi
+
/**
- * Transforms given realworld-coordinate according to its type (X or Y)
+ * Transforms given realworld-coordinate according to its type (X or Y)
* into a pdf-coordinate. Needs the variables $mapOffset_left, $mapOffset_bottom,
* $map_height, $map_width, $coord to be defined in a global scope.
*
* @param float the realworld coordinate
* @param string type of coordinate either 'X' or 'Y'
- *
+ *
* @see makeCoordPairs [needs this function]
*
* @return float the pdf-coordinate
@@ -61,9 +79,9 @@
*/
function transformForPDF ($theRealCoord, $theType) {
global $mapOffset_left, $mapOffset_bottom, $map_height, $map_width, $coord;
-
+
$thePDFvalue = "";
-
+
switch (mb_strtolower($theType)) {
case 'x':
// calculate pdf x-pos:
@@ -75,7 +93,7 @@
case 'y':
// calculate pdf y-pos:
$real_shown_height = $coord[3] - $coord[1];
- $ratio_to_display = $map_height / $real_shown_height;
+ $ratio_to_display = ($map_height / $real_shown_height);
$target_height = $theRealCoord - $coord[1];
$thePDFvalue = $mapOffset_bottom + ($target_height * $ratio_to_display);
break;
@@ -87,16 +105,57 @@
return $thePDFvalue;
} // end of function transformForPDF
+/**
+ * Use for new template print with lib fpdi:
+ * Transforms given realworld-coordinate according to its type (X or Y)
+ * into a pdf-coordinate. Needs the variables $mapOffset_left, $mapOffset_bottom,
+ * $map_height, $map_width, $coord to be defined in a global scope.
+ *
+ * @param float the realworld coordinate
+ * @param string type of coordinate either 'X' or 'Y'
+ *
+ * @see makeCoordPairsForFpdi [needs this function]
+ *
+ * @return float the pdf-coordinate
+ *
+ * @author V. Diewald
+ */
+function transformForPDFFpdi ($theRealCoord, $theType) {
+ global $mapOffset_left, $mapOffset_bottom, $map_height, $map_width, $coord;
+ $thePDFvalue = "";
+ switch (mb_strtolower($theType)) {
+ case 'x':
+ // calculate pdf x-pos:
+ $real_shown_width = $coord[2] - $coord[0];
+ $ratio_to_display = $map_width / $real_shown_width;
+ $target_width = $theRealCoord - $coord[0];
+ $thePDFvalue = $mapOffset_left + ($target_width * $ratio_to_display);
+ break;
+ case 'y':
+ // calculate pdf y-pos:
+ $real_shown_height = $coord[3] - $coord[1];
+ $ratio_to_display = ($map_height / $real_shown_height);
+ $target_height = $theRealCoord - $coord[1];
+ $thePDFvalue = $mapOffset_bottom +($map_height- ($target_height * $ratio_to_display));
+ break;
+ default:
+ // a non valid parameter was given
+ $thePDFvalue = $theRealCoord;
+ break;
+ }
+ return $thePDFvalue;
+} // end of function transformForPDFFpdi
+
/**
- * extracts PDF-relevant information from a full coordinates array
+ * extracts PDF-relevant information from a full coordinates array
* and returns a transformed array
- *
+ *
* @param array the Array containing all infos about single coordinates
* created via makeCoordPairs()
- *
+ *
* @return array the array containing PDF-Values for a polygon
*
* @see makeCoordPairs
@@ -121,7 +180,7 @@
*
* @param array the Array containing all infos about single coordinates
* created via makeCoordPairs()
- *
+ *
* @return array the array containing PDF-Values for single lines
*
* @see makeCoordPairs
@@ -160,7 +219,7 @@
*
* @param array the Array containing all infos about single coordinates
* created via makeCoordPairs()
- *
+ *
* @return bool is it closed (TRUE || FALSE)
*
* @see makeCoordPairs
@@ -172,7 +231,7 @@
if ($coord_arr[0]['pdf_x'] == $coord_arr[$nr_of-1]['pdf_x']
&& $coord_arr[0]['pdf_y'] == $coord_arr[$nr_of-1]['pdf_y']
&& $nr_of != 1) {
- return TRUE;
+ return TRUE;
} else {
return FALSE;
}
@@ -183,7 +242,7 @@
/**
* Adds the measured item to the PDF output.
- *
+ *
* @param object reference (!) to the current ezPDF-Object
* @param string commaseperated X-Values of polygon / line
* @param string commaseperated Y-Values of polygon / line
@@ -208,7 +267,7 @@
$leg_img = imagecreate($legend_width, $legend_width);
// save previous state:
$thePDF->saveState();
-
+
// save colors for legend:
if(!defined("MAP_HAS_USER_POLYGON")) {
define("MAP_HAS_USER_POLYGON", "test");
@@ -217,22 +276,22 @@
// get the arrays
$theFullArr = makeCoordPairs($x_value_str, $y_value_str);
$thePolyArr = makePolyFromCoord($theFullArr);
-
+
if (isClosedPolygon($theFullArr)) {
$isClosed = TRUE;
- }
+ }
else {
$isClosed = FALSE;
}
$nr_of_points = count($theFullArr);
-
+
// is fill option set?
// wenn der erste und letzte punkt nicht �bereinstimmen,
// so muss in jedem Falle dofill auf 0 gesetzt werden
if($theConfArray['do_fill'] != '' && $isClosed) {
$doFill = 1;
// which color to use for filling?
- if (is_array($theConfArray['fill_color'])
+ if (is_array($theConfArray['fill_color'])
&& $theConfArray['fill_color']['r'] != ''
&& $theConfArray['fill_color']['g'] != ''
&& $theConfArray['fill_color']['b'] != '') {
@@ -250,11 +309,11 @@
// color to legend file
$bg_color = imagecolorallocate($leg_img, -1, -1, -1);
}
-
+
// Do we need to stroke (outline)?
if($theConfArray['do_stroke'] != '') {
// which color to use for filling?
- if (is_array($theConfArray['stroke_color'])
+ if (is_array($theConfArray['stroke_color'])
&& $theConfArray['stroke_color']['r'] != ''
&& $theConfArray['stroke_color']['g'] != ''
&& $theConfArray['stroke_color']['b'] != '') {
@@ -266,7 +325,7 @@
if ($i != count($theStrokePointPairs) - 1
|| $isClosed) {
$thePDF->line($line[0], $line[1], $line[2], $line[3]);
-
+
$stroke_color_legend_image = imagecolorallocate($leg_img, round($theConfArray['stroke_color']['r'] * 255), round($theConfArray['stroke_color']['g'] * 255), round($theConfArray['stroke_color']['b'] * 255));
if (is_array($theConfArray['line_style']['dash'])
&& $theConfArray['line_style']['dash'][1] != ""
@@ -280,16 +339,16 @@
imageline($leg_img, $legend_width-1, 0, $legend_width-1, $legend_width-1, $stroke_color_legend_image);
imageline($leg_img, $legend_width-1, $legend_width-1, 0, $legend_width-1, $stroke_color_legend_image);
imageline($leg_img, 0, $legend_width-1, 0, 0, $stroke_color_legend_image);
- }
- }
+ }
+ }
}
- }
+ }
}
-
+
$thePDF->polygon($thePolyArr, $nr_of_points, $doFill);
// eventually create the file:
imagepng($leg_img, $legendFilenameUserPolygon);
-
+
$thePDF->restoreState();
} // end of function addMeasuredItem
@@ -309,7 +368,7 @@
// trimme wort auf maximal erlaubte zeichenzahl
$word_fit = mb_substr($word, 0, $available_chars_per_line);
$chars = preg_split('//', $word_fit, -1, PREG_SPLIT_NO_EMPTY);
-
+
if(count($chars) + $chars_current_line + 1 < $available_chars_per_line && $total_number_of_lines < $maxlines) {
$chars_current_line += count($chars) + 1;
$the_return_array[$total_number_of_lines] .= " " . $word_fit;
@@ -326,7 +385,7 @@
* Adds two white polygons to hide any user elements outside the mapframe:
* First all A-Areas are filled, then all B-Areas. This is a rather grumpy
* way out of having user edited stuff flying outside the mapframe.
- *
+ *
* @example <pre>
* BBBBBBBBBBBBBBBBBBBBBBBBBBBBAAA
* BBBBBBBBBBBBBBBBBBBBBBBBBBBBAAA
@@ -339,7 +398,7 @@
* AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
* AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
* </pre>
- *
+ *
* @param reference (!, pass over with '&') to the pdf-file
* @author M. Jansen <jansen at terrestris.de>
*/
@@ -359,7 +418,7 @@
0 , 0
);
// draw polygon
- $pdf->polygon($allOutside, 7, 1);
+ $pdf->polygon($allOutside, 7, 1);
// The BBB-part
$allOutside = array(
0 , $mapOffset_bottom, // 1st coord-pair
@@ -368,7 +427,7 @@
$mapOffset_left + $map_width , $mapOffset_bottom + $map_height,
$mapOffset_left + $map_width , $pdf->ez['pageHeight'],
0 , $pdf->ez['pageHeight'],
- 0 , $mapOffset_bottom,
+ 0 , $mapOffset_bottom,
);
// draw polygon
$pdf->polygon($allOutside, 7, 1);
More information about the Mapbender_commits
mailing list