[Mapbender-commits] r7514 - in trunk/mapbender/http: classes plugins
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Feb 2 03:30:10 EST 2011
Author: armin11
Date: 2011-02-02 00:30:10 -0800 (Wed, 02 Feb 2011)
New Revision: 7514
Added:
trunk/mapbender/http/classes/class_weldMaps2JPEG.php
Modified:
trunk/mapbender/http/plugins/mb_metadata_edit.js
trunk/mapbender/http/plugins/mb_metadata_layerPreview.php
trunk/mapbender/http/plugins/mb_metadata_saveLayerPreview.js
trunk/mapbender/http/plugins/mb_metadata_wmcPreview.php
Log:
Some changes to metadata editors - save previews as jpg and not as png cause they are much smaler. If they are showed in a long result list it would be very slow if you have a bad internet connection.
Added: trunk/mapbender/http/classes/class_weldMaps2JPEG.php
===================================================================
--- trunk/mapbender/http/classes/class_weldMaps2JPEG.php (rev 0)
+++ trunk/mapbender/http/classes/class_weldMaps2JPEG.php 2011-02-02 08:30:10 UTC (rev 7514)
@@ -0,0 +1,82 @@
+<?php
+# $Id: class_weldMaps2PNG.php 5529 2010-02-19 15:54:30Z christoph $
+# http://www.mapbender.org/index.php/class_weldMaps2JPEG.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_weldMaps2JPEG
+* @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");
+
+class weldMaps2JPEG{
+
+ function weldMaps2JPEG($urls,$filename, $encode = true){
+ if(!$urls || $urls == ""){
+ $e = new mb_exception("weldMaps2JPEG: no maprequests delivered");
+ }
+ $url = explode("___", $urls);
+ $obj1 = new stripRequest($url[0]);
+ $width = $obj1->get("width");
+ $height = $obj1->get("height");
+
+ $image = imagecreatetruecolor($width, $height );
+ $white = ImageColorAllocate($image,255,255,255);
+ ImageFilledRectangle($image,0,0,$width,$height,$white);
+
+ for($i=0; $i<count($url); $i++){
+ $obj = new stripRequest($url[$i]);
+
+ $url[$i] = $obj->setPNG();
+ $url[$i] = $obj->encodeGET($encode);
+ $img = $this->loadpng($url[$i]);
+ if($img != false){
+ imagecopy($image, $img, 0, 0, 0, 0, $width, $height);
+ @imagedestroy($img);
+ }
+ else{
+ $e = new mb_exception("weldMaps2JPEG: unable to load image: " . $url[$i]);
+ }
+ }
+ imagejpeg($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("weldMaps2JPEG: unable to load image: ".$imgurl);
+ }
+ return $im;
+
+ }
+
+}
+
+?>
Modified: trunk/mapbender/http/plugins/mb_metadata_edit.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_edit.js 2011-02-01 20:15:27 UTC (rev 7513)
+++ trunk/mapbender/http/plugins/mb_metadata_edit.js 2011-02-02 08:30:10 UTC (rev 7514)
@@ -109,7 +109,7 @@
if (!formReady) {
$metadataForm.load("../plugins/mb_metadata_edit.php", function () {
$metadataForm.find(".help-dialog").helpDialog();
- $metadataForm.find(".original-metadata-wms").bind("click", function() {
+ $metadataForm.find(".original-metadata-wms").bind("click", function() {
showOriginalMetadata();
});
validator = $metadataForm.validate({
Modified: trunk/mapbender/http/plugins/mb_metadata_layerPreview.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_layerPreview.php 2011-02-01 20:15:27 UTC (rev 7513)
+++ trunk/mapbender/http/plugins/mb_metadata_layerPreview.php 2011-02-02 08:30:10 UTC (rev 7514)
@@ -2,19 +2,24 @@
require_once(dirname(__FILE__)."/../../core/globalSettings.php");
require_once(dirname(__FILE__)."/../../http/classes/class_connector.php");
require_once(dirname(__FILE__)."/../../http/classes/class_administration.php");
-
+require_once(dirname(__FILE__)."/../classes/class_weldMaps2JPEG.php");
//define("LAYER_PREVIEW_BASE","../tmp/layerpreviews/");
-define("LAYER_PREVIEW_BASE","../tmp/");
+//define("LAYER_PREVIEW_BASE","../tmp/");
-$layerPreviewMapFileName = LAYER_PREVIEW_BASE . sha1(uniqid(rand()));
-$layerPreviewLegendFileName = LAYER_PREVIEW_BASE . sha1(uniqid(rand()));
+
$ajaxResponse = new AjaxResponse($_REQUEST);
$mapurl = $ajaxResponse->getParameter("mapurl");
$layerName = $ajaxResponse->getParameter("layerName");
$legendUrl = $ajaxResponse->getParameter("legendUrl");
$wmsId = $ajaxResponse->getParameter("wmsId");
+$layerId = $ajaxResponse->getParameter("layerId");
+$layerPreviewMapFileName = PREVIEW_DIR ."/".$layerId."_layer_map_preview.jpg";
+$layerPreviewLegendFileName = PREVIEW_DIR ."/".$layerId."_layer_legend_preview.jpg";
+
+
+
if(!$mapurl){
$ajaxResponse->setSuccess(false);
$ajaxResponse->setMessage('mapURL not set');
@@ -41,29 +46,38 @@
switch ($ajaxResponse->getMethod()) {
case "saveLayerPreview":
- $con = new connector();
- $admin = new administration();
- $mapImage = $con->load($mapurl);
- if (!$mapImage) {
+ $mapImg = new weldMaps2JPEG($mapurl, $layerPreviewMapFileName);
+ if(!$mapImg) {
$ajaxResponse->setSuccess(false);
- $ajaxResponse->setMessage('Could not save preview: Unable to load map image.');
- $ajaxResponse->send();
+ $ajaxResponse->setMessage('Map preview could not be created');
+ $ajaxResponse->send();
+ }
+ else {
+ $ajaxResponse->setSuccess(true);
+ $ajaxResponse->setMessage('Preview saved as '.$layerPreviewMapFileName);
+ $ajaxResponse->send();
}
- $admin->saveFile($layerPreviewMapFileName,$mapImage);
-
+
if ($legendUrl) {
- $legendImage = $con->load($legendUrl);
- if (!$legendImage) {
+ $legendImg = new weldMaps2JPEG($legendUrl, $layerPreviewLegendFileName);
+ /*if(!$legendImg) {
$ajaxResponse->setSuccess(false);
- $ajaxResponse->setMessage('Could not save preview: Unable to load map image.');
- $ajaxResponse->send();
- }
- $admin->saveFile($layerPreviewLegendFileName,$legendImage);
+ $ajaxResponse->setMessage('Legend preview could not be created');
+ $ajaxResponse->send();
+ }
+ else {
+ $ajaxResponse->setSuccess(true);
+ $ajaxResponse->setMessage('Preview saved');
+ $ajaxResponse->send();
+ }*/
}
else {
$legendUrl = null;
}
+
+ break;
+
$updateSQL = <<<SQL
UPDATE layer_preview SET
@@ -112,4 +126,4 @@
$ajaxResponse->setMessage("invalid method");
}
$ajaxResponse->send();
-?>
\ No newline at end of file
+?>
Modified: trunk/mapbender/http/plugins/mb_metadata_saveLayerPreview.js
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_saveLayerPreview.js 2011-02-01 20:15:27 UTC (rev 7513)
+++ trunk/mapbender/http/plugins/mb_metadata_saveLayerPreview.js 2011-02-02 08:30:10 UTC (rev 7514)
@@ -15,9 +15,12 @@
var wms = map.wms[map.wms.length-1];
var url = wms.mapURL;
var wmsId = wms.wms_id;
+ var layerId = layer.layer_id;
if (!layer || !layer.layer_name) {
+ alert("No layer defined or layer is not named and cannot be requested!");
return;
}
+ var layerId = layer.layer_id;
var layerName = layer.layer_name;
var layerParent = wms.checkLayerParentByLayerName(layerName);
@@ -36,7 +39,8 @@
method: "saveLayerPreview",
parameters : {
mapurl: url,
- wmsId: wmsId,
+ wmsId: wmsId,
+ layerId: layerId,
legendUrl: legendUrl,
layerName: layerName
},
Modified: trunk/mapbender/http/plugins/mb_metadata_wmcPreview.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_wmcPreview.php 2011-02-01 20:15:27 UTC (rev 7513)
+++ trunk/mapbender/http/plugins/mb_metadata_wmcPreview.php 2011-02-02 08:30:10 UTC (rev 7514)
@@ -3,7 +3,7 @@
require_once(dirname(__FILE__)."/../classes/class_connector.php");
require_once(dirname(__FILE__)."/../classes/class_administration.php");
require_once(dirname(__FILE__)."/../classes/class_stripRequest.php");
-require_once(dirname(__FILE__)."/../classes/class_weldMaps2PNG.php");
+require_once(dirname(__FILE__)."/../classes/class_weldMaps2JPEG.php");
$ajaxResponse = new AjaxResponse($_REQUEST);
@@ -24,7 +24,7 @@
switch ($ajaxResponse->getMethod()) {
case "saveWmcPreview":
- $img = new weldMaps2PNG(implode("___",$mapUrls), PREVIEW_DIR."/".$wmcId."_wmc_preview.png");
+ $img = new weldMaps2JPEG(implode("___",$mapUrls), PREVIEW_DIR."/".$wmcId."_wmc_preview.jpg");
if(!$img) {
$ajaxResponse->setSuccess(false);
$ajaxResponse->setMessage('Preview could not be created');
@@ -43,4 +43,4 @@
$ajaxResponse->setMessage("invalid method");
}
$ajaxResponse->send();
-?>
\ No newline at end of file
+?>
More information about the Mapbender_commits
mailing list