[Mapbender-commits] r2162 - in branches/2.5/http: classes javascripts php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Mar 3 09:46:12 EST 2008


Author: greq
Date: 2008-03-03 09:46:12 -0500 (Mon, 03 Mar 2008)
New Revision: 2162

Added:
   branches/2.5/http/classes/class_weldMaps2Image.php
   branches/2.5/http/javascripts/mod_exportMapImage.php
   branches/2.5/http/php/mod_exportMapImage_server.php
Log:
new mapImageExport-Module(png, jpeg and geotiff)
http://www.mapbender.org/ExportMapimage

Added: branches/2.5/http/classes/class_weldMaps2Image.php
===================================================================
--- branches/2.5/http/classes/class_weldMaps2Image.php	                        (rev 0)
+++ branches/2.5/http/classes/class_weldMaps2Image.php	2008-03-03 14:46:12 UTC (rev 2162)
@@ -0,0 +1,201 @@
+<?php
+# $Id$
+# http://www.mapbender.org/
+# 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.
+
+require_once(dirname(__FILE__)."/class_stripRequest.php");
+require_once(dirname(__FILE__)."/class_mb_exception.php");
+require_once(dirname(__FILE__)."/class_connector.php");
+include_once(dirname(__FILE__)."/../../conf/mapbender.conf");
+ 
+ /*
+  * Class generats Images (jpegs/pngs/geotiff) 
+  * of Image-URL-Array
+  * For geotiff export gdal is necessary
+  * 
+  */
+ class weldMaps2Image{
+ 	
+	var $urls = array();
+	var $filename; 	
+ 	
+ 	function weldMaps2Image($urls, $array_file){
+ 		$this->urls = $urls;
+  		$this->array_file = $array_file;
+ 	}
+ 	
+ 	
+	function getImage($imageTyp_imp, $outputKind=''){
+		
+		$imageTyp="";
+		$imageTyp=$imageTyp_imp;
+		
+		if($imageTyp=='jpg'){
+			$imageTyp='jpeg';
+		}
+				
+		if(!$this->urls || $this->urls == ""){
+			$e = new mb_exception("weldMaps2Image: no maprequests delivered");
+		}
+		$obj1 = new stripRequest($this->urls[0]);
+		$width = $obj1->get("width");
+		$height = $obj1->get("height");
+		$wms_srs = $obj1->get("srs");
+		$wms_bbox = $obj1->get("bbox");
+		$wms_format = $obj1->getFormat();
+		
+		$image = imagecreatetruecolor($width, $height	);
+		$white = ImageColorAllocate($image,255,255,255); 
+		ImageFilledRectangle($image,0,0,$width,$height,$white); 
+	
+		for($i=0; $i<count($this->urls); $i++){
+			$obj = new stripRequest($this->urls[$i]);
+			if($imageTyp=='geotiff'){
+				$this->urls[$i] = $obj->setFormat($wms_format);
+			} else {
+				$this->urls[$i] = $obj->setFormat($imageTyp);	
+			}	
+			
+			$this->urls[$i] = $obj->encodeGET();			
+			$img = $this->loadImage($this->urls[$i]);				
+			if($img != false){
+				imagecopy($image, $img, 0, 0, 0, 0, $width, $height);
+			}
+			else{
+				$e = new mb_exception("weldMaps2Image: unable to load image: " . $this->urls[$i]);
+			}
+		}		
+		
+		$filename = $this->array_file['dir']."/";
+		$timestamp = time();			
+		$filenameOnly =$this->array_file['filename'].md5($timestamp);
+		
+		if($imageTyp=='png'){
+			
+			$filenameOnly .= '.png';
+			$filename .= $filenameOnly;
+
+			imagepng($image, $filename);
+			
+			$this->downloadLink($filenameOnly);
+			
+		} else if($imageTyp=='jpeg'){
+			
+			$filenameOnly .= '.jpeg';
+			$filename .= $filenameOnly;
+			imagejpeg($image, $filename);
+			
+			$this->downloadLink($filenameOnly);
+					
+		} else if($imageTyp=='geotiff'){
+			
+			$filenameOnly .= '.'.$wms_format;
+			$filename .= $filenameOnly;
+			
+			if ($wms_format=='png'){
+				imagepng($image, $filename);	
+			} else if ($wms_format=='jpeg'){
+				imagejpeg($image, $filename);	
+			} else {
+				$e = new mb_exception("weldMaps2Image: unable to generate temp-Image for getiff: " . $filename);
+			}
+			
+			// gdal_translate...
+			$wms_bbox = str_replace(',', ' ', $wms_bbox);
+			$filename_tif = str_replace($wms_format, 'tif', $filenameOnly);
+
+			$tmp_dir = $this->array_file['dir'];
+			$cmd = "gdal_translate -a_srs ".$wms_srs." -a_ullr ".$wms_bbox." ".$tmp_dir.$filenameOnly." ".$tmp_dir.$filename_tif;
+			exec($cmd);
+			
+			echo "<br>";
+			$this->downloadLink($filenameOnly);
+					
+		}else {
+			
+		}
+		
+		
+	}
+	
+	function loadImage ($imgurl) {
+
+		$x = new connector($imgurl);		
+		$im = @imagecreatefromstring($x->file);
+		if(!$im){
+			$im = false;
+			$e = new mb_exception("weldMaps2Image: unable to load image: ".$imgurl);
+		}  
+		return $im;
+		
+	}
+ 	
+ 	function downloadLink($downloadFilename){
+ 		
+
+		$dwDir  = $this->array_file['dir']."/";
+		$dwFilename = $downloadFilename;
+		
+		
+		if(!(bool)$dwFilename) {
+			die("No filename given.");
+		}
+		
+		if((int)strpos($dwFilename,"..") !== 0) {
+			die("Illegal filename given.");
+		}
+		
+		$img = $dwDir."/".$dwFilename; 
+		
+		if(!file_exists($img) || !is_readable($img)) {
+			die("An error occured.");
+			
+		}
+		
+		$now_date = date("Ymd_His");
+		
+		switch(substr($dwFilename,-4)) {
+			case ".png":
+				$filename = "map_export__".$now_date.".png";
+				header('Content-Type: image/png');
+				break;
+			case "jpeg":
+				$filename = "map_export__".$now_date.".jpeg";
+				header('Content-Type: image/jpeg');
+				break;
+			case ".tif";
+				$filename = "map_export__".$now_date.".tif";
+				header('Content-Type: image/tif');
+				break;
+			default:
+				die("An error occured.");
+		}
+
+ 		if(file_exists($img) && is_file($img)) {
+				header("Content-Disposition: attachment; filename=\"".$filename."\"");
+
+				readfile($img); 
+		} else {
+			    die('Error: The file '.$img.' does not exist!');
+			}
+
+ 	}
+ 	
+ }
+ 
+
+?>
\ No newline at end of file


Property changes on: branches/2.5/http/classes/class_weldMaps2Image.php
___________________________________________________________________
Name: svn:keywords
   + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: branches/2.5/http/javascripts/mod_exportMapImage.php
===================================================================
--- branches/2.5/http/javascripts/mod_exportMapImage.php	                        (rev 0)
+++ branches/2.5/http/javascripts/mod_exportMapImage.php	2008-03-03 14:46:12 UTC (rev 2162)
@@ -0,0 +1,166 @@
+<?php
+# $Id$
+# http://www.mapbender.org/ExportMapimage
+# 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.
+
+require_once(dirname(__FILE__) . "/../php/mb_validatePermission.php");
+
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+
+<html>
+<head>
+<meta http-equiv="cache-control" content="no-cache">
+<meta http-equiv="pragma" content="no-cache">
+<meta http-equiv="expires" content="0">
+<?php
+echo '<meta http-equiv="Content-Type" content="text/html; charset='.CHARSET.'">';	
+?>
+<title>Export Mapimage</title>
+<?php
+ include '../include/dyn_css.php';
+?>
+</head>
+<style type="text/css">
+<!-- 
+ 
+input{
+	width:50px;
+    font-family: Arial, Helvetica, sans-serif;
+	font-size: 12px;
+}
+div{
+	font-family : Arial, Helvetica, sans-serif;
+	font-size: 12px;
+}
+.imageformat{
+	width:50px;
+	font-family : Arial, Helvetica, sans-serif;
+	font-size: 14px;
+    font-weight: bold;
+}
+
+-->
+</style>
+<?php
+
+
+
+echo "<script type='text/javascript'>";
+echo "var target = '".$_REQUEST["target"]."';";
+
+echo "</script>";
+?>
+<script type="text/javascript">
+
+
+// some defaults
+try{if (pngExport){}}catch(e){pngExport = 'true';}
+try{if (jpegExport){}}catch(e){jpegExport = 'true';}
+try{if (geotiffExport){}}catch(e){geotiffExport = 'true';}
+
+
+function generateExportOptions(){
+if (pngExport=='true'){
+	document.write('<tr><td><span class="imageformat"><input type="radio" name="imageformat" value="png">PNG</span></td></tr>');		
+}
+if (jpegExport=='true'){
+	document.write('<tr><td><span class="imageformat"><input type="radio" name="imageformat" value="jpeg">JPEG / JPG</span></td></tr>');		
+}
+if (geotiffExport=='true'){
+	document.write('<tr><td><span class="imageformat"><input type="radio" name="imageformat" value="geotiff">GeoTIFF</span></td></tr>');		
+}
+
+
+
+}
+
+function exportMapimage(){
+		
+	choosen = "";
+	len = document.form1.imageformat.length;
+	
+	for (i = 0; i <len; i++) {
+		if (document.form1.imageformat[i].checked) {
+			choosen = document.form1.imageformat[i].value;
+		}
+	}
+	
+	if (choosen == "") {
+		alert("Keine Wahl getroffen, per DEFAULT wird die Karte als PNG exportiert");
+		choosen = document.form1.imageformat[0].value;
+	}
+	else {
+		//alert(choosen)
+	}
+
+	
+	var idx = window.opener.getMapObjIndexByName(target);
+	
+    
+	var wms_string = "";
+    
+	for(var ii=0; ii<window.opener.mb_mapObj[idx].wms.length; ii++){
+
+    
+    if (window.opener.mb_mapObj[idx].mapURL[ii] == false || typeof(window.opener.mb_mapObj[idx].mapURL[ii]) == 'undefined' || window.opener.mb_mapObj[idx].mapURL[ii] == 'undefined'){
+				
+				//alert('Keine WMSe vorhanden.');
+			} else{
+
+   				if (ii==0){
+					wms_string = window.opener.mb_mapObj[idx].mapURL[ii];	
+				} else {
+					wms_string += "___"+window.opener.mb_mapObj[idx].mapURL[ii];
+				}
+			}		
+	}
+	wms_string = encodeURIComponent(wms_string);
+	var myLocation = "../php/mod_exportMapImage_server.php?target="+target+"&imagetype="+choosen+"&wms_urls="+wms_string;
+	//mynewwin = window.open("../php/mod_exportMapImage_server.php?target="+target+"&imagetype="+choosen+"&wms_urls="+wms_string+"","exportMapImage","width=180, height=200, resizable=yes ");
+	document.location.href = myLocation; 
+	
+//	alert('ImageExport done');
+//	window.close();
+	
+}
+
+function close_exportMapimage(){
+	window.close();
+}
+
+</script>
+<body>
+<form name='form1' method='POST' action='' target="_blank" onSubmit="return FormCheck()">
+<table border='0'>
+<div>Please select a format for the exported image!</div><br>
+
+<script type="text/javascript"> generateExportOptions();
+</script>
+
+<tr>
+<td> <br><br> </td>
+</tr>
+
+</table>  
+<div id="buttons" align='right'>
+		<input type='button' name='expImg_ok' value="OK" onclick='exportMapimage();'>
+		<input type='button' name='expImg_close' value="Close" onclick='close_exportMapimage();'>
+</div>
+</form>
+</body>
+</html>


Property changes on: branches/2.5/http/javascripts/mod_exportMapImage.php
___________________________________________________________________
Name: svn:keywords
   + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: branches/2.5/http/php/mod_exportMapImage_server.php
===================================================================
--- branches/2.5/http/php/mod_exportMapImage_server.php	                        (rev 0)
+++ branches/2.5/http/php/mod_exportMapImage_server.php	2008-03-03 14:46:12 UTC (rev 2162)
@@ -0,0 +1,46 @@
+<?php
+# $Id$
+# http://www.mapbender.org/ExportMapimage
+# 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.
+
+require_once(dirname(__FILE__) . "/../php/mb_validateSession.php");
+include_once(dirname(__FILE__)."/../classes/class_weldMaps2Image.php");
+
+$imageType = "";
+if(isset($_REQUEST["imagetype"])){
+	
+	$imageType = $_REQUEST["imagetype"];
+	
+}
+
+$urls = "";
+if(isset($_REQUEST["wms_urls"])){
+	
+	$wms_urls = $_REQUEST["wms_urls"];
+	
+}
+
+$array_file = array();
+$array_file["dir"]  = TMPDIR; 
+$array_file["filename"] = "image"; 
+
+$array_urls = explode("___", $wms_urls);
+$image = new weldMaps2Image($array_urls, $array_file);
+$image->getImage($imageType, 'file');
+
+ 
+?>
\ No newline at end of file


Property changes on: branches/2.5/http/php/mod_exportMapImage_server.php
___________________________________________________________________
Name: svn:keywords
   + HeadURL Id LastChangedBy LastChangedDate LastChangedRevision



More information about the Mapbender_commits mailing list