1 | |
---|
2 | .. currentmodule:: GeoExt.data |
---|
3 | |
---|
4 | :class:`GeoExt.data.PrintProvider` |
---|
5 | ================================================================================ |
---|
6 | |
---|
7 | |
---|
8 | .. cssclass:: meta |
---|
9 | |
---|
10 | |
---|
11 | Extends |
---|
12 | * `Ext.util.Observable <http://dev.sencha.com/deploy/dev/docs/?class=Ext.util.Observable>`_ |
---|
13 | |
---|
14 | |
---|
15 | |
---|
16 | |
---|
17 | |
---|
18 | |
---|
19 | |
---|
20 | .. class:: PrintProvider |
---|
21 | |
---|
22 | Provides an interface to a Mapfish or GeoServer print module. For printing, |
---|
23 | one or more instances of :class:`GeoExt.data.PrintPage` are also required |
---|
24 | to tell the PrintProvider about the scale and extent (and optionally |
---|
25 | rotation) of the page(s) we want to print. |
---|
26 | |
---|
27 | |
---|
28 | |
---|
29 | Example Use |
---|
30 | ----------- |
---|
31 | |
---|
32 | Minimal code to print as much of the current map extent as possible as |
---|
33 | soon as the print service capabilities are loaded, using the first layout |
---|
34 | reported by the print service: |
---|
35 | |
---|
36 | .. code-block:: javascript |
---|
37 | |
---|
38 | var mapPanel = new GeoExt.MapPanel({ |
---|
39 | renderTo: "mappanel", |
---|
40 | layers: [new OpenLayers.Layer.WMS("wms", "/geoserver/wms", |
---|
41 | {layers: "topp:tasmania_state_boundaries"})], |
---|
42 | center: [146.56, -41.56], |
---|
43 | zoom: 7 |
---|
44 | }); |
---|
45 | var printProvider = new GeoExt.data.PrintProvider({ |
---|
46 | url: "/geoserver/pdf", |
---|
47 | listeners: { |
---|
48 | "loadcapabilities": function() { |
---|
49 | var printPage = new GeoExt.data.PrintPage({ |
---|
50 | printProvider: printProvider |
---|
51 | }); |
---|
52 | printPage.fit(mapPanel, true); |
---|
53 | printProvider.print(mapPanel, printPage); |
---|
54 | } |
---|
55 | } |
---|
56 | }); |
---|
57 | |
---|
58 | |
---|
59 | |
---|
60 | |
---|
61 | Config Options |
---|
62 | -------------- |
---|
63 | |
---|
64 | Configuration properties in addition to |
---|
65 | those listed for `Ext.util.Observable <http://dev.sencha.com/deploy/dev/docs/?class=Ext.util.Observable>`_. |
---|
66 | |
---|
67 | |
---|
68 | .. describe:: autoLoad |
---|
69 | |
---|
70 | ``Boolean`` If set to true, the capabilities will be loaded upon |
---|
71 | instance creation, and ``loadCapabilities`` does not need to be called |
---|
72 | manually. Setting this when ``capabilities`` and no ``url`` is provided |
---|
73 | has no effect. Default is false. |
---|
74 | |
---|
75 | .. describe:: baseParams |
---|
76 | |
---|
77 | ``Object`` Key-value pairs of base params to be add to every |
---|
78 | request to the service. Optional. |
---|
79 | |
---|
80 | .. describe:: capabilities |
---|
81 | |
---|
82 | ``Object`` Capabilities of the print service. Only required if ``url`` |
---|
83 | is not provided. This is the object returned by the ``info.json`` |
---|
84 | endpoint of the print service, and is usually obtained by including a |
---|
85 | script tag pointing to |
---|
86 | http://path/to/printservice/info.json?var=myvar in the head of the |
---|
87 | html document, making the capabilities accessible as ``window.myvar``. |
---|
88 | This property should be used when no local print service or proxy is |
---|
89 | available, or when you do not listen for the ``loadcapabilities`` |
---|
90 | events before creating components that require the PrintProvider's |
---|
91 | capabilities to be available. |
---|
92 | |
---|
93 | .. describe:: customParams |
---|
94 | |
---|
95 | ``Object`` Key-value pairs of custom data to be sent to the print |
---|
96 | service. Optional. This is e.g. useful for complex layout definitions |
---|
97 | on the server side that require additional parameters. |
---|
98 | |
---|
99 | .. describe:: method |
---|
100 | |
---|
101 | ``String`` Either ``POST`` or ``GET`` (case-sensitive). Method to use |
---|
102 | when sending print requests to the servlet. If the print service is at |
---|
103 | the same origin as the application (or accessible via proxy), then |
---|
104 | ``POST`` is recommended. Use ``GET`` when accessing a remote print |
---|
105 | service with no proxy available, but expect issues with character |
---|
106 | encoding and URLs exceeding the maximum length. Default is ``POST``. |
---|
107 | |
---|
108 | .. describe:: url |
---|
109 | |
---|
110 | ``String`` Base url of the print service. Only required if |
---|
111 | ``capabilities`` is not provided. This |
---|
112 | is usually something like http://path/to/mapfish/print for Mapfish, |
---|
113 | and http://path/to/geoserver/pdf for GeoServer with the printing |
---|
114 | extension installed. This property requires that the print service is |
---|
115 | at the same origin as the application (or accessible via proxy). |
---|
116 | |
---|
117 | |
---|
118 | |
---|
119 | |
---|
120 | Public Properties |
---|
121 | ----------------- |
---|
122 | |
---|
123 | Public properties in addition to those |
---|
124 | listed for `Ext.util.Observable <http://dev.sencha.com/deploy/dev/docs/?class=Ext.util.Observable>`_. |
---|
125 | |
---|
126 | |
---|
127 | .. attribute:: PrintProvider.customParams |
---|
128 | |
---|
129 | ``Object`` Key-value pairs of custom data to be sent to the print |
---|
130 | service. Optional. This is e.g. useful for complex layout definitions |
---|
131 | on the server side that require additional parameters. |
---|
132 | |
---|
133 | .. attribute:: PrintProvider.dpi |
---|
134 | |
---|
135 | ``Ext.data.Record`` the record for the currently used resolution. |
---|
136 | Read-only, use ``setDpi`` to set the value. |
---|
137 | |
---|
138 | .. attribute:: PrintProvider.dpis |
---|
139 | |
---|
140 | ``Ext.data.JsonStore`` read-only. A store representing the dpis |
---|
141 | available. |
---|
142 | |
---|
143 | Fields of records in this store: |
---|
144 | |
---|
145 | * name - ``String`` the name of the dpi |
---|
146 | * value - ``Float`` the dots per inch |
---|
147 | |
---|
148 | .. attribute:: PrintProvider.layout |
---|
149 | |
---|
150 | ``Ext.data.Record`` the record of the currently used layout. Read-only, |
---|
151 | use ``setLayout`` to set the value. |
---|
152 | |
---|
153 | .. attribute:: PrintProvider.layouts |
---|
154 | |
---|
155 | ``Ext.data.JsonStore`` read-only. A store representing the layouts |
---|
156 | available. |
---|
157 | |
---|
158 | Fields of records in this store: |
---|
159 | |
---|
160 | * name - ``String`` the name of the layout |
---|
161 | * size - ``Object`` width and height of the map in points |
---|
162 | * rotation - ``Boolean`` indicates if rotation is supported |
---|
163 | |
---|
164 | .. attribute:: PrintProvider.scales |
---|
165 | |
---|
166 | ``Ext.data.JsonStore`` read-only. A store representing the scales |
---|
167 | available. |
---|
168 | |
---|
169 | Fields of records in this store: |
---|
170 | |
---|
171 | * name - ``String`` the name of the scale |
---|
172 | * value - ``Float`` the scale denominator |
---|
173 | |
---|
174 | |
---|
175 | |
---|
176 | |
---|
177 | Public Methods |
---|
178 | -------------- |
---|
179 | |
---|
180 | Public methods in addition to those |
---|
181 | listed for `Ext.util.Observable <http://dev.sencha.com/deploy/dev/docs/?class=Ext.util.Observable>`_. |
---|
182 | |
---|
183 | |
---|
184 | .. method:: PrintProvider.loadCapabilities |
---|
185 | |
---|
186 | Loads the capabilities from the print service. If this instance is |
---|
187 | configured with either ``capabilities`` or a ``url`` and ``autoLoad`` |
---|
188 | set to true, then this method does not need to be called from the |
---|
189 | application. |
---|
190 | |
---|
191 | .. method:: PrintProvider.print |
---|
192 | |
---|
193 | :param map: ``GeoExt.MapPanel`` or ``OpenLayers.Map`` The map to print. |
---|
194 | :param pages: ``Array`` of :class:`GeoExt.data.PrintPage` or |
---|
195 | :class:`GeoExt.data.PrintPage` page(s) to print. |
---|
196 | :param options: ``Object`` of additional options, see below. |
---|
197 | |
---|
198 | Sends the print command to the print service and opens a new window |
---|
199 | with the resulting PDF. |
---|
200 | |
---|
201 | Valid properties for the ``options`` argument: |
---|
202 | |
---|
203 | * ``legend`` - :class:`GeoExt.LegendPanel` If provided, the legend |
---|
204 | will be added to the print document. For the printed result to |
---|
205 | look like the LegendPanel, the following ``!legends`` block |
---|
206 | should be included in the ``items`` of your page layout in the |
---|
207 | print module's configuration file: |
---|
208 | |
---|
209 | .. code-block:: none |
---|
210 | |
---|
211 | - !legends |
---|
212 | maxIconWidth: 0 |
---|
213 | maxIconHeight: 0 |
---|
214 | classIndentation: 0 |
---|
215 | layerSpace: 5 |
---|
216 | layerFontSize: 10 |
---|
217 | |
---|
218 | * ``overview`` - :class:`OpenLayers.Control.OverviewMap` If provided, |
---|
219 | the layers for the overview map in the printout will be taken from |
---|
220 | the OverviewMap control. If not provided, the print service will |
---|
221 | use the main map's layers for the overview map. Applies only for |
---|
222 | layouts configured to print an overview map. |
---|
223 | |
---|
224 | .. method:: PrintProvider.setDpi |
---|
225 | |
---|
226 | :param dpi: ``Ext.data.Record`` the dpi record. |
---|
227 | |
---|
228 | Sets the dpi for this printProvider. |
---|
229 | |
---|
230 | .. method:: PrintProvider.setLayout |
---|
231 | |
---|
232 | :param layout: ``Ext.data.Record`` the record of the layout. |
---|
233 | |
---|
234 | Sets the layout for this printProvider. |
---|
235 | |
---|
236 | |
---|
237 | |
---|
238 | |
---|
239 | Events |
---|
240 | ------ |
---|
241 | |
---|
242 | Events in addition to those |
---|
243 | listed for `Ext.util.Observable <http://dev.sencha.com/deploy/dev/docs/?class=Ext.util.Observable>`_. |
---|
244 | |
---|
245 | |
---|
246 | .. describe:: beforeencodelayer |
---|
247 | |
---|
248 | Triggered before a layer is encoded. This can be used to |
---|
249 | exclude layers from the printing, by having the listener |
---|
250 | return false. |
---|
251 | |
---|
252 | Listener arguments: |
---|
253 | |
---|
254 | * printProvider - :class:`GeoExt.data.PrintProvider` this |
---|
255 | PrintProvider |
---|
256 | * layer - ``OpenLayers.Layer`` the layer which is about to be |
---|
257 | encoded. |
---|
258 | |
---|
259 | .. describe:: beforeprint |
---|
260 | |
---|
261 | Triggered when the print method is called. |
---|
262 | |
---|
263 | Listener arguments: |
---|
264 | |
---|
265 | * printProvider - :class:`GeoExt.data.PrintProvider` this |
---|
266 | PrintProvider |
---|
267 | * map - ``OpenLayers.Map`` the map being printed |
---|
268 | * pages - Array of :class:`GeoExt.data.PrintPage` the print |
---|
269 | pages being printed |
---|
270 | * options - ``Object`` the options to the print command |
---|
271 | |
---|
272 | .. describe:: dpichange |
---|
273 | |
---|
274 | Triggered when the dpi value is changed. |
---|
275 | |
---|
276 | Listener arguments: |
---|
277 | |
---|
278 | * printProvider - :class:`GeoExt.data.PrintProvider` this |
---|
279 | PrintProvider |
---|
280 | * dpi - ``Ext.data.Record`` the new dpi record |
---|
281 | |
---|
282 | .. describe:: encodelayer |
---|
283 | |
---|
284 | Triggered when a layer is encoded. This can be used to modify |
---|
285 | the encoded low-level layer object that will be sent to the |
---|
286 | print service. |
---|
287 | |
---|
288 | Listener arguments: |
---|
289 | |
---|
290 | * printProvider - :class:`GeoExt.data.PrintProvider` this |
---|
291 | PrintProvider |
---|
292 | * layer - ``OpenLayers.Layer`` the layer which is about to be |
---|
293 | encoded. |
---|
294 | * encodedLayer - ``Object`` the encoded layer that will be |
---|
295 | sent to the print service. |
---|
296 | |
---|
297 | .. describe:: layoutchange |
---|
298 | |
---|
299 | Triggered when the layout is changed. |
---|
300 | |
---|
301 | Listener arguments: |
---|
302 | |
---|
303 | * printProvider - :class:`GeoExt.data.PrintProvider` this |
---|
304 | PrintProvider |
---|
305 | * layout - ``Ext.data.Record`` the new layout |
---|
306 | |
---|
307 | .. describe:: loadcapabilities |
---|
308 | |
---|
309 | Triggered when the capabilities have finished loading. This |
---|
310 | event will only fire when ``capabilities`` is not configured. |
---|
311 | |
---|
312 | Listener arguments: |
---|
313 | |
---|
314 | * printProvider - :class:`GeoExt.data.PrintProvider` this |
---|
315 | PrintProvider |
---|
316 | * capabilities - ``Object`` the capabilities |
---|
317 | |
---|
318 | .. describe:: print |
---|
319 | |
---|
320 | Triggered when the print document is opened. |
---|
321 | |
---|
322 | Listener arguments: |
---|
323 | |
---|
324 | * printProvider - :class:`GeoExt.data.PrintProvider` this |
---|
325 | PrintProvider |
---|
326 | * url - ``String`` the url of the print document |
---|
327 | |
---|
328 | .. describe:: printexception |
---|
329 | |
---|
330 | Triggered when using the ``POST`` method, when the print |
---|
331 | backend returns an exception. |
---|
332 | |
---|
333 | Listener arguments: |
---|
334 | |
---|
335 | * printProvider - :class:`GeoExt.data.PrintProvider` this |
---|
336 | PrintProvider |
---|
337 | * response - ``Object`` the response object of the XHR |
---|
338 | |
---|
339 | |
---|
340 | |
---|