[Commits] r1767 - in sandbox/ahocevar/playground/trunk/geoext: examples lib/GeoExt/data tests tests/lib/GeoExt/data
commits at geoext.org
commits at geoext.org
Mon Jan 18 16:49:16 CET 2010
Author: ahocevar
Date: 2010-01-18 16:49:16 +0100 (Mon, 18 Jan 2010)
New Revision: 1767
Added:
sandbox/ahocevar/playground/trunk/geoext/examples/print-page.html
sandbox/ahocevar/playground/trunk/geoext/examples/print-page.js
sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/data/PrintPage.html
sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/data/PrintProvider.html
Modified:
sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/data/PrintPage.js
sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/data/PrintProvider.js
sandbox/ahocevar/playground/trunk/geoext/tests/list-tests.html
Log:
unit tests and example for PrintPage and PrintProvider
Added: sandbox/ahocevar/playground/trunk/geoext/examples/print-page.html
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/examples/print-page.html (rev 0)
+++ sandbox/ahocevar/playground/trunk/geoext/examples/print-page.html 2010-01-18 15:49:16 UTC (rev 1767)
@@ -0,0 +1,31 @@
+<html>
+ <head>
+ <title>GeoExt PrintPage Example</title>
+
+ <script type="text/javascript" src="http://extjs.cachefly.net/ext-2.2.1/adapter/ext/ext-base.js"></script>
+ <script type="text/javascript" src="http://extjs.cachefly.net/ext-2.2.1/ext-all.js"></script>
+ <link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-2.2.1/resources/css/ext-all.css" />
+ <link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-2.2.1/examples/shared/examples.css" />
+ <script src="http://openlayers.org/api/2.8/OpenLayers.js"></script>
+ <script type="text/javascript" src="../lib/GeoExt.js"></script>
+
+ <script type="text/javascript" src="print-page.js"></script>
+
+ <!-- The script below will load the capabilities of the print service
+ and save them into the global printCapabilities variable. Instead
+ of this, the PrintProvider can be configured with a url and take
+ care of fetching the capabilities. -->
+ <script type="text/javascript" src="http://demo.opengeo.org/geoserver/pdf/info.json?var=printCapabilities"></script>
+
+ </head>
+ <body>
+ <h1>Printing Contents from a MapPanel</h1>
+ <p>This example shows the how to create a printable PDF with
+ GeoExt.data.PrintProvider and GeoExt.data.PrintPage, using the
+ <a href="http://trac.mapfish.org/trac/mapfish/wiki/PrintModuleInstallation">MapFish</a>
+ or <a href="http://geoserver.org/display/GEOS/Printing+2.0+HOWTO">GeoServer</a>
+ print module.</p>
+ <p>The js is not minified so it is readable. See <a href="print-page.js">print-page.js</a>.</p>
+ <div id="content"></div>
+ </body>
+</html>
Added: sandbox/ahocevar/playground/trunk/geoext/examples/print-page.js
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/examples/print-page.js (rev 0)
+++ sandbox/ahocevar/playground/trunk/geoext/examples/print-page.js 2010-01-18 15:49:16 UTC (rev 1767)
@@ -0,0 +1,72 @@
+ /**
+ * Copyright (c) 2008-2009 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.
+ */
+
+/** api: example[print-page]
+ * Printing contents from a MapPanel
+ * ---------------------------------
+ * Using PrintPage and PrintProvider to print the visible extent of a MapPanel.
+ */
+
+var mapPanel, printPage;
+
+ Ext.onReady(function() {
+ // The map we want to print
+ mapPanel = new GeoExt.MapPanel({
+ region: "center",
+ 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: 7
+ });
+ // The legend to optionally include on the printout
+ var legendPanel = new GeoExt.LegendPanel({
+ region: "west",
+ width: 150,
+ bodyStyle: "padding:5px",
+ layerStore: mapPanel.layers
+ });
+
+ // The printProvider that connects us to the print service
+ var printProvider = new GeoExt.data.PrintProvider({
+ method: "GET", // "POST" recommended for production use
+ capabilities: printCapabilities // from the info.json script in the html
+ });
+
+ var includeLegend; // controlled by the "Include legend?" checkbox
+
+ // The main panel
+ new Ext.Panel({
+ renderTo: "content",
+ layout: "border",
+ width: 700,
+ height: 420,
+ items: [mapPanel, legendPanel],
+ bbar: ["->", {
+ text: "Print",
+ handler: function() {
+ // Our print page. Tells the PrintProvider about the scale and
+ // center of our page.
+ printPage = new GeoExt.data.PrintPage({
+ printProvider: printProvider,
+ customParams: {
+ mapTitle: "Printing Demo",
+ comment: "This is a simple map printed from GeoExt."
+ }
+ });
+ // convenient way to fit the print page to the visible map area
+ printPage.fit(mapPanel, true);
+ // print the page, optionally including the legend
+ printProvider.print(mapPanel, printPage, includeLegend && {legend: legendPanel});
+ }
+ }, {
+ xtype: "checkbox",
+ boxLabel: "Include legend?",
+ handler: function() {includeLegend = this.checked}
+ }]
+ });
+});
Modified: sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/data/PrintPage.js
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/data/PrintPage.js 2010-01-18 14:37:52 UTC (rev 1766)
+++ sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/data/PrintPage.js 2010-01-18 15:49:16 UTC (rev 1767)
@@ -41,7 +41,7 @@
feature: null,
/** api: property[handle]
- * ``OpenLayers.Feature.Vector`` Features providing the four
+ * Array(``OpenLayers.Feature.Vector``) Features providing the four
* scale/rotation handles for the page. Read-only.
*/
handles: null,
@@ -144,9 +144,9 @@
},
/** api: method[setCenter]
- * :param scale: ``OpenLayers.LonLat`` The new center.
+ * :param center: ``OpenLayers.LonLat`` The new center.
*
- * Moves the page geometry to a new center.
+ * Moves the page extent to a new center.
*/
setCenter: function(center) {
var geom = this.feature.geometry;
@@ -172,15 +172,20 @@
},
/** api: method[fit]
- * :param map: ``OpenLayers.Map`` The map to fit the page to.
- * :param loose: ``Boolean`` If set to true, the print extent will
- * be at least as large as the visible map extent. Default is false.
+ * :param map: :class:`GeoExt.MapPanel`|``OpenLayers.Map`` The map to fit
+ * the page to.
+ * :param loose: ``Boolean`` If true, the closest matching print extent
+ * will be chosen. If set to false, the chosen print extent will
+ * be the closest one that entirely fits into the visible map extent.
+ * Default is false.
*
- * Fits the page layout to the current map extent, using the smallest
- * scale that entirely fits the extent. If the map has not been centered
- * yet, this will do nothing.
+ * Fits the page layout to the current map extent. If the map has not
+ * been centered yet, this will do nothing.
*/
fit: function(map, loose) {
+ if(map instanceof GeoExt.MapPanel) {
+ map = map.map;
+ }
var center = map.getCenter();
if(!center) {
return;
@@ -371,7 +376,6 @@
*/
destroy: function() {
this.printProvider.un("layoutchange", this.onLayoutChange, this);
- GeoExt.data.PrintPage.superclass.destroy.apply(this, arguments);
}
});
\ No newline at end of file
Modified: sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/data/PrintProvider.js
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/data/PrintProvider.js 2010-01-18 14:37:52 UTC (rev 1766)
+++ sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/data/PrintProvider.js 2010-01-18 15:49:16 UTC (rev 1767)
@@ -15,10 +15,18 @@
/** api: example
* Minimal code to print as much of the current map extent as possible as
- * soon as the print service capabilities are loaded:
+ * soon as the print service capabilities are loaded, using the first layout
+ * reported by the print service:
*
* .. code-block:: javascript
*
+ * var mapPanel = new GeoExt.MapPanel({
+ * renderTo: "mappanel",
+ * layers: [new OpenLayers.Layer.WMS("wms", "/geoserver/wms",
+ * {layers: "topp:tasmania_state_boundaries"})],
+ * center: [146.56, -41.56],
+ * zoom: 7
+ * });
* var printProvider = new GeoExt.data.PrintProvider({
* url: "/geoserver/pdf",
* listeners: {
@@ -26,8 +34,8 @@
* var printPage = new GeoExt.data.PrintPage({
* printProvider: printProvider
* });
- * printPage.fit(map);
- * printProvider.print(map, [printPage]);
+ * printPage.fit(mapPanel, true);
+ * printProvider.print(mapPanel, printPage);
* }
* }
* });
@@ -36,7 +44,10 @@
/** api: constructor
* .. class:: PrintProvider
*
- * Provides an interface to a Mapfish or GeoServer print module.
+ * Provides an interface to a Mapfish or GeoServer print module. For printing,
+ * one or more instances of :class:`GeoExt.data.PrintPage` are also required
+ * to tell the PrintProvider about the scale and extent (and optionally
+ * rotation) of the page(s) we want to print.
*/
GeoExt.data.PrintProvider = Ext.extend(Ext.util.Observable, {
@@ -268,8 +279,8 @@
/** api: method[print]
* :param map: ``GeoExt.MapPanel``|``OpenLayers.Map`` The map to print.
- * :param pages: ``Array`` of :class:`GeoExt.data.PrintPage`` pages to
- * print.
+ * :param pages: ``Array``(:class:`GeoExt.data.PrintPage`) or
+ * :class:`GeoExt.data.PrintPage` page(s) to print.
* :param options: ``Object`` of additional options:
* * ``legend``: :class:`GeoExt.LegendPanel` If provided, the legend
* will be added to the print document. For this to look like in
@@ -289,6 +300,7 @@
if(map instanceof GeoExt.MapPanel) {
map = map.map;
}
+ pages = pages instanceof Array ? pages : [pages];
options = options || {};
if(this.fireEvent("beforeprint", this, map, pages, options) === false) {
return;
Added: sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/data/PrintPage.html
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/data/PrintPage.html (rev 0)
+++ sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/data/PrintPage.html 2010-01-18 15:49:16 UTC (rev 1767)
@@ -0,0 +1,148 @@
+<!DOCTYPE html>
+<html debug="true">
+ <head>
+ <script type="text/javascript" src="../../../../../openlayers/lib/OpenLayers.js"></script>
+ <script type="text/javascript" src="../../../../../ext/adapter/ext/ext-base.js"></script>
+ <script type="text/javascript" src="../../../../../ext/ext-all-debug.js"></script>
+ <script type="text/javascript" src="../../../../lib/GeoExt.js"></script>
+
+ <script type="text/javascript">
+ var printCapabilities = {"scales":[{"name":"1:25,000","value":"25000"},{"name":"1:50,000","value":"50000"},{"name":"1:100,000","value":"100000"},{"name":"1:200,000","value":"200000"},{"name":"1:500,000","value":"500000"},{"name":"1:1,000,000","value":"1000000"},{"name":"1:2,000,000","value":"2000000"},{"name":"1:4,000,000","value":"4000000"}],"dpis":[{"name":"75","value":"75"},{"name":"150","value":"150"},{"name":"300","value":"300"}],"layouts":[{"name":"A4 portrait","map":{"width":440,"height":483},"rotation":true},{"name":"Legal","map":{"width":440,"height":483},"rotation":false}],"printURL":"http://demo.opengeo.org/geoserver/pdf/print.pdf","createURL":"http://demo.opengeo.org/geoserver/pdf/create.json"};
+
+ function test_constructor(t) {
+ t.plan(4);
+ var log = {};
+
+ var printProvider = new GeoExt.data.PrintProvider({
+ capabilities: printCapabilities
+ });
+ var printPage = new GeoExt.data.PrintPage({
+ printProvider: printProvider,
+ onLayoutChange: function() {log.layoutchange = true;}
+ });
+
+ t.ok(printPage.feature, "feature initialized properly.");
+ t.eq(printPage.handles.length, 4, "handles initialized properly.");
+ t.eq(printPage.customParams, {}, "customParam initialized properly.");
+
+ printProvider.setLayout(printProvider.layouts.getAt(1));
+ t.eq(log.layoutchange, true, "onLayoutChange called when printProvider's layout changes.");
+
+ printPage.destroy();
+ }
+
+ function test_setCenter(t) {
+ t.plan(2);
+
+ var printPage = new GeoExt.data.PrintPage({
+ printProvider: new GeoExt.data.PrintProvider({
+ capabilities: printCapabilities
+ })
+ });
+
+ var center = new OpenLayers.LonLat(10, 11);
+ printPage.setCenter(center);
+ t.eq(printPage.getCenter().toString(), center.toString(), "center set correctly.");
+ t.geom_eq(printPage.handles[0].geometry, printPage.feature.geometry.components[0].components[0], "handle updated correctly.");
+
+ printPage.destroy();
+ }
+
+ function test_setScale(t) {
+ t.plan(3);
+
+ var printProvider = new GeoExt.data.PrintProvider({
+ capabilities: printCapabilities
+ });
+ var printPage = new GeoExt.data.PrintPage({
+ printProvider: printProvider
+ });
+
+ var scale = printProvider.scales.getAt(1);
+ printPage.setScale(scale, "m");
+ t.eq(printPage.scale.get("value"), scale.get("value"), "scale property of the print page set correctly.");
+
+ var printSize = printProvider.layout.get("size");
+ var expectedArea = printSize.x * printSize.y;
+ t.eq(parseInt(printPage.handles[0].geometry.distanceTo(printPage.handles[1].geometry) * 72 * OpenLayers.INCHES_PER_UNIT["m"] / scale.get("value")), printSize.width, "width of the print feature is correct.");
+ t.eq(parseInt(printPage.handles[1].geometry.distanceTo(printPage.handles[2].geometry) * 72 * OpenLayers.INCHES_PER_UNIT["m"] / scale.get("value")), printSize.height, "height of the print feature is correct.");
+
+ printPage.destroy();
+ }
+
+ function test_setRotation(t) {
+ t.plan(3);
+
+ var printPage = new GeoExt.data.PrintPage({
+ printProvider: new GeoExt.data.PrintProvider({
+ capabilities: printCapabilities
+ })
+ });
+
+ printPage.setRotation(90);
+ t.eq(printPage.rotation, 90, "rotation set correctly.");
+ t.eq(printPage.handles[0].geometry.x.toPrecision(8), printPage.handles[1].geometry.x.toPrecision(8), "x-coords of handle geometries show that the extent is rotated by 90 degrees.");
+ t.eq(printPage.handles[1].geometry.y.toPrecision(8), printPage.handles[2].geometry.y.toPrecision(8), "y-coords of handle geometries show that the extent is rotated by 90 degrees.");
+
+ printPage.destroy();
+ }
+
+ function test_fit(t) {
+ t.plan(3);
+
+ var center = new OpenLayers.LonLat(146.56, -41.56);
+ var mapPanel = new GeoExt.MapPanel({
+ renderTo: "map",
+ width: 400,
+ height: 300,
+ layers: [new OpenLayers.Layer.WMS("wms", "http://demo.opengeo.org/geoserver/wms", {layers: "topp:tasmania_water_bodies"})],
+ center: center,
+ zoom: 7
+ });
+
+ var printPage = new GeoExt.data.PrintPage({
+ printProvider: new GeoExt.data.PrintProvider({
+ capabilities: printCapabilities
+ })
+ });
+
+ printPage.fit(mapPanel);
+ t.eq(printPage.getCenter().toString(), center.toString(), "Print page centered correctly.");
+ t.eq(printPage.scale.get("value"), 2000000, "Print scale set correctly.");
+
+ printPage.fit(mapPanel, true);
+ t.eq(printPage.scale.get("value"), 4000000, "Print scale for 'loose' option set correctly.");
+
+ printPage.destroy();
+ mapPanel.destroy();
+ }
+
+ function test_updateByHandle(t) {
+ t.plan(4);
+ var printPage = new GeoExt.data.PrintPage({
+ printProvider: new GeoExt.data.PrintProvider({
+ capabilities: printCapabilities
+ })
+ });
+
+ // position a handle so it should rotate the extent by 45 degrees and scale it
+ // to twice its size
+ printPage.handles[0].geometry.y = 0;
+ printPage.handles[0].geometry.x = -4.5;
+ expectedOppositeHandleGeom = new OpenLayers.Geometry.Point(4.5, 0);
+
+ printPage.updateByHandle(printPage.handles[0]);
+ t.eq(printPage.rotation, 45, "Correctly rotated 45 degrees by handle.");
+ t.eq(printPage.scale.get("value"), 4000000, "Correctly scaled by handle to 1:4000000");
+ t.geom_eq(printPage.handles[2].geometry, expectedOppositeHandleGeom, "Opposite handle not repositioned if updateHandles argument is not set.");
+
+ printPage.updateByHandle(printPage.handles[0], true);
+ t.ok(!printPage.handles[2].geometry.equals(expectedOppositeHandleGeom), "Opposite handle repositioned when updateHandles argument is set to true.");
+ }
+
+ </script>
+ </head>
+ <body>
+ <div id="map"></div>
+ </body>
+</html>
Added: sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/data/PrintProvider.html
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/data/PrintProvider.html (rev 0)
+++ sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/data/PrintProvider.html 2010-01-18 15:49:16 UTC (rev 1767)
@@ -0,0 +1,166 @@
+<!DOCTYPE html>
+<html debug="true">
+ <head>
+ <script type="text/javascript" src="../../../../../openlayers/lib/OpenLayers.js"></script>
+ <script type="text/javascript" src="../../../../../ext/adapter/ext/ext-base.js"></script>
+ <script type="text/javascript" src="../../../../../ext/ext-all-debug.js"></script>
+ <script type="text/javascript" src="../../../../lib/GeoExt.js"></script>
+
+ <script type="text/javascript">
+ var printCapabilities = {"scales":[{"name":"1:25,000","value":"25000"},{"name":"1:50,000","value":"50000"},{"name":"1:100,000","value":"100000"},{"name":"1:200,000","value":"200000"},{"name":"1:500,000","value":"500000"},{"name":"1:1,000,000","value":"1000000"},{"name":"1:2,000,000","value":"2000000"},{"name":"1:4,000,000","value":"4000000"}],"dpis":[{"name":"75","value":"75"},{"name":"150","value":"150"},{"name":"300","value":"300"}],"layouts":[{"name":"A4 portrait","map":{"width":440,"height":483},"rotation":true},{"name":"Legal","map":{"width":440,"height":483},"rotation":false}],"printURL":"http://demo.opengeo.org/geoserver/pdf/print.pdf","createURL":"http://demo.opengeo.org/geoserver/pdf/create.json"};
+
+ function test_constructor(t) {
+ t.plan(7);
+ var log = {};
+
+ var origRequest = Ext.Ajax.request;
+ Ext.Ajax.request = function(req) {
+ req.success.call(req.scope, {responseText: Ext.encode(printCapabilities)});
+ }
+ var printProvider = new GeoExt.data.PrintProvider({
+ url: "PrintProvider",
+ listeners: {
+ "loadcapabilities": function() {
+ log.loadcapabilities = arguments;
+ }
+ }
+ });
+ Ext.Ajax.request = origRequest;
+
+ t.eq(printProvider.customParams, {}, "customParams initialized properly.");
+ t.ok(log.loadcapabilities[0] == printProvider, "printProvider passed as 1st argument of the loadcapabilities listener.");
+ t.ok(log.loadcapabilities[1] == printProvider.capabilities, "capabilities passed as 2nd argument of the loadcapabilities listener.");
+ t.eq(printProvider.capabilities.createURL, "http://demo.opengeo.org/geoserver/pdf/create.json", "capabilities available and createURL correct after loadcapabilities event");
+ t.ok(printProvider.layout == printProvider.layouts.getAt(0), "layout set to first available layout record.");
+ t.ok(printProvider.dpi == printProvider.dpis.getAt(0), "dpi set to first available dpi record.");
+ t.eq(printProvider.scales.getCount(), 8, "8 scales read in properly.");
+ }
+
+ function test_setLayout(t) {
+ t.plan(3);
+ var log = {};
+ var printProvider = new GeoExt.data.PrintProvider({
+ capabilities: printCapabilities,
+ listeners: {
+ "layoutchange": function() {
+ log.layoutchange = arguments;
+ }
+ }
+ });
+ var layout = printProvider.layouts.getAt(1);
+ printProvider.setLayout(layout);
+ t.ok(printProvider.layout == layout, "layout set correctly.");
+ t.ok(log.layoutchange[0] == printProvider, "printProvider passed as 1st argment of the layoutchange listener.");
+ t.ok(log.layoutchange[1] == layout, "layout passed as 2nd argment of the layoutchange listener.");
+ }
+
+ function test_setDpi(t) {
+ t.plan(3);
+ var log = {};
+ var printProvider = new GeoExt.data.PrintProvider({
+ capabilities: printCapabilities,
+ listeners: {
+ "dpichange": function() {
+ log.dpichange = arguments;
+ }
+ }
+ });
+ var dpi = printProvider.dpis.getAt(1);
+ printProvider.setDpi(dpi);
+ t.ok(printProvider.dpi == dpi, "dpi set correctly.");
+ t.ok(log.dpichange[0] == printProvider, "printProvider passed as 1st argment of the dpichange listener.");
+ t.ok(log.dpichange[1] == dpi, "dpi passed as 2nd argment of the dpichange listener.");
+ }
+
+ function test_print(t) {
+ t.plan(1);
+ var log = {};
+ var printProvider = new GeoExt.data.PrintProvider({
+ capabilities: printCapabilities,
+ customParams: {customParam: "foo"},
+ listeners: {
+ "dpichange": function() {
+ log.dpichange = arguments;
+ }
+ }
+ });
+ var printPage = new GeoExt.data.PrintPage({
+ printProvider: printProvider,
+ customParams: {mapTitle: "foo", comment: "bar"}
+ });
+ var map = new OpenLayers.Map("map");
+
+ // layers to test all supported layer encoders
+ var layers = [
+ new OpenLayers.Layer.WMS("wms", "http://demo.opengeo.org/geoserver/wms", {
+ layers: ["topp:tasmania_state_boundaries","topp:tasmania_water_bodies"], format: "image/gif", vendorFoo: "bar"
+ }),
+ new OpenLayers.Layer.OSM("osm", {isBaseLayer: false}),
+ new OpenLayers.Layer.TileCache("tilecache",
+ ["http://c0.labs.metacarta.com/wms-c/cache/",
+ "http://c1.labs.metacarta.com/wms-c/cache/",
+ "http://c2.labs.metacarta.com/wms-c/cache/",
+ "http://c3.labs.metacarta.com/wms-c/cache/",
+ "http://c4.labs.metacarta.com/wms-c/cache/"],
+ "basic",
+ {
+ serverResolutions: [0.703125, 0.3515625, 0.17578125, 0.087890625,
+ 0.0439453125, 0.02197265625, 0.010986328125,
+ 0.0054931640625, 0.00274658203125, 0.001373291015625,
+ 0.0006866455078125, 0.00034332275390625, 0.000171661376953125,
+ 0.0000858306884765625, 0.00004291534423828125, 0.000021457672119140625],
+ isBaseLayer: false
+ }
+ ),
+ new OpenLayers.Layer.Image(
+ "image",
+ "http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif",
+ new OpenLayers.Bounds(-180, -88.759, 180, 88.759),
+ new OpenLayers.Size(580, 288),
+ {numZoomLevels: 3, isBaseLayer: false}
+ ),
+ new OpenLayers.Layer.Vector("vector")
+ ];
+ map.addLayers(layers);
+
+ // give the vector layer a feature
+ map.getLayersBy("name", "vector")[0].addFeatures([new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(1,2))]);
+
+ map.setCenter(new OpenLayers.LonLat(1, 2), 3);
+ printPage.fit(map);
+
+ // create a layer store for the legend
+ var layerStore = new GeoExt.data.LayerStore({
+ layers: [layers[0], layers[1]]
+ });
+ layerStore.getAt(1).set("legendURL", "../../../../../geoext/resources/images/default/anchor.png");
+
+ // a legend panel to test all legend encoders
+ var legend = new GeoExt.LegendPanel({
+ renderTo: "legend",
+ layerStore: layerStore
+ });
+
+ var origRequest = Ext.Ajax.request;
+ Ext.Ajax.request = function(req) {
+ log.request = req;
+ req.success.call(req.scope, {
+ responseText: '{"getURL":"foo"}'
+ });
+ }
+ printProvider.print(map, [printPage], {legend: legend});
+ Ext.Ajax.request = origRequest;
+ var expect = {"units":"degrees","srs":"EPSG:4326","layout":"A4 portrait","dpi":75,"layers":[{"baseURL":"http://demo.opengeo.org/geoserver/wms","opacity":1,"singleTile":false,"type":"WMS","layers":["topp:tasmania_state_boundaries","topp:tasmania_water_bodies"],"format":"image/gif","styles":[""],"customParams":{"VENDORFOO":"bar"}},{"baseURL":"http://c0.labs.metacarta.com/wms-c/cache/","opacity":1,"singleTile":false,"type":"TileCache","layer":"basic","maxExtent":[-180,-90,180,90],"tileSize":[256,256],"extension":"png","resolutions":[0.703125,0.3515625,0.17578125,0.087890625,0.0439453125,0.02197265625,0.010986328125,0.0054931640625,0.00274658203125,0.001373291015625,0.0006866455078125,0.00034332275390625,0.000171661376953125,0.0000858306884765625,0.00004291534423828125,0.000021457672119140625]},{"type":"Image","baseURL":"http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif","opacity":1,"extent":[-180,-88.759,180,88.759],"pixelSize":[580,288],"name":"image"},{"type":"Vector","styles":{"1":{"fillColor":"#ee9900","fillOpacity":0.4,"hoverFillColor":"white","hoverFillOpacity":0.8,"strokeColor":"#ee9900","strokeOpacity":1,"strokeWidth":1,"strokeLinecap":"round","strokeDashstyle":"solid","hoverStrokeColor":"red","hoverStrokeOpacity":1,"hoverStrokeWidth":0.2,"pointRadius":6,"hoverPointRadius":1,"hoverPointUnit":"%","pointerEvents":"visiblePainted","cursor":"inherit"}},"styleProperty":"_gx_style","geoJson":{"type":"FeatureCollection","features":[{"type":"Feature","id":"OpenLayers.Feature.Vector_72","properties":{"_gx_style":1},"geometry":{"type":"Point","coordinates":[1,2]}}]},"name":"vector","opacity":1}],"pages":[{"mapTitle":"foo","comment":"bar","center":[1,2],"scale":4000000,"rotation":0}],"customParam":"foo","legends":[{"name":"osm","classes":[{"name":"","icon":"http://localhost/geoext-playground/trunk/geoext/resources/images/default/anchor.png"}]},{"name":"wms","classes":[{"name":"","icons":["http://demo.opengeo.org/geoserver/wms?FORMAT=image%2Fgif&VENDORFOO=bar&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&LAYER=topp%3Atasmania_state_boundaries","http://demo.opengeo.org/geoserver/wms?FORMAT=image%2Fgif&VENDORFOO=bar&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetLegendGraphic&EXCEPTIONS=application%2Fvnd.ogc.se_xml&LAYER=topp%3Atasmania_water_bodies"]}]}]};
+ t.eq(log.request.jsonData, expect, "Request with encoded layers and legend is correct.");
+
+ layerStore.destroy();
+ printPage.destroy();
+ map.destroy();
+ }
+ </script>
+ </head>
+ <body>
+ <div id="map" style="width:400px; height:300px"></div>
+ <div id="legend" style="width:200px; height:300px"></div>
+ </body>
+</html>
Modified: sandbox/ahocevar/playground/trunk/geoext/tests/list-tests.html
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/tests/list-tests.html 2010-01-18 14:37:52 UTC (rev 1766)
+++ sandbox/ahocevar/playground/trunk/geoext/tests/list-tests.html 2010-01-18 15:49:16 UTC (rev 1767)
@@ -7,6 +7,8 @@
<li>lib/GeoExt/data/LayerRecord.html</li>
<li>lib/GeoExt/data/LayerReader.html</li>
<li>lib/GeoExt/data/LayerStore.html</li>
+ <li>lib/GeoExt/data/PrintPage.html</li>
+ <li>lib/GeoExt/data/PrintProvider.html</li>
<li>lib/GeoExt/data/ScaleStore.html</li>
<li>lib/GeoExt/data/ProtocolProxy.html</li>
<li>lib/GeoExt/data/WFSCapabilitiesReader.html</li>
More information about the Commits
mailing list