/** * @requires OpenLayers/Control.js * @requires mapfish/Protocol/MapFish.js */ /** * Class: OpenLayers.Control.PDFPrint * * * Inherits From: * - */ OpenLayers.Control.PDFPrint = OpenLayers.Class(OpenLayers.Control, { /* * i18n text for language pack */ i18n_tab_template_title: 'Template', i18n_tab_form_title: 'Form', /** * Property: formPanel * {Ext.Panel} The form panel saved so it can be recalled */ formPanel: null, /** * Property: map * {OpenLayers.Map} The map object to be called */ map: null, /** * Property: oldwindow * {Ext.Window} The window saved so it can be recalled */ oldwindow: null, /** * Property: selectedTemplate * {Object} The currently selected template */ selectedTemplate: 0, /** * Property: templates * {Object array} The array containing all templates */ templates: null, /** * Property: type * {String} The type of -- When added to a * , 'type' is used by the panel to determine how to * handle our events. */ type: OpenLayers.Control.TYPE_BUTTON, isArray: function(a) { return Object.prototype.toString.apply(a) === '[object Array]'; }, /* * Method: generatePDF * Generate the PDF with the specified template */ generatePDF: function(button, e) { var template = this.selectedTemplate; var spec = { layout: template.model, title: template.model, srs: this.map.projection.projCode, units: 'm', layers: [], pages: [ { center: [this.map.center.lon, this.map.center.lat], scale: (this.map.scales)?this.map.scales[this.map.zoom]:Math.round(OpenLayers.Util.getScaleFromResolution(this.map.resolution, "m")), resolution: (this.map.resolutions)?this.map.resolutions[this.map.zoom]:Math.round(OpenLayers.Util.getResolutionFromScale(this.map.scales[this.map.zoom], "m")), dpi: template.dpi ? template.dpi : 96 } ] }; // For each layers for (var i=0; i 0) { for (i=0; i0) { spec.pages[i] = new Object(); for (key in spec.pages[i-1]) { spec.pages[i][key] = spec.pages[i-1][key]; } } // For each page fields for (key in template.pages) { spec.pages[i][key] = template.pages[key][i]; } } } // Sends the specs to the print applet var form = document.createElement("form"); form.action = "print_proxy.php"; form.method = "POST"; form.target = "PDFPrint"; var hiddenForm = document.createElement("input"); hiddenForm.type = "hidden"; hiddenForm.name = "spec"; hiddenForm.value = escape("{"+this.stringify(spec)+"}"); document.body.insertBefore(form, null); form.insertBefore(hiddenForm, null); window.open("","PDFPrint","location=0,status=0,scrollbars=0,resizable=1"); form.submit(); document.body.removeChild(form); }, /* * Method: initializeForm * Initialize the form with the corresponding fields */ initializeForm: function(template, node) { var template = (template != null)? template:this.templates[node]; this.formPanel.removeAll(); this.selectedTemplate = template; // If there's only one field if (!template.fields.length) { template.fields = Array(template.fields.field); } for (var i=0; i0) { stringified = stringified.substr(0,stringified.length-1); } return stringified; }, /* * Method: trigger * Open the window. */ trigger: function(template) { if (template == null){template = null;} // If a template is not pushed if (!this.oldwindow) { this.store = new Ext.data.JsonStore({ data: this.templates, fields: ['name', 'thumb'] }); this.tpl = new Ext.XTemplate( '', '
', '
', '{name}
', '
', '
' ); templateChooser = new Ext.DataView({ store: this.store, tpl: this.tpl, autoWidth: true, autoHeight: true, maxHeight: 400, multiSelect: false, singleSelect: true, overClass:'x-view-over', itemSelector:'div.thumb-wrap', emptyText: '', ownerWidget: this, listeners: { click: { fn: function(dv,nodes){ this.ownerWidget.initializeForm(null, nodes); } } } }); templatePanel = new Ext.Panel({ id:'images-view', frame:true, autoWidth: true, autoHeight: true, maxHeight: 400, title: this.i18n_tab_template_title, autoScroll: true, items: [templateChooser] }); this.formPanel = new Ext.FormPanel({ id:'formPDF', frame:true, autoWidth: true, autoHeight: true, minHeight: 200, title: this.i18n_tab_form_title, autoScroll: true, items: [] }); this.initializeForm(template, 0); this.oldwindow = new Ext.Window({ id: 'PDFPrint', title: 'PDF', closeAction: 'hide', resizable: true, items: [templatePanel, this.formPanel], width: 450 }); templateChooser.select(0); } if (template) { this.initializeForm(template, 0); this.generatePDF(null, null); }else{ this.oldwindow.show(); } }, CLASS_NAME: "OpenLayers.Control.PDFPrint" });