source:
trunk/workshop-routing-foss4g/web/GeoExt/examples/print-page.js
@
77
Revision 76, 2.3 KB checked in by djay, 13 years ago (diff) | |
---|---|
|
Line | |
---|---|
1 | /** |
2 | * Copyright (c) 2008-2010 The Open Source Geospatial Foundation |
3 | * |
4 | * Published under the BSD license. |
5 | * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text |
6 | * of the license. |
7 | */ |
8 | |
9 | /** api: example[print-page] |
10 | * Print Your Map |
11 | * -------------- |
12 | * Print the visible extent of a MapPanel with PrintPage and PrintProvider. |
13 | */ |
14 | |
15 | var mapPanel, printPage; |
16 | |
17 | Ext.onReady(function() { |
18 | // The printProvider that connects us to the print service |
19 | var printProvider = new GeoExt.data.PrintProvider({ |
20 | method: "GET", // "POST" recommended for production use |
21 | capabilities: printCapabilities // from the info.json script in the html |
22 | }); |
23 | // Our print page. Tells the PrintProvider about the scale and center of |
24 | // our page. |
25 | printPage = new GeoExt.data.PrintPage({ |
26 | printProvider: printProvider, |
27 | customParams: { |
28 | mapTitle: "Printing Demo", |
29 | comment: "This is a simple map printed from GeoExt." |
30 | } |
31 | }); |
32 | |
33 | // The map we want to print |
34 | mapPanel = new GeoExt.MapPanel({ |
35 | region: "center", |
36 | layers: [new OpenLayers.Layer.WMS("Tasmania", "http://demo.opengeo.org/geoserver/wms", |
37 | {layers: "topp:tasmania_state_boundaries"}, {singleTile: true})], |
38 | center: [146.56, -41.56], |
39 | zoom: 7 |
40 | }); |
41 | // The legend to optionally include on the printout |
42 | var legendPanel = new GeoExt.LegendPanel({ |
43 | region: "west", |
44 | width: 150, |
45 | bodyStyle: "padding:5px", |
46 | layerStore: mapPanel.layers |
47 | }); |
48 | |
49 | var includeLegend; // controlled by the "Include legend?" checkbox |
50 | |
51 | // The main panel |
52 | new Ext.Panel({ |
53 | renderTo: "content", |
54 | layout: "border", |
55 | width: 700, |
56 | height: 420, |
57 | items: [mapPanel, legendPanel], |
58 | bbar: ["->", { |
59 | text: "Print", |
60 | handler: function() { |
61 | // convenient way to fit the print page to the visible map area |
62 | printPage.fit(mapPanel, true); |
63 | // print the page, optionally including the legend |
64 | printProvider.print(mapPanel, printPage, includeLegend && {legend: legendPanel}); |
65 | } |
66 | }, { |
67 | xtype: "checkbox", |
68 | boxLabel: "Include legend?", |
69 | handler: function() {includeLegend = this.checked} |
70 | }] |
71 | }); |
72 | }); |
Note: See TracBrowser
for help on using the repository browser.