[Mapbender-commits] r8395 - trunk/mapbender/http/plugins
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Tue Jun 26 23:26:01 PDT 2012
Author: verenadiewald
Date: 2012-06-26 23:26:01 -0700 (Tue, 26 Jun 2012)
New Revision: 8395
Modified:
trunk/mapbender/http/plugins/mb_print.php
Log:
add possibility to configure a selectbox for scale selection
Modified: trunk/mapbender/http/plugins/mb_print.php
===================================================================
--- trunk/mapbender/http/plugins/mb_print.php 2012-06-27 06:24:18 UTC (rev 8394)
+++ trunk/mapbender/http/plugins/mb_print.php 2012-06-27 06:26:01 UTC (rev 8395)
@@ -3,7 +3,7 @@
*
* Description:
* Mapbender print PDF with PDF templates module.
- *
+ *
* Files:
* - http/plugins/mb_print.php
* - http/print/classes
@@ -12,9 +12,9 @@
* - lib/printbox.js
*
* SQL:
- * > INSERT INTO gui_element(fkey_gui_id, e_id, e_pos, e_public, e_comment,
- * > e_title, e_element, e_src, e_attributes, e_left, e_top, e_width,
- * > e_height, e_z_index, e_more_styles, e_content, e_closetag, e_js_file,
+ * > INSERT INTO gui_element(fkey_gui_id, e_id, e_pos, e_public, e_comment,
+ * > e_title, e_element, e_src, e_attributes, e_left, e_top, e_width,
+ * > e_height, e_z_index, e_more_styles, e_content, e_closetag, e_js_file,
* > e_mb_mod, e_target, e_requires, e_url) VALUES('<appId>','printPDF',
* > 2,1,'pdf print','Print','div','','',1,1,2,2,5,'',
* > '<div id="printPDF_working_bg"></div><div id="printPDF_working"><img src="../img/indicator_wheel.gif" style="padding:10px 0 0 10px">Generating PDF</div><div id="printPDF_input"><form id="printPDF_form" action="../print/printFactory.php"><div id="printPDF_selector"></div><div class="print_option"><input type="hidden" id="map_url" name="map_url" value=""/><input type="hidden" id="legend_url" name="legend_url" value=""/><input type="hidden" id="overview_url" name="overview_url" value=""/><input type="hidden" id="map_scale" name="map_scale" value=""/><input type="hidden" name="measured_x_values" /><input type="hidden" name="measured_y_values" /><br /></div><div class="print_option" id="printPDF_formsubmit"><input id="submit" type="submit" value="Print"><br /></div></form><div id="printPDF_result"></div></div>',
@@ -22,8 +22,8 @@
* > '../../lib/printbox.js,../extensions/jquery-ui-1.7.2.custom/development-bundle/external/bgiframe/jquery.bgiframe.js,../extensions/jquery.form.min.js',
* > 'mapframe1','','http://www.mapbender.org/index.php/Print');
* >
- * > INSERT INTO gui_element_vars(fkey_gui_id, fkey_e_id, var_name,
- * > var_value, context, var_type) VALUES('<appId>', 'printPDF',
+ * > INSERT INTO gui_element_vars(fkey_gui_id, fkey_e_id, var_name,
+ * > var_value, context, var_type) VALUES('<appId>', 'printPDF',
* > 'mbPrintConfig', '{"Standard": "mapbender_template.json"}', '' ,'var');
* >
* > INSERT INTO gui_element_vars(fkey_gui_id, fkey_e_id, var_name,
@@ -45,14 +45,14 @@
* > INSERT INTO gui_element_vars(fkey_gui_id, fkey_e_id, var_name,
* > var_value, context, var_type) VALUES('<appId>', 'body',
* > 'print_css', '../css/print_div.css', '' ,'file/css');
- *
+ *
* Help:
* http://www.mapbender.org/PrintPDF_with_template
*
* Maintainer:
* http://www.mapbender.org/User:Michael_Schulz
* http://www.mapbender.org/User:Christoph_Baudson
- *
+ *
* Parameters:
* mbPrintConfig - *[optional]* object with name and filename of template,
* like {
@@ -62,8 +62,8 @@
*
* License:
* Copyright (c) 2009, Open Source Geospatial Foundation
- * This program is dual licensed under the GNU General Public License
- * and Simplified BSD license.
+ * This program is dual licensed under the GNU General Public License
+ * and Simplified BSD license.
* http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
*/
@@ -99,10 +99,10 @@
var PrintPDF = function (options) {
var that = this;
-
+
/**
* Property: actualConfig
- *
+ *
* object, holds the actual configuration after loading the json file
*/
var actualConfig;
@@ -113,14 +113,14 @@
eventInit.register(function () {
mod_printPDF_init();
});
-
+
/**
* Property: printBox
- *
+ *
* the movable printframe
- */
+ */
var printBox = null;
-
+
eventAfterMapRequest.register(function () {
if (printBox !== null) {
printBox.repaint();
@@ -128,8 +128,8 @@
});
/**
* Method: createPrintBox
- *
- * creates a printBox in the current view, calculates the scale
+ *
+ * creates a printBox in the current view, calculates the scale
* (tbd. if not set from the config) so that the printbox fits in the mapframe.
* Width and height are taken from the configuration.
*/
@@ -145,42 +145,48 @@
var $scaleInput = $("#scale");
if (printBox !== null) {
- destroyPrintBox();
+ destroyPrintBox();
jqForm[0].scale.value = "";
jqForm[0].coordinates.value = "";
jqForm[0].angle.value = "";
}
else {
- printBox = new Mapbender.PrintBox({
+ printBox = new Mapbender.PrintBox({
target : myTarget,
printWidth : getPDFMapSize("width")/10,
printHeight : getPDFMapSize("height")/10,
- scale : $scaleInput.size() > 0 && !isNaN(parseInt($scaleInput.val(), 10)) ?
- parseInt($scaleInput.val(), 10) :
+ scale : $scaleInput.size() > 0 && !isNaN(parseInt($scaleInput.val(), 10)) ?
+ parseInt($scaleInput.val(), 10) :
Math.pow(10, Math.floor(Math.log(map.getScale())/Math.LN10)),
afterChangeAngle : function (obj) {
if (typeof(obj) == "object") {
if (typeof(obj.angle) == "number") {
- if(typeof(jqForm[0].angle) != "undefined") {
- jqForm[0].angle.value = obj.angle;
- }
+ if(typeof(jqForm[0].angle) != "undefined") {
+ jqForm[0].angle.value = obj.angle;
+ }
}
if (obj.coordinates) {
- if(typeof(jqForm[0].coordinates) != "undefined") {
- jqForm[0].coordinates.value = String(obj.coordinates);
- }
+ if(typeof(jqForm[0].coordinates) != "undefined") {
+ jqForm[0].coordinates.value = String(obj.coordinates);
+ }
}
}
},
afterChangeSize : function (obj) {
if (typeof(obj) == "object") {
if (obj.scale) {
- jqForm[0].scale.value = parseInt(obj.scale / 10, 10) * 10;
+ if($("#scale").is("input")) {
+ jqForm[0].scale.value = parseInt(obj.scale / 10, 10) * 10;
+ }
+ else {
+ $("#scale .addedScale").remove();
+ $("#scale").append("<option selected class='addedScale' value='"+parseInt(obj.scale / 10, 10) * 10+"'>1 : " + parseInt(obj.scale / 10, 10) * 10 + "</option>");
+ }
}
if (obj.coordinates) {
- if(typeof(jqForm[0].coordinates) != "undefined") {
- jqForm[0].coordinates.value = String(obj.coordinates);
- }
+ if(typeof(jqForm[0].coordinates) != "undefined") {
+ jqForm[0].coordinates.value = String(obj.coordinates);
+ }
}
}
}
@@ -193,12 +199,12 @@
/**
* Method: getPDFMapSize
- *
+ *
* checks the actual config for the size w/h values.
*
* Parameters:
* key - string, the key which value to retrieve (currently width or height)
- */
+ */
var getPDFMapSize = function (key) {
for (var page in actualConfig.pages) {
for (var pageElement in actualConfig.pages[page].elements) {
@@ -206,29 +212,29 @@
return actualConfig.pages[page].elements[pageElement][key];
}
}
- }
+ }
};
/**
* Method: destroyPrintBox
- *
+ *
* removes an existing printBox.
- */
+ */
var destroyPrintBox = function () {
if (printBox) {
printBox.destroy();
printBox = null;
}
};
-
+
/**
* Method: mod_printPDF_init
- *
+ *
* initializes the print modules, generates template chooser and loads first configuration.
- */
+ */
var mod_printPDF_init = function () {
/* first we'd need to build the configuration selection */
- buildConfigSelector();
+ buildConfigSelector();
/* second we'd need to read the json configuration */
that.loadConfig(mbPrintConfigFilenames[0]);
/* than we need the translation of the print button */
@@ -247,15 +253,15 @@
/**
* Method: loadConfig
- *
+ *
* GETs the config, build corresponding form, remove an existing printBox
- */
+ */
this.loadConfig = function (configFilename, callback) {
- // the dataType to $.get is given explicitely, because there were instances of Mapbender that were returning
+ // the dataType to $.get is given explicitely, because there were instances of Mapbender that were returning
// either json or a string, which trips up $.parseJSON which was being used in the callback
$.get(mbPrintConfigPath + configFilename, function(json, status){
actualConfig = json;
- buildForm();
+ buildForm();
hookForm();
if (typeof callback === "function") {
printBox = null;
@@ -263,14 +269,14 @@
}
},"json");
destroyPrintBox();
-
+
};
/**
* Method: hookForm
- *
+ *
* utility method to connect the form plugin to the print form.
- */
+ */
var hookForm = function () {
var o = {
url: '../print/printFactory.php?e_id='+myId,
@@ -286,9 +292,9 @@
};
$("#"+myId+"_form").ajaxForm(o);
};
-
+
/**
- * Change status of the working elements. These should begin with "$myId_working"
+ * Change status of the working elements. These should begin with "$myId_working"
*
* @param {String} newStatus either "hide or "show"
*/
@@ -297,10 +303,10 @@
$("[id^='"+myId+"_working']").hide();
}
else {
- $("[id^='"+myId+"_working']").show();
+ $("[id^='"+myId+"_working']").show();
}
};
-
+
/**
* update form values helper function
*
@@ -311,7 +317,7 @@
formData[j].value = value;
break;
}
- }
+ }
};
var getCurrentResolution = function (type) {
@@ -386,31 +392,31 @@
*/
var validate = function (formData, jqForm, params) {
showHideWorking("show");
-
+
// map urls
var ind = getMapObjIndexByName(myTarget);
var f = jqForm[0];
f.map_url.value = '';
-
+
var scale = f.scale.value || mb_mapObj[ind].getScale();
scale = parseInt(scale, 10);
-
+
var legendUrlArray = [];
f.overview_url.value = '';
for(var i=0; i < mb_mapObj[ind].wms.length; i++){
var currentWms = mb_mapObj[ind].wms[i];
if(mb_mapObj[ind].wms[i].gui_wms_visible > 0){
- if (mb_mapObj[ind].wms[i].mapURL != false && mb_mapObj[ind].wms[i].mapURL != 'false' && mb_mapObj[ind].wms[i].mapURL != ''){
+ if (mb_mapObj[ind].wms[i].mapURL != false && mb_mapObj[ind].wms[i].mapURL != 'false' && mb_mapObj[ind].wms[i].mapURL != ''){
if(f.map_url.value != ""){
f.map_url.value += '___';
- }
+ }
var currentMapUrl = mb_mapObj[ind].getMapUrl(i, mb_mapObj[ind].getExtentInfos(), scale);
-
+
currentMapUrl = replaceMapFileForHighQualityPrint(currentMapUrl, "map");
f.map_url.value += currentMapUrl
var wmsLegendObj = [];
-
+
var layers = currentWms.getLayers(mb_mapObj[ind], scale);
for (var j = 0; j < layers.length; j++) {
var currentLayer = currentWms.getLayerByLayerName(layers[j]);
@@ -435,7 +441,7 @@
var tmpObj = {};
tmpObj[currentWms.wms_currentTitle] = wmsLegendObj;
legendUrlArray.push(tmpObj);
-
+
}
}
}
@@ -444,7 +450,7 @@
updateFormField(formData, "legend_url", legendUrlArrayJson);
updateFormField(formData, "map_url", f.map_url.value);
updateFormField(formData, "scale", scale);
-
+
//overview_url
var ind_overview = getMapObjIndexByName('overview');
if(mb_mapObj[ind_overview].mapURL != false ){
@@ -455,7 +461,7 @@
updateFormField(formData, "overview_url", f.overview_url.value);
}
-
+
updateFormField(formData, "map_scale", mb_getScale(myTarget));
// write the measured coordinates
if (typeof(mod_measure_RX) !== "undefined") {
@@ -497,14 +503,14 @@
width: 40 * 2,
height: 40 * 2,
offset_x: 40,
- offset_y: 40
+ offset_y: 40
});
}
var permanentImage = JSON.stringify(markers);
updateFormField(formData, "mypermanentImage", permanentImage);
}
-
+
if (f.map_url.value!="") {
//return true;
} else {
@@ -515,16 +521,16 @@
/**
* Method: showResult
- *
- * load the generated PDF from the returned URL as an attachment,
+ *
+ * load the generated PDF from the returned URL as an attachment,
* that triggers a download popup or is displayed in PDF plugin.
- */
+ */
var showResult = function (res, text) {
if (text == 'success') {
var $downloadFrame = $("#" + myId + "_frame");
if ($downloadFrame.size() === 0) {
$downloadFrame = $(
- "<iframe id='" + myId + "_frame' name='" +
+ "<iframe id='" + myId + "_frame' name='" +
myId + "_frame' width='0' height='0' style='display:none'></iframe>"
).appendTo("body");
}
@@ -541,7 +547,7 @@
});
}
else {
- window.frames[myId + "_frame"].location.href =
+ window.frames[myId + "_frame"].location.href =
stripslashes(res.outputFileName);
}
showHideWorking("hide");
@@ -553,11 +559,11 @@
$("#"+myId+"_result").html(text);
}
};
-
+
/**
* Generates form elements as specified in the config controls object.
* Adds the elements before the submit button.
- *
+ *
* @param {Object} json the config object in json
*/
var buildForm = function () {
@@ -567,13 +573,15 @@
var element = actualConfig.controls[item];
var element_id = myId + "_" + element.id;
if (element.type != "hidden") {
- str += '<div class="print_option_dyn">\n';
+ str += '<div class="print_option_dyn">\n';
str += '<label class="print_label" for="'+element.id+'">'+element.label+'</label>\n';
} else {
- str += '<div class="print_option_dyn" style="display:none;">\n';
+ str += '<div class="print_option_dyn" style="display:none;">\n';
}
+
if(element.maxCharacter) {
var maxLength = 'maxlength="'+element.maxCharacter+'"';
+
}
else {
var maxLength = "";
@@ -587,7 +595,7 @@
break;
case "textarea":
str += '<textarea id="'+element.id+'" name="'+element.id+'" size="'+element.size+'" '+maxLength+'></textarea><br>\n';
- break;
+ break;
case "select":
str += '<select id="'+element.id+'" name="'+element.id+'" size="1">\n';
for (var option_index in element.options) {
@@ -609,26 +617,43 @@
}
});
$("#" + myId + "_formsubmit").before(str);
- $("#scale").keydown(function (e) {
- if (e.keyCode === 13) {
- return false;
- }
- }).keyup(function (e) {
- if (e.keyCode === 13) {
- return false;
- }
-
- var scale = parseInt(this.value, 10);
+ if($("#scale").is("input")) {
+ $("#scale").keydown(function (e) {
+ if (e.keyCode === 13) {
+ return false;
+ }
+ }).keyup(function (e) {
+ if (e.keyCode === 13) {
+ return false;
+ }
+
+ var scale = parseInt(this.value, 10);
+ if (isNaN(scale) || typeof printBox === "undefined") {
+ return true;
+ }
+
+ if(scale < 10) {
+ return true;
+ }
+ printBox.setScale(scale);
+ return true;
+ });
+ }
+ else {
+ $("#scale").change(function (e) {
+ var scale = parseInt(this.value, 10);
if (isNaN(scale) || typeof printBox === "undefined") {
return true;
}
- if(scale < 10) {
- return true;
- }
- printBox.setScale(scale);
- return true;
- });
+ if(scale < 10) {
+ return true;
+ }
+ printBox.setScale(scale);
+ return true;
+ });
+ }
+
$("#angle").keydown(function (e) {
if (e.keyCode === 13) {
return false;
@@ -646,7 +671,7 @@
});
}
};
-
+
/**
* Generates the configuration select element from the gui element vars
* mbPrintConfigFilenames and mbPrintConfigTitles
@@ -663,20 +688,20 @@
$("#printPDF_selector").append(str).find("#printPDF_template").change(function () {
printObj.loadConfig(mbPrintConfigFilenames[this.selectedIndex], function () {
printObj.createPrintBox()
- });
+ });
});
-
+
$("#printPDF_handle").click(function () {
printObj.createPrintBox();
});
- $("#printPDF_working").bgiframe({
+ $("#printPDF_working").bgiframe({
src: "BLOCKED SCRIPT'<html></html>';",
width: 200,
height: 200
});
}
};
-
+
var stripslashes = function ( str ) {
return (str+'').replace(/\0/g, '0').replace(/\\([\\'"])/g, '$1');
};
More information about the Mapbender_commits
mailing list