[Mapbender-commits] r1375 - trunk/mapbender/http/print
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Tue May 29 10:33:18 EDT 2007
Author: sven
Date: 2007-05-29 10:33:18 -0400 (Tue, 29 May 2007)
New Revision: 1375
Added:
trunk/mapbender/http/print/print_functions.php
Modified:
trunk/mapbender/http/print/mod_printPDF.php
trunk/mapbender/http/print/mod_printPDF_pdf.php
Log:
add temporary elements
Modified: trunk/mapbender/http/print/mod_printPDF.php
===================================================================
--- trunk/mapbender/http/print/mod_printPDF.php 2007-05-29 12:22:37 UTC (rev 1374)
+++ trunk/mapbender/http/print/mod_printPDF.php 2007-05-29 14:33:18 UTC (rev 1375)
@@ -18,6 +18,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
session_start();
require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
+
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
@@ -282,6 +283,24 @@
document.form1.mylegend.value = 'true';
}
+ // write the measured coordinates
+ var tmp_x = '';
+ var tmp_y = '';
+ var tmp_dist = '';
+ for(i = 0; i<pt.mod_measure_RX.length; i++) {
+ if(tmp_x != '') {
+ tmp_x += ','
+ }
+ tmp_x += pt.mod_measure_RX[i];
+ }
+ for(i = 0; i<pt.mod_measure_RY.length; i++) {
+ if(tmp_y != '') {
+ tmp_y += ','
+ }
+ tmp_y += pt.mod_measure_RY[i];
+ }
+ document.forms['form1'].elements['measured_x_values'].value = tmp_x;
+ document.forms['form1'].elements['measured_y_values'].value = tmp_y;
document.form1.submit();
}
else{
@@ -371,6 +390,8 @@
<input type='hidden' name='comment1' value=''>
<input type='hidden' name='comment2' value=''>
<input type='hidden' name='mylegend' value='true'>
+<input type='hidden' name='measured_x_values' value=''>
+<input type='hidden' name='measured_y_values' value=''>
</form>
</body>
Modified: trunk/mapbender/http/print/mod_printPDF_pdf.php
===================================================================
--- trunk/mapbender/http/print/mod_printPDF_pdf.php 2007-05-29 12:22:37 UTC (rev 1374)
+++ trunk/mapbender/http/print/mod_printPDF_pdf.php 2007-05-29 14:33:18 UTC (rev 1375)
@@ -29,6 +29,8 @@
include (dirname(__FILE__)."/../classes/class_weldOverview2PNG.php");
include (dirname(__FILE__)."/../print/".$_REQUEST["conf"]);
include (dirname(__FILE__)."/../classes/class_SaveLegend.php");
+include (dirname(__FILE__)."/../print/print_functions.php");
+
if($log == true){
include (dirname(__FILE__)."/../classes/class_log.php");
}
@@ -435,6 +437,38 @@
$pdf->addText($mapOffset_left + $map_width - ($pdf->getTextWidth($mySize, $myMaxx)), $mapOffset_bottom + $map_height + 3, $mySize, $myMaxx);
$pdf->addText($mapOffset_left + $map_width + 3, $mapOffset_bottom + $map_height, $mySize, $myMaxy, 90);
+
+
+/** ******************************************************************
+* user drawn elements
+*/
+
+$theMeasureConfigArray = array(
+ "do_fill" => FALSE,
+ "fill_color" => array(
+ "r" => "0.95",
+ "g" => "0.95",
+ "b" => "0.95"
+ ),
+ "do_stroke" => TRUE,
+ "stroke_color" => array(
+ "r" => 254 / 255,
+ "g" => 1 / 255,
+ "b" => 1 / 255
+ ),
+ "line_style" => array(
+ "width" => 2,
+ "cap" => 'butt',
+ "join" => 'miter',
+ "dash" => array(10, 6)
+ )
+ );
+$use_r = 180 / 255;
+$use_g = 206 / 255;
+$use_b = 140 / 255;
+addMeasuredItem(&$pdf, $_POST['measured_x_values'], $_POST['measured_y_values'], $theMeasureConfigArray);
+hideElementsOutsideMapframe(&$pdf);
+
if ($overview==true){
// analyse request, draw rectancle
$filename = str_replace("map_","overview_",$filename);
Added: trunk/mapbender/http/print/print_functions.php
===================================================================
--- trunk/mapbender/http/print/print_functions.php (rev 0)
+++ trunk/mapbender/http/print/print_functions.php 2007-05-29 14:33:18 UTC (rev 1375)
@@ -0,0 +1,375 @@
+<?php
+/**
+ * converts the coordinates created via the JavaScript
+ * 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'
+ *
+ * @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
+ * )
+ *
+ * @see transformForPDF
+ *
+ * @author M. Jansen <jansen at terrestris.de>, 2006-05-26
+ */
+function makeCoordPairs($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" => transformForPDF($arr_x[$i], "x"),
+ "pdf_y" => transformForPDF($arr_y[$i], "y")
+ );
+ }
+ }
+
+ return $the_return_arr;
+} // end of function makeCoordPairs
+
+
+
+/**
+ * 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
+ *
+ * @author M. Jansen <jansen at terrestris.de>, 2006-05-26
+ */
+function transformForPDF ($theRealCoord, $theType) {
+ global $mapOffset_left, $mapOffset_bottom, $map_height, $map_width, $coord;
+
+ $thePDFvalue = "";
+
+ switch (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 + ($target_height * $ratio_to_display);
+ break;
+ default:
+ // a non valid parameter was given
+ $thePDFvalue = $theRealCoord;
+ break;
+ }
+ return $thePDFvalue;
+} // end of function transformForPDF
+
+
+
+
+/**
+ * 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
+ *
+ * @author M. Jansen <jansen at terrestris.de>, 2006-05-26
+ */
+function makePolyFromCoord($theFullCoordinatesArray) {
+ $theRetArr = array();
+ foreach($theFullCoordinatesArray as $singlePoint) {
+ $theRetArr[] = $singlePoint['pdf_x'];
+ $theRetArr[] = $singlePoint['pdf_y'];
+ }
+ return $theRetArr;
+} // end of function makePolyFromCoord
+
+
+
+
+/**
+ * converts an array of coordinates (created e.g. by makeCoordPairs()) into
+ * an array thats needed to draw lines via line(x0, y0, x1, y1)
+ *
+ * @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
+ *
+ * @author M. Jansen <jansen at terrestris.de>, 2006-05-26
+ */
+function makeStrokePointPairs($thePointArray) {
+ $cnt = count($thePointArray);
+ $theRetArray = array();
+ for($i = 0; $i < $cnt; $i++) {
+ if($i != $cnt - 1) {
+ $theRetArray[] = array(
+ $thePointArray[$i]['pdf_x'],
+ $thePointArray[$i]['pdf_y'],
+ $thePointArray[$i+1]['pdf_x'],
+ $thePointArray[$i+1]['pdf_y'],
+ );
+ } else {
+ $theRetArray[] = array(
+ $thePointArray[$i]['pdf_x'],
+ $thePointArray[$i]['pdf_y'],
+ $thePointArray[0]['pdf_x'],
+ $thePointArray[0]['pdf_y'],
+ );
+ }
+ }
+ return $theRetArray;
+} // end of function makeStrokePointPairs
+
+
+
+
+/**
+ * test whether the coordinates in an array form a closed polygon
+ * meaning that first an last point of polygon are equal
+ *
+ * @param array the Array containing all infos about single coordinates
+ * created via makeCoordPairs()
+ *
+ * @return bool is it closed (TRUE || FALSE)
+ *
+ * @see makeCoordPairs
+ *
+ * @author M. Jansen <jansen at terrestris.de>, 2006-05-26
+ */
+function isClosedPolygon($coord_arr) {
+ $nr_of = count($coord_arr);
+ 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;
+ } else {
+ return FALSE;
+ }
+} // end of function isClosedPolygon
+
+
+
+
+/**
+ * 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
+ * @param array configuration settings.
+ *
+ * @return void nothing
+ *
+ * @see makeCoordPairs
+ * @see isClosedPolygon
+ * @see makeStrokePointPairs
+ * @see makePolyFromCoord
+ * @see transformForPDF
+ * @see makeCoordPairs
+ *
+ * @author M. Jansen <jansen at terrestris.de>, 2006-05-26
+ */
+function addMeasuredItem($thePDF, $x_value_str, $y_value_str, $theConfArray = array()) {
+ // get global variable:
+ global $legendFilenameUserPolygon;
+ // create legend image:
+ $legend_width = 17;
+ $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");
+ }
+
+ // get the arrays
+ $theFullArr = makeCoordPairs($x_value_str, $y_value_str);
+ $thePolyArr = makePolyFromCoord($theFullArr);
+
+ if (isClosedPolygon($theFullArr)) {
+ $nr_of_points = count($theFullArr);
+ $isClosed = TRUE;
+ } else {
+ $nr_of_points = count($theFullArr) - 1;
+ $isClosed = FALSE;
+ }
+
+ // 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'])
+ && $theConfArray['fill_color']['r'] != ''
+ && $theConfArray['fill_color']['g'] != ''
+ && $theConfArray['fill_color']['b'] != '') {
+ $thePDF->setColor($theConfArray['fill_color']['r'], $theConfArray['fill_color']['g'], $theConfArray['fill_color']['b']);
+ $legend_image_fill = $theConfArray['fill_color']['r'] . "," . $theConfArray['fill_color']['g'] . "," . $theConfArray['fill_color']['b'];
+ // color to legend file
+ $bg_color = imagecolorallocate($leg_img, round($theConfArray['fill_color']['r'] * 255), round($theConfArray['fill_color']['g'] * 255), round($theConfArray['fill_color']['b'] * 255));
+ } else {
+ $thePDF->setColor(0, 0, 0);
+ // color to legend file
+ $bg_color = imagecolorallocate($leg_img, 0, 0, 0);
+ }
+ } else {
+ $doFill = 0;
+ // 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'])
+ && $theConfArray['stroke_color']['r'] != ''
+ && $theConfArray['stroke_color']['g'] != ''
+ && $theConfArray['stroke_color']['b'] != '') {
+ $thePDF->setStrokeColor($theConfArray['stroke_color']['r'], $theConfArray['stroke_color']['g'], $theConfArray['stroke_color']['b']);
+ $thePDF->setLineStyle($theConfArray['line_style']['width'], $theConfArray['line_style']['cap'], $theConfArray['line_style']['join'], $theConfArray['line_style']['dash']);
+ $theStrokePointPairs = makeStrokePointPairs($theFullArr);
+ for($i = 0; $i < count($theStrokePointPairs); $i++) {
+ $line = $theStrokePointPairs[$i];
+ 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] != ""
+ && $theConfArray['line_style']['dash'][1] != 0) {
+ imagedashedline($leg_img, 0, 0, $legend_width-1, 0, $stroke_color_legend_image);
+ imagedashedline($leg_img, $legend_width-1, 0, $legend_width-1, $legend_width-1, $stroke_color_legend_image);
+ imagedashedline($leg_img, $legend_width-1, $legend_width-1, 0, $legend_width-1, $stroke_color_legend_image);
+ imagedashedline($leg_img, 0, $legend_width-1, 0, 0, $stroke_color_legend_image);
+ } else {
+ imageline($leg_img, 0, 0, $legend_width-1, 0, $stroke_color_legend_image);
+ 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
+
+/**
+ * Konvertiert einen Text in ein array aus einzelnen Zeilen. Parameter wie Zeichen pro
+ * zeile etc. können in der Funktion geändert werden.
+ */
+function convert2lines($the_text) {
+ $words = explode(' ', $the_text);
+ $maxlines = 6;
+ $available_chars_per_line = 35;
+ $total_number_of_lines = 0;
+ $chars_current_line = 0;
+ $the_return_array = array();
+
+ foreach($words as $word) {
+ // trimme wort auf maximal erlaubte zeichenzahl
+ $word_fit = 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;
+ } elseif($total_number_of_lines < $maxlines) {
+ $chars_current_line = count($chars) + 1;
+ $the_return_array[$total_number_of_lines + 1] = " " . $word_fit;
+ $total_number_of_lines++;
+ }
+ }
+ return $the_return_array;
+} // end of function convert2lines
+
+/**
+ * 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
+ * BBB AAA
+ * BBB AAA
+ * BBB Mapframe AAA
+ * BBB AAA
+ * BBB AAA
+ * BBB AAA
+ * AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+ * AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+ * </pre>
+ *
+ * @param reference (!, pass over with '&') to the pdf-file
+ * @author M. Jansen <jansen at terrestris.de>
+ */
+function hideElementsOutsideMapframe($pdf) {
+ // get globals
+ global $mapOffset_left, $map_width, $mapOffset_bottom, $map_height;
+ $pdf->saveState();
+ $pdf->setColor(1, 1, 1);
+ // The AAA-Part
+ $allOutside = array(
+ 0 , 0, // 1st coord-pair
+ $pdf->ez['pageWidth'] , 0, // 2nd coord-pair
+ $pdf->ez['pageWidth'] , $pdf->ez['pageHeight'], // ...
+ $mapOffset_left + $map_width , $pdf->ez['pageHeight'],
+ $mapOffset_left + $map_width , $mapOffset_bottom,
+ 0 , $mapOffset_bottom,
+ 0 , 0
+ );
+ // draw polygon
+ $pdf->polygon($allOutside, 7, 1);
+ // The BBB-part
+ $allOutside = array(
+ 0 , $mapOffset_bottom, // 1st coord-pair
+ $mapOffset_left , $mapOffset_bottom, // 2nd coord-pair
+ $mapOffset_left , $mapOffset_bottom + $map_height, // ...
+ $mapOffset_left + $map_width , $mapOffset_bottom + $map_height,
+ $mapOffset_left + $map_width , $pdf->ez['pageHeight'],
+ 0 , $pdf->ez['pageHeight'],
+ 0 , $mapOffset_bottom,
+ );
+ // draw polygon
+ $pdf->polygon($allOutside, 7, 1);
+ $pdf->restoreState();
+}
+?>
\ No newline at end of file
More information about the Mapbender_commits
mailing list