[Mapbender-commits] r4497 - in branches/print_dev/http: classes
print print/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Aug 5 11:07:30 EDT 2009
Author: mschulz
Date: 2009-08-05 11:07:30 -0400 (Wed, 05 Aug 2009)
New Revision: 4497
Added:
branches/print_dev/http/classes/class_weldMaps2PNG_rotate.php
branches/print_dev/http/classes/class_weldOverview2PNG_rotate.php
Modified:
branches/print_dev/http/print/classes/mbImageDecorator.php
branches/print_dev/http/print/classes/mbMapDecorator.php
branches/print_dev/http/print/classes/mbOverviewDecorator.php
branches/print_dev/http/print/testConfigTemplate.json
Log:
added print rotation - caution: needs php-imagick installed
Added: branches/print_dev/http/classes/class_weldMaps2PNG_rotate.php
===================================================================
--- branches/print_dev/http/classes/class_weldMaps2PNG_rotate.php (rev 0)
+++ branches/print_dev/http/classes/class_weldMaps2PNG_rotate.php 2009-08-05 15:07:30 UTC (rev 4497)
@@ -0,0 +1,95 @@
+<?php
+# $Id: class_weldMaps2PNG_rotate.php 2684 2008-07-22 07:26:19Z christoph $
+# http://www.mapbender.org/index.php/class_weldMaps2PNG_rotate.php
+# Copyright (C) 2002 CCGIS
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+/*
+* class_weldMaps2PNG_rotate
+* @version 1.0.0
+* get/post '___' separated maprequests
+*
+**/
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/class_stripRequest.php");
+require_once(dirname(__FILE__)."/class_connector.php");
+require_once(dirname(__FILE__)."/class_weldMaps2PNG.php");
+
+class weldMaps2PNG_rotate extends weldMaps2PNG{
+
+ function weldMaps2PNG_rotate($urls,$filename, $angle){
+ if(!$urls || $urls == ""){
+ $e = new mb_exception("weldMaps2PNG_rotate: no maprequests delivered");
+ }
+ $url = explode("___", $urls);
+ $obj1 = new stripRequest($url[0]);
+ $width = $obj1->get("width");
+ $height = $obj1->get("height");
+
+ //calculate rotated dimensions
+ $neededWidth = round(abs(sin(deg2rad($angle))*$height)+abs(cos(deg2rad($angle))*$width));
+ $neededHeight = round(abs(sin(deg2rad($angle))*$width)+abs(cos(deg2rad($angle))*$height));
+
+ //modify requests
+ for($i=0; $i<count($url); $i++){
+ $obj = new stripRequest($url[$i]);
+ $obj->set("width", $neededWidth);
+ $obj->set("height", $neededHeight);
+
+ $map_extent = $obj->get("BBOX");
+ $coord = split(",",$map_extent);
+ $coord = $this->enlargeExtent($coord, $width, $height, $neededWidth, $neededHeight);
+
+ $obj->set("BBOX", implode(",", $coord));
+ $url[$i] = $obj->url;
+ }
+
+ //get image
+ $urls = implode("___", $url);
+ $this->weldMaps2PNG($urls, $filename);
+
+
+ //rotate image
+ $imagick = new Imagick();
+ $imagick->readImage($filename);
+ $imagick->rotateImage(new ImagickPixel(), $angle);
+
+ //get the new dimensions
+ $imgWidth = $imagick->getImageWidth();
+ $imgHeight = $imagick->getImageHeight();
+
+ //crop empty areas
+ $imagick->cropImage($width, $height, ($imgWidth-$width)/2, ($imgHeight-$height)/2);
+
+ //write modified image
+ $imagick->writeImage();
+ $image = imagecreatefrompng($filename);
+ imagepng($image,$filename);
+ }
+
+ function enlargeExtent($coordArray, $oldWidth, $oldHeight, $newWidth, $newHeight){
+ $extentx = ($coordArray[2] - $coordArray[0]);
+ $extenty = ($coordArray[3] - $coordArray[1]);
+ $coordArray[0]+=($extentx/$oldWidth)*($oldWidth-$newWidth)/2;
+ $coordArray[2]+=($extentx/$oldWidth)*($newWidth-$oldWidth)/2;
+ $coordArray[1]+=($extenty/$oldHeight)*($oldHeight-$newHeight)/2;
+ $coordArray[3]+=($extenty/$oldHeight)*($newHeight-$oldHeight)/2;
+ return $coordArray;
+ }
+
+}
+
+?>
\ No newline at end of file
Added: branches/print_dev/http/classes/class_weldOverview2PNG_rotate.php
===================================================================
--- branches/print_dev/http/classes/class_weldOverview2PNG_rotate.php (rev 0)
+++ branches/print_dev/http/classes/class_weldOverview2PNG_rotate.php 2009-08-05 15:07:30 UTC (rev 4497)
@@ -0,0 +1,148 @@
+<?php
+# $Id: class_weldOverview2PNG.php 1584 2007-08-06 07:56:11Z christoph $
+# $Header: /cvsroot/mapbender/mapbender/http/classes/class_weldOverview2PNG.php,v 1.3 2006/02/22 11:56:22 astrid_emde Exp $
+# Copyright (C) 2002 CCGIS
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+/*
+* class_weldOverview2PNG
+* @version 1.0.0
+* get/post '___' separated maprequests
+*
+**/
+require_once(dirname(__FILE__)."/class_stripRequest.php");
+require_once(dirname(__FILE__)."/class_mb_exception.php");
+require_once(dirname(__FILE__)."/class_connector.php");
+
+class weldOverview2PNG_rotate{
+
+ function weldOverview2PNG_rotate($url_overview,$url_extent,$filename, $rotatedExtent){
+
+ if(!$url_overview || $url_overview == ""){
+ $e = new mb_exception("weldOverview2PNG: no maprequests delivered");
+ }
+ $url = $url_overview;
+ $obj1 = new stripRequest($url);
+ $width = $obj1->get("width");
+ $height = $obj1->get("height");
+
+ /*
+ $e = new mb_exception("--------overview-----------------");
+ $e = new mb_exception("-----width ".$width." / height: ".$height."--------------------");
+ $e = new mb_exception("url_overview: ".$url_overview);
+ $e = new mb_exception("url_extent: ".$url_extent);
+ */
+ $image = imagecreatetruecolor($width, $height);
+ $white = ImageColorAllocate($image,255,255, 255);
+ ImageFilledRectangle($image,0,0,$width,$height,$white);
+
+ //overview
+ $obj = new stripRequest($url_overview);
+ $xurl_overview = $obj->setPNG();
+ $xurl_overview = $obj->encodeGET();
+ $img = $this->loadpng($xurl_overview);
+ if($img != false){
+ imagecopy($image, $img, 0, 0, 0, 0, $width, $height);
+ }
+ else{
+ $e = new mb_exception("weldMaps2PNG: unable to load image: " . $url_overview);
+ }
+
+
+ // rectangle - position of the map in the overview
+ $objx = new stripRequest($url_extent);
+ $ex_width = $objx->get("width");
+ $ex_height = $objx->get("height");
+ $extent = explode(",",$objx->get("BBOX"));
+
+ $p1 = $this->makeRealWorld2mapPos($url_overview, round($rotatedExtent[0][0]), round($rotatedExtent[0][1]));
+ $p2 = $this->makeRealWorld2mapPos($url_overview, round($rotatedExtent[1][0]), round($rotatedExtent[1][1]));
+ $p3 = $this->makeRealWorld2mapPos($url_overview, round($rotatedExtent[2][0]), round($rotatedExtent[2][1]));
+ $p4 = $this->makeRealWorld2mapPos($url_overview, round($rotatedExtent[3][0]), round($rotatedExtent[3][1]));
+
+ /*
+ $e = new mb_exception("ex_width: " .$ex_width);
+ $e = new mb_exception("ex_height: " . $ex_height);
+ $e = new mb_exception("bbox:".$extent[0]."--".$extent[1]."--".$extent[2]."--------".$extent[3]);
+ $e = new mb_exception("ll: " . $lowerleft[0]." / ".$lowerleft[1]);
+ $e = new mb_exception("ur: " . $upperright[0]." / ".$upperright[1]);
+ */
+
+ $red = ImageColorAllocate($image,255,0,0);
+ imageline ( $image, $p1[0], $p1[1], $p2[0], $p2[1], $red);
+ imageline ( $image, $p2[0], $p2[1], $p3[0], $p3[1], $red);
+ imageline ( $image, $p3[0], $p3[1], $p4[0], $p4[1], $red);
+ imageline ( $image, $p4[0], $p4[1], $p1[0], $p1[1], $red);
+
+
+ // black frame - size of the overview
+ $black = ImageColorAllocate($image,0,0,0);
+ imageline ( $image, 0, 0, $width-1, 0, $black);
+ imageline ( $image, $width-1, 0, $width-1, $height-1, $black);
+ imageline ( $image, $width-1, $height-1, 0, $height-1, $black);
+ imageline ( $image, 0, $height-1, 0, 0, $black);
+
+ imagepng($image,$filename);
+ imagedestroy($image);
+
+ }
+
+
+ function loadpng ($imgurl) {
+ $obj = new stripRequest($imgurl);
+ $x = new connector($imgurl);
+
+ $f = $obj->get("format");
+ $im = @imagecreatefromstring($x->file);
+
+ if(!$im){
+ $im = false;
+ $e = new mb_exception("weldOverview2PNG: unable to load image: ".$imgurl);
+ }
+ return $im;
+ }
+
+ function makeRealWorld2mapPos($url, $rw_posx, $rw_posy){
+ $obj = new stripRequest($url);
+ $width = $obj->get("width");
+ $height = $obj->get("height");
+
+
+ #$e = new mb_exception("weld_url: ".$url);
+ #$e = new mb_exception("w: ".$width."height".$height);
+
+ $arrayBBox = explode(",",$obj->get("BBOX"));
+ $minX = $arrayBBox[0];
+ $minY = $arrayBBox[1];
+ $maxX = $arrayBBox[2];
+ $maxY = $arrayBBox[3];
+
+ #$e = new mb_exception("------- minx: ".$minX." miny:".$minY." maxx:".$maxX." maxy:".$maxY."----------");
+
+ $xtentx = $maxX - $minX ;
+ $xtenty = $maxY - $minY ;
+
+ $pixPos_x = round((($rw_posx - $minX)/$xtentx)*$width);
+ $pixPos_y = round((($maxY - $rw_posy)/$xtenty)*$height);
+
+ $pixPos = array($pixPos_x, $pixPos_y);
+
+ return $pixPos;
+ }
+
+}
+
+?>
\ No newline at end of file
Modified: branches/print_dev/http/print/classes/mbImageDecorator.php
===================================================================
--- branches/print_dev/http/print/classes/mbImageDecorator.php 2009-08-05 14:33:12 UTC (rev 4496)
+++ branches/print_dev/http/print/classes/mbImageDecorator.php 2009-08-05 15:07:30 UTC (rev 4497)
@@ -4,8 +4,8 @@
protected $pageElementType = "image";
protected $elementId;
- protected $rotationAngle = 200;
- protected $overrideMembersFromRequest = array("rotationAngle");
+ protected $angle = 0;
+ protected $overrideMembersFromRequest = array("angle");
public function __construct($pdfObj, $elementId, $mapConf, $controls) {
parent::__construct($pdfObj, $mapConf, $controls);
@@ -18,30 +18,35 @@
/* returns an array of (request key, member id) arrays */
$idsFromRequest = $this->getPageElementLink($this->elementId);
foreach ($idsFromRequest as $requestKey => $memberId) {
- $e = new mb_notice("mbImageDecorator: checking overrides: ".$requestKey.$memberId);
+ $e = new mb_notice("mbOverviewDecorator: checking overrides: ".$requestKey.$memberId);
}
foreach ($_REQUEST as $k => $v) {
- $e = new mb_notice("mbImageDecorator: checking Request: ".$k."=".$v);
+ $e = new mb_notice("mbOverviewDecorator: checking Request: ".$k."=".$v);
}
foreach ($this->overrideMembersFromRequest as $overrideMemberFromRequest) {
+ /* take the value of the config in every case */
+ $this->{$overrideMemberFromRequest} = $this->conf->{$overrideMemberFromRequest};
foreach ($idsFromRequest as $requestKey => $memberId) {
- $e = new mb_notice("mbImageDecorator: before override: set ".$memberId." to ".$requestKey);
+ $e = new mb_notice("mbOverviewDecorator: before override: set ".$memberId." to ".$requestKey);
if ($overrideMemberFromRequest==$memberId && isset($_REQUEST[$requestKey]) && $_REQUEST[$requestKey] != "") {
$this->{$overrideMemberFromRequest} = $_REQUEST[$requestKey];
- $e = new mb_notice("mbImageDecorator: override from Request: ".$overrideMemberFromRequest." to ".$this->{$overrideMemberFromRequest});
+ $e = new mb_notice("mbOverviewDecorator: override from Request: ".$overrideMemberFromRequest." to ".$this->{$overrideMemberFromRequest});
}
+ /* this else branch is not necessary anymore
else {
$this->{$overrideMemberFromRequest} = $this->conf->{$memberId};
- $e = new mb_notice("mbImageDecorator: using conf: ".$overrideMemberFromRequest." to ".$this->conf->{$memberId});
- }
+ $e = new mb_notice("mbOverviewDecorator: override from conf: ".$overrideMemberFromRequest." to ".$this->conf->{$memberId});
+ }
+ */
}
}
+
}
public function decorate() {
#Image($file,$x,$y,$w=0,$h=0,$type='',$link='', $isMask=false, $maskImg=0, $angle=0)
- $this->pdf->objPdf->Image($this->conf->filename, $this->conf->x_ul, $this->conf->y_ul, $this->conf->width, $this->conf->height,'','',false,0,5,$this->rotationAngle);
+ $this->pdf->objPdf->Image($this->conf->filename, $this->conf->x_ul, $this->conf->y_ul, $this->conf->width, $this->conf->height,'','',false,0,5,-1*$this->angle);
}
}
Modified: branches/print_dev/http/print/classes/mbMapDecorator.php
===================================================================
--- branches/print_dev/http/print/classes/mbMapDecorator.php 2009-08-05 14:33:12 UTC (rev 4496)
+++ branches/print_dev/http/print/classes/mbMapDecorator.php 2009-08-05 15:07:30 UTC (rev 4497)
@@ -2,6 +2,7 @@
require_once(dirname(__FILE__)."/../../classes/class_stripRequest.php");
require_once(dirname(__FILE__)."/../../classes/class_weldMaps2PNG.php");
+require_once(dirname(__FILE__)."/../../classes/class_weldMaps2PNG_rotate.php");
require_once(dirname(__FILE__)."/../../classes/class_map.php");
class mbMapDecorator extends mbTemplatePdfDecorator {
@@ -10,8 +11,9 @@
protected $elementId;
protected $filename;
/* a decorator should declare which parameters could be overwritten through the request object */
- protected $overrideMembersFromRequest = array("res_dpi");
+ protected $overrideMembersFromRequest = array("res_dpi","angle");
protected $res_dpi;
+ protected $angle = 0;
public function __construct($pdfObj, $elementId, $mapConf, $controls) {
parent::__construct($pdfObj, $mapConf, $controls);
@@ -40,11 +42,12 @@
$this->{$overrideMemberFromRequest} = $_REQUEST[$requestKey];
$e = new mb_notice("mbMapDecorator: override from Request: ".$overrideMemberFromRequest." to ".$this->{$overrideMemberFromRequest});
}
- /* this else branch is not necessary anymore */
+ /* this else branch is not necessary anymore
else {
$this->{$overrideMemberFromRequest} = $this->conf->{$memberId};
$e = new mb_notice("mbMapDecorator: override from conf: ".$overrideMemberFromRequest." to ".$this->conf->{$memberId});
}
+ */
}
}
}
@@ -72,7 +75,11 @@
$array_urls[$i] = $m->url;
}
- $i = new weldMaps2PNG(implode("___",$array_urls), $this->filename);
+ if ($this->angle != 0) {
+ $i = new weldMaps2PNG_rotate(implode("___",$array_urls), $this->filename, $this->angle);
+ } else {
+ $i = new weldMaps2PNG(implode("___",$array_urls), $this->filename);
+ }
$this->pdf->objPdf->Image($this->filename, $this->conf->x_ul, $this->conf->y_ul, $width, $height,'png');
/* show coordinates ... */
Modified: branches/print_dev/http/print/classes/mbOverviewDecorator.php
===================================================================
--- branches/print_dev/http/print/classes/mbOverviewDecorator.php 2009-08-05 14:33:12 UTC (rev 4496)
+++ branches/print_dev/http/print/classes/mbOverviewDecorator.php 2009-08-05 15:07:30 UTC (rev 4497)
@@ -2,12 +2,16 @@
require_once(dirname(__FILE__)."/../../classes/class_stripRequest.php");
require_once(dirname(__FILE__)."/../../classes/class_weldOverview2PNG.php");
+require_once(dirname(__FILE__)."/../../classes/class_weldOverview2PNG_rotate.php");
class mbOverviewDecorator extends mbTemplatePdfDecorator {
protected $pageElementType = "overview";
protected $elementId;
protected $filename;
+ protected $overrideMembersFromRequest = array("angle");
+ protected $angle = 0;
+
public function __construct($pdfObj, $elementId, $mapConf, $controls) {
parent::__construct($pdfObj, $mapConf, $controls);
@@ -17,7 +21,33 @@
$this->decorate();
}
- public function override() {}
+ public function override() {
+ $idsFromRequest = $this->getPageElementLink($this->elementId);
+ foreach ($idsFromRequest as $requestKey => $memberId) {
+ $e = new mb_notice("mbOverviewDecorator: checking overrides: ".$requestKey.$memberId);
+ }
+ foreach ($_REQUEST as $k => $v) {
+ $e = new mb_notice("mbOverviewDecorator: checking Request: ".$k."=".$v);
+ }
+
+ foreach ($this->overrideMembersFromRequest as $overrideMemberFromRequest) {
+ /* take the value of the config in every case */
+ $this->{$overrideMemberFromRequest} = $this->conf->{$overrideMemberFromRequest};
+ foreach ($idsFromRequest as $requestKey => $memberId) {
+ $e = new mb_notice("mbOverviewDecorator: before override: set ".$memberId." to ".$requestKey);
+ if ($overrideMemberFromRequest==$memberId && isset($_REQUEST[$requestKey]) && $_REQUEST[$requestKey] != "") {
+ $this->{$overrideMemberFromRequest} = $_REQUEST[$requestKey];
+ $e = new mb_notice("mbOverviewDecorator: override from Request: ".$overrideMemberFromRequest." to ".$this->{$overrideMemberFromRequest});
+ }
+ /* this else branch is not necessary anymore
+ else {
+ $this->{$overrideMemberFromRequest} = $this->conf->{$memberId};
+ $e = new mb_notice("mbOverviewDecorator: override from conf: ".$overrideMemberFromRequest." to ".$this->conf->{$memberId});
+ }
+ */
+ }
+ }
+ }
public function decorate() {
$overview_url = $_REQUEST["overview_url"];
@@ -34,10 +64,68 @@
$array_urls = explode("___", $urls);
$myURL = new stripRequest($array_urls[0]);
$myURL->set('bbox', $this->pdf->getMapExtent());
+ $rotatedExtent = $this->rotatePoints(explode(",",$this->pdf->getMapExtent()), intval($angle));
- $i = new weldOverview2PNG($overview_url, $myURL->url, $this->filename);
+ if ($this->angle != 0) {
+ $i = new weldOverview2PNG_rotate($overview_url, $myURL->url, $this->filename, $rotatedExtent);
+ } else {
+ $i = new weldOverview2PNG($overview_url, $myURL->url, $this->filename);
+ }
+
$this->pdf->objPdf->Image($this->filename, $this->conf->x_ul, $this->conf->y_ul, $width, $height, 'png');
}
+
+ protected function rotate($point, $center, $angle) {
+ if ($angle === 0) {
+ return $point;
+ }
+ // first, calculate point around 0
+ // then rotate
+ // then add center vector again
+
+ $pNew = array(
+ $point[0] - $center[0],
+ $point[1] - $center[1]
+ );
+
+ $angle = deg2rad(-$angle);
+ return array(
+ ($pNew[0] * cos($angle) + $pNew[1] * sin($angle)) + $center[0],
+ ($pNew[0] * -sin($angle) + $pNew[1] * cos($angle)) + $center[1]
+ );
+ }
+
+ protected function rotatePoints($coordArray, $angle) {
+ $center = array(
+ ($coordArray[2] + $coordArray[0]) / 2,
+ ($coordArray[3] + $coordArray[1]) / 2,
+ );
+
+ $p1 = array(
+ $coordArray[0],
+ $coordArray[1]
+ );
+ $p2 = array(
+ $coordArray[2],
+ $coordArray[1]
+ );
+ $p3 = array(
+ $coordArray[2],
+ $coordArray[3]
+ );
+ $p4 = array(
+ $coordArray[0],
+ $coordArray[3]
+ );
+
+ $newCoordArray = array(
+ $this->rotate($p1, $center, $angle),
+ $this->rotate($p2, $center, $angle),
+ $this->rotate($p3, $center, $angle),
+ $this->rotate($p4, $center, $angle)
+ );
+ return $newCoordArray;
+ }
}
Modified: branches/print_dev/http/print/testConfigTemplate.json
===================================================================
--- branches/print_dev/http/print/testConfigTemplate.json 2009-08-05 14:33:12 UTC (rev 4496)
+++ branches/print_dev/http/print/testConfigTemplate.json 2009-08-05 15:07:30 UTC (rev 4497)
@@ -47,7 +47,10 @@
"id" : "angle",
"type" : "hidden",
"pageElementsLink" : {
- "nordpfeil" : "rotation"
+ "nordpfeil" : "angle",
+ "karte" : "angle",
+ "minikarte" : "angle"
+
}
},
{
@@ -135,7 +138,7 @@
"y_ul" : 35.2,
"width" : 8,
"height" : 18,
- "rotation" : 0,
+ "angle" : 0,
"filename" : "./img/northarrow.png"
}
}
More information about the Mapbender_commits
mailing list