/** * Copyright (c) 2008-2010 The Open Source Geospatial Foundation * * Published under the BSD license. * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text * of the license. */ Ext.namespace("GeoExt.plugins"); /** api: (define) * module = GeoExt.plugins * class = PrintExtent */ /** api: example * Sample code to create a MapPanel with a PrintExtent, and print it * immediately: * * .. code-block:: javascript * * var printExtent = new GeoExt.plugins.PrintExtent({ * printProvider: new GeoExt.data.PrintProvider({ * capabilities: printCapabilities * }) * }); * * var mapPanel = new GeoExt.MapPanel({ * border: false, * renderTo: "div-id", * layers: [new OpenLayers.Layer.WMS("Tasmania", "http://demo.opengeo.org/geoserver/wms", * {layers: "topp:tasmania_state_boundaries"}, {singleTile: true})], * center: [146.56, -41.56], * zoom: 6, * plugins: printExtent * }); * * printExtent.addPage(); * * // print the map * printExtent.print(); */ /** api: constructor * .. class:: PrintExtent * * Provides a way to show and modify the extents of print pages on the map. It * uses a layer to render the page extent and handle features of print pages, * and provides a control to modify them. Must be set as a plugin to a * :class:`GeoExt.MapPanel`. */ GeoExt.plugins.PrintExtent = Ext.extend(Ext.util.Observable, { /** private: initialConfig * ``Object`` Holds the initial config object passed to the * constructor. */ initialConfig: null, /** api: config[printProvider] * :class:`GeoExt.data.PrintProvider` The print provider this form * is connected to. Optional if pages are provided. */ /** api: property[printProvider] * :class:`GeoExt.data.PrintProvider` The print provider this form * is connected to. Read-only. */ printProvider: null, /** private: property[map] * ``OpenLayers.Map`` The map the layer and control are added to. */ map: null, /** api: config[layer] * ``OpenLayers.Layer.Vector`` The layer used to render extent and handle * features to. Optional, will be created if not provided. */ /** private: property[layer] * ``OpenLayers.Layer.Vector`` The layer used to render extent and handle * features to. */ layer: null, /** private: property[control] * ``OpenLayers.Control.TransformFeature`` The control used to change * extent, center, rotation and scale. */ control: null, /** api: config[pages] * Array of :class:`GeoExt.data.PrintPage` The pages that this plugin * controls. Optional. If not provided, it will be created with one page * that is completely contained within the visible map extent. * * .. note:: All pages must use the same PrintProvider. */ /** api: property[pages] * Array of :class:`GeoExt.data.PrintPage` The pages that this component * controls. Read-only. */ pages: null, /** api: property[page] * :class:`GeoExt.data.PrintPage` The page currently set for * transformation. */ page: null, /** private: method[constructor] * Private constructor override. */ constructor: function(config) { config = config || {}; Ext.apply(this, config); this.initialConfig = config; if(!this.printProvider) { this.printProvider = this.pages[0].printProvider; } if(!this.pages) { this.pages = []; } this.addEvents( /** api: event[selectpage] * Triggered when a page has been selected using the control * * Listener arguments: * * printPage - :class:`GeoExt.data.PrintPage` this printPage */ "selectpage" ); GeoExt.plugins.PrintExtent.superclass.constructor.apply(this, arguments); }, /** api: method[print] * :param options: ``Object`` Options to send to the PrintProvider's * print method. See :class:`GeoExt.data.PrintProvider` :: ``print``. * * Prints all pages as shown on the map. */ print: function(options) { this.printProvider.print(this.map, this.pages, options); }, /** private: method[init] * :param mapPanel: class:`GeoExt.MapPanel` * * Initializes the plugin. */ init: function(mapPanel) { this.map = mapPanel.map; mapPanel.on("destroy", this.onMapPanelDestroy, this); if (!this.layer) { this.layer = new OpenLayers.Layer.Vector(null, { displayInLayerSwitcher: false }); } this.createControl(); for(var i=0, len=this.pages.length; i=0; i--) { this.removePage(this.pages[i]); } this.hide(); var control = this.control; if(map && map.events && control && control.events) { control.destroy(); } var layer = this.layer; if(!this.initialConfig.layer && map && map.events && layer && layer.events) { layer.destroy(); } delete this.layer; delete this.control; delete this.page; this.map = null; }, /** private: method[createControl] */ createControl: function() { this.control = new OpenLayers.Control.TransformFeature(this.layer, { preserveAspectRatio: true, eventListeners: { "beforesetfeature": function(e) { for(var i=0, len=this.pages.length; i