[Mapbender-commits] r2160 - in branches/2.4.5/http: classes javascripts php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Mar 3 09:24:21 EST 2008


Author: greq
Date: 2008-03-03 09:24:20 -0500 (Mon, 03 Mar 2008)
New Revision: 2160

Modified:
   branches/2.4.5/http/classes/class_weldMaps2Image.php
   branches/2.4.5/http/javascripts/mod_exportMapImage.php
   branches/2.4.5/http/php/mod_exportMapImage_server.php
Log:
mapImageExport improved:
- no download.php needed
- close - button added
- element vars handling added

Modified: branches/2.4.5/http/classes/class_weldMaps2Image.php
===================================================================
--- branches/2.4.5/http/classes/class_weldMaps2Image.php	2008-03-03 11:36:44 UTC (rev 2159)
+++ branches/2.4.5/http/classes/class_weldMaps2Image.php	2008-03-03 14:24:20 UTC (rev 2160)
@@ -91,7 +91,7 @@
 
 			imagepng($image, $filename);
 			
-			echo $this->downloadLink("../php/download.php?download=".$filenameOnly);
+			$this->downloadLink($filenameOnly);
 			
 		} else if($imageTyp=='jpeg'){
 			
@@ -99,7 +99,7 @@
 			$filename .= $filenameOnly;
 			imagejpeg($image, $filename);
 			
-			echo $this->downloadLink("../php/download.php?download=".$filenameOnly);
+			$this->downloadLink($filenameOnly);
 					
 		} else if($imageTyp=='geotiff'){
 			
@@ -120,12 +120,10 @@
 
 			$tmp_dir = $this->array_file['dir'];
 			$cmd = "gdal_translate -a_srs ".$wms_srs." -a_ullr ".$wms_bbox." ".$tmp_dir.$filenameOnly." ".$tmp_dir.$filename_tif;
-//			echo "cmd: <br>".$cmd."<br>";
 			exec($cmd);
 			
-			
 			echo "<br>";
-			echo $this->downloadLink("../php/download.php?download=".$filename_tif);
+			$this->downloadLink($filenameOnly);
 					
 		}else {
 			
@@ -146,8 +144,55 @@
 		
 	}
  	
- 	function downloadLink($link){
- 		return "<a href=".$link.">Image Download</a>";
+ 	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!');
+			}
+
  	}
  	
  }

Modified: branches/2.4.5/http/javascripts/mod_exportMapImage.php
===================================================================
--- branches/2.4.5/http/javascripts/mod_exportMapImage.php	2008-03-03 11:36:44 UTC (rev 2159)
+++ branches/2.4.5/http/javascripts/mod_exportMapImage.php	2008-03-03 14:24:20 UTC (rev 2160)
@@ -32,6 +32,9 @@
 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">
 <!-- 
@@ -66,29 +69,46 @@
 <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;
 	
-	choosen = ""
-	len = document.form1.imageformat.length
-	
 	for (i = 0; i <len; i++) {
 		if (document.form1.imageformat[i].checked) {
-			choosen = document.form1.imageformat[i].value
+			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
+		choosen = document.form1.imageformat[0].value;
 	}
 	else {
 		//alert(choosen)
 	}
 
-// Static for testing
-//		window.open("../php/mod_exportMapImage_server.php?target="+target+"&imagetype="+choosen+"","exportMapImage","width=180, height=200, resizable=yes ")
-//
 	
 	var idx = window.opener.getMapObjIndexByName(target);
 	
@@ -111,40 +131,37 @@
 			}		
 	}
 	wms_string = encodeURIComponent(wms_string);
-	window.open("../php/mod_exportMapImage_server.php?target="+target+"&imagetype="+choosen+"&wms_urls="+wms_string+"","exportMapImage","width=180, height=200, resizable=yes ")
+	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>
-	<span class="imageformat"><input type="radio" name="imageformat" value="png">PNG</span><br>
-	</td>
+<td> <br><br> </td>
 </tr>
-<tr>
-	<td>
-	<span class="imageformat"><input type="radio" name="imageformat" value="jpeg">JPEG / JPG</span><br>
-	</td>
-</tr>
-<!--
-<tr>
-	<td>
-		<span class="imageformat"><input type="radio" name="imageformat" value="geotiff">GeoTIFF</span><br><br>
-	</td>
-</tr>
--->
-<tr>
-	<td align="center">
-		<input type='button' name='print' value="OK" onclick='exportMapimage()'>
-	</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>

Modified: branches/2.4.5/http/php/mod_exportMapImage_server.php
===================================================================
--- branches/2.4.5/http/php/mod_exportMapImage_server.php	2008-03-03 11:36:44 UTC (rev 2159)
+++ branches/2.4.5/http/php/mod_exportMapImage_server.php	2008-03-03 14:24:20 UTC (rev 2160)
@@ -34,24 +34,13 @@
 	
 }
 
-echo "Imagetype: <br>".$imageType."<br><br>";
-
 $array_file = array();
 $array_file["dir"]  = TMPDIR; 
 $array_file["filename"] = "image"; 
 
-// static for testing 
-// $url_1 = "http://wms1.ccgis.de/cgi-bin/mapserv?map=/data/umn/germany/germany.map&VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&LAYERS=Topographie&STYLES=,,,,,,,,&SRS=EPSG:31467&BBOX=3337412.5,5636600,3366787.5,5655400&WIDTH=625&HEIGHT=400&FORMAT=image/png&BGCOLOR=0xffffff&TRANSPARENT=TRUE&EXCEPTIONS=application/vnd.ogc.se_inimage";
-// $url_2 = "http://wms1.ccgis.de/cgi-bin/mapserv?map=/data/umn/germany/germany.map&VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&LAYERS=Staedte&STYLES=,,,,,,,,&SRS=EPSG:31467&BBOX=3337412.5,5636600,3366787.5,5655400&WIDTH=625&HEIGHT=400&FORMAT=image/png&BGCOLOR=0xffffff&TRANSPARENT=TRUE&EXCEPTIONS=application/vnd.ogc.se_inimage";
-// $url_3 = "http://wms1.ccgis.de/cgi-bin/mapserv?map=/data/umn/germany/germany.map&VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&LAYERS=Bahnlinien&STYLES=,,,,,,,,&SRS=EPSG:31467&BBOX=3337412.5,5636600,3366787.5,5655400&WIDTH=625&HEIGHT=400&FORMAT=image/png&BGCOLOR=0xffffff&TRANSPARENT=TRUE&EXCEPTIONS=application/vnd.ogc.se_inimage";
-// $url_4 = "http://wms1.ccgis.de/cgi-bin/mapserv?map=/data/umn/germany/germany.map&VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&LAYERS=Strassen&STYLES=,,,,,,,,&SRS=EPSG:31467&BBOX=3337412.5,5636600,3366787.5,5655400&WIDTH=625&HEIGHT=400&FORMAT=image/png&BGCOLOR=0xffffff&TRANSPARENT=TRUE&EXCEPTIONS=application/vnd.ogc.se_inimage";
-// $array_urls  = array ($url_1, $url_2, $url_3, $url_4);
-
 $array_urls = explode("___", $wms_urls);
 $image = new weldMaps2Image($array_urls, $array_file);
- 
- 
- $image->getImage($imageType, 'file');
+$image->getImage($imageType, 'file');
 
  
 ?>



More information about the Mapbender_commits mailing list