[Commits] r2268 - in core/trunk/geoext: examples lib/GeoExt/data lib/GeoExt/plugins lib/GeoExt/widgets tests/lib/GeoExt/widgets
commits at geoext.org
commits at geoext.org
Thu Aug 12 10:58:07 CEST 2010
Author: ahocevar
Date: 2010-08-12 10:58:07 +0200 (Thu, 12 Aug 2010)
New Revision: 2268
Modified:
core/trunk/geoext/examples/print-preview-osm.js
core/trunk/geoext/examples/print-preview.js
core/trunk/geoext/lib/GeoExt/data/PrintPage.js
core/trunk/geoext/lib/GeoExt/plugins/PrintPageField.js
core/trunk/geoext/lib/GeoExt/widgets/PrintMapPanel.js
core/trunk/geoext/tests/lib/GeoExt/widgets/PrintMapPanel.html
Log:
PrintMapPanel enhancements:
* No longer preview based on the resolution, but on the print extent instead. This means that we can now print on paper sizes that are much larger than what we can preview in the browser.
* New limitScales option and previewScales store - with this we get a subset of the scales which can be displayed properly (i.e. without the printed map being much smaller or larger than what we see in the preview).
* New getPrintExtent convenience method for the PrintPage.
* PrintPageField now works with stores other than the provider's ScaleStore, if the field's name is "scale".
Note that the committed version differs from the previous patch to allow rendering a PrintMapPanel to a dom element:
* In adjustSize, check for ownerCt before using it.
* Override the afterrender method instead of registering for an (after)render event, because the render event is fired too early. This was necessary to achieve proper sizing also in Ext < 3.0, and has the advantage that we can now also use the limitScales option in older Ext versions.
Thanks tschaub for the great collaboration on this. r=tschaub (closes #309)
Modified: core/trunk/geoext/examples/print-preview-osm.js
===================================================================
--- core/trunk/geoext/examples/print-preview-osm.js 2010-08-11 00:52:52 UTC (rev 2267)
+++ core/trunk/geoext/examples/print-preview-osm.js 2010-08-12 08:58:07 UTC (rev 2268)
@@ -54,8 +54,12 @@
// the print extent before creating the pdf.
printDialog = new Ext.Window({
title: "Print Preview",
+ width: 350,
+ autoHeight: true,
items: [{
xtype: "gx_printmappanel",
+ // use only a PanPanel control
+ map: {controls: [new OpenLayers.Control.PanPanel()]},
sourceMap: mapPanel,
printProvider: printProvider
}],
Modified: core/trunk/geoext/examples/print-preview.js
===================================================================
--- core/trunk/geoext/examples/print-preview.js 2010-08-11 00:52:52 UTC (rev 2267)
+++ core/trunk/geoext/examples/print-preview.js 2010-08-12 08:58:07 UTC (rev 2268)
@@ -30,11 +30,21 @@
renderTo: "content",
width: 500,
height: 350,
+ map: {
+ maxExtent: new OpenLayers.Bounds(
+ 143.835, -43.648,
+ 148.479, -39.574
+ ),
+ maxResolution: 0.018140625,
+ projection: "EPSG:4326",
+ units: 'degrees'
+ },
layers: [new OpenLayers.Layer.WMS("Tasmania State Boundaries",
"http://demo.opengeo.org/geoserver/wms",
- {layers: "topp:tasmania_state_boundaries"}, {singleTile: true})],
+ {layers: "topp:tasmania_state_boundaries"},
+ {singleTile: true, numZoomLevels: 8})],
center: [146.56, -41.56],
- zoom: 6,
+ zoom: 0,
bbar: [{
text: "Print...",
handler: function(){
@@ -42,6 +52,9 @@
// the print extent before creating the pdf.
printDialog = new Ext.Window({
title: "Print Preview",
+ layout: "fit",
+ width: 350,
+ autoHeight: true,
items: [{
xtype: "gx_printmappanel",
sourceMap: mapPanel,
Modified: core/trunk/geoext/lib/GeoExt/data/PrintPage.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/data/PrintPage.js 2010-08-11 00:52:52 UTC (rev 2267)
+++ core/trunk/geoext/lib/GeoExt/data/PrintPage.js 2010-08-12 08:58:07 UTC (rev 2268)
@@ -34,7 +34,9 @@
printProvider: null,
/** api: property[feature]
- * ``OpenLayers.Feature.Vector`` Feature representing the page extent.
+ * ``OpenLayers.Feature.Vector`` Feature representing the page extent. To
+ * get the extent of the print page for a specific map, use
+ * ``getPrintExtent``.
* Read-only.
*/
feature: null,
@@ -99,6 +101,18 @@
scope: this
});
},
+
+ /** api: method[getPrintExtent]
+ * :param map: ``OpenLayers.Map`` or :class:`GeoExt.MapPanel` the map to
+ * get the print extent for.
+ * :returns: ``OpenLayers.Bounds``
+ *
+ * Gets this page's print extent for the provided map.
+ */
+ getPrintExtent: function(map) {
+ map = map instanceof GeoExt.MapPanel ? mapPanel.map : map;
+ return this.calculatePageBounds(this.scale, map.getUnits());
+ },
/** api: method[setScale]
* :param scale: ``Ext.data.Record`` The new scale record.
@@ -178,16 +192,34 @@
var center = extent.getCenterLonLat();
this.setCenter(center);
var units = map.getUnits();
- var scale, looseScale, contains;
+ var scale = this.printProvider.scales.getAt(0);
+ var closest = {
+ diff: Number.POSITIVE_INFINITY,
+ scale: scale
+ };
+ var mapWidth = extent.getWidth();
+ var mapHeight = extent.getHeight();
this.printProvider.scales.each(function(rec) {
- looseScale = scale || rec;
- scale = rec;
- contains = extent.containsBounds(
- this.calculatePageBounds(scale, units));
- return !contains
+ var bounds = this.calculatePageBounds(rec, units);
+ var contains = bounds.containsBounds(extent);
+ if (contains) {
+ scale = rec;
+ }
+ if (loose) {
+ var diff = Math.min(
+ Math.abs(bounds.getWidth() - mapWidth),
+ Math.abs(bounds.getHeight() - mapHeight)
+ );
+ if (diff < closest.diff) {
+ closest.diff = diff;
+ closest.scale = rec;
+ }
+ } else {
+ // no need to continue if not contained and not loose
+ return contains;
+ }
}, this);
- scale = loose && contains ? looseScale : scale;
- this.setScale(scale, units);
+ this.setScale(loose ? closest.scale : scale, units);
delete this._updating;
this.updateFeature(this.feature.geometry, {
center: center,
Modified: core/trunk/geoext/lib/GeoExt/plugins/PrintPageField.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/plugins/PrintPageField.js 2010-08-11 00:52:52 UTC (rev 2267)
+++ core/trunk/geoext/lib/GeoExt/plugins/PrintPageField.js 2010-08-12 08:58:07 UTC (rev 2268)
@@ -33,6 +33,7 @@
* xtype: "combo",
* displayField: "name",
* store: printPage.scales, // printPage.scale
+ * name: "scale",
* fieldLabel: "Scale",
* typeAhead: true,
* mode: "local",
@@ -64,7 +65,8 @@
* .. class:: PrintPageField
*
* A plugin for ``Ext.form.Field`` components which provides synchronization
- * with a :class:`GeoExt.data.PrintPage`.
+ * with a :class:`GeoExt.data.PrintPage`. The field name has to match the
+ * respective property of the printPage (e.g. ``scale``, ``rotation``).
*/
GeoExt.plugins.PrintPageField = Ext.extend(Ext.util.Observable, {
@@ -124,7 +126,7 @@
var printProvider = this.printPage.printProvider;
var value = field.getValue();
this._updating = true;
- if(field.store === printProvider.scales) {
+ if(field.store === printProvider.scales || field.name === "scale") {
this.printPage.setScale(record);
} else if(field.name == "rotation") {
!isNaN(value) && this.printPage.setRotation(value);
@@ -165,7 +167,7 @@
setValue: function(printPage) {
var t = this.target;
t.suspendEvents();
- if(t.store === printPage.printProvider.scales) {
+ if(t.store === printPage.printProvider.scales || t.name === "scale") {
if(printPage.scale) {
t.setValue(printPage.scale.get(t.displayField));
}
Modified: core/trunk/geoext/lib/GeoExt/widgets/PrintMapPanel.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/PrintMapPanel.js 2010-08-11 00:52:52 UTC (rev 2267)
+++ core/trunk/geoext/lib/GeoExt/widgets/PrintMapPanel.js 2010-08-12 08:58:07 UTC (rev 2268)
@@ -39,6 +39,8 @@
* text: "Print...",
* handler: function() {
* var printDialog = new Ext.Window({
+ * autoHeight: true,
+ * width: 350,
* items: [new GeoExt.PrintMapPanel({
* sourceMap: mapPanel,
* printProvider: {
@@ -61,10 +63,14 @@
/** api: constructor
* .. class:: PrintMapPanel
*
- * A map panel that controls scale and center of a print page, based the
- * current view of a source map. This panel will contain the same layers as
- * the source map, and it will be sized to exactly match the print extent at
- * the smallest available scale.
+ * A map panel that controls scale and center of a print page. Based on the
+ * current view (i.e. layers and extent) of a source map, this panel will be
+ * sized according to the aspect ratio of the print page. As the user zooms
+ * and pans in the :class:`GeoExt.PrintMapPanel`, the print page will update
+ * its scale and center accordingly. If the scale on the print page changes
+ * (e.g. by setting it using a combo box with a
+ * :class:`GeoExt.plugins.PrintPageField`), the extent of the
+ * :class:`GeoExt.PrintMapPanel` will be updated to match the page bounds.
*
* .. note:: The ``zoom``, ``center`` and ``extent`` config options will have
* no affect, as they will be determined by the ``sourceMap``.
@@ -76,10 +82,6 @@
* that this PrintMapPanel creates. Useful e.g. to configure a map with a
* custom set of controls, or to add a ``preaddlayer`` listener for
* filtering out layer types that cannot be printed.
- *
- * .. note:: the ``zoomToMaxExtent``, ``zoomIn`` and ``zoomOut`` methods
- * of the map will be overridden by this PrintMapPanel, and visible
- * layers will be copied from ``sourceMap``.
*/
/** api: config[sourceMap]
@@ -96,19 +98,19 @@
* :class:`GeoExt.data.PrintProvider` or ``Object`` PrintProvider to use
* for printing. If an ``Object`` is provided, a new PrintProvider will
* be created and configured with the object.
+ *
+ * .. note:: The PrintMapPanel requires the printProvider's capabilities
+ * to be available upon initialization. This means that a PrintMapPanel
+ * configured with an ``Object`` as ``printProvider`` will only work
+ * when ``capabilities`` is provided in the printProvider's
+ * configuration object. If ``printProvider`` is provided as an instance
+ * of :class:`GeoExt.data.PrintProvider`, the capabilities must be
+ * loaded before PrintMapPanel initialization.
*/
/** api: property[printProvider]
* :class:`GeoExt.data.PrintProvider` PrintProvider for this
* PrintMapPanel.
- *
- * .. note:: The PrintMapPanel requires the printProvider's capabilities
- * to be available upon initialization. This means that a PrintMapPanel
- * configured with an object as ``printProvider`` will only work when
- * ``capabilities`` is provided in the printProvider's configuration
- * object. If ``printProvider`` is provided as an instance of
- * :class:`GeoExt.data.PrintProvider`, the capabilities must be loaded
- * before PrintMapPanel initialization.
*/
printProvider: null,
@@ -118,30 +120,45 @@
*/
printPage: null,
+ /** api: config[limitScales]
+ * ``Boolean`` If set to true, the printPage cannot be set to scales that
+ * would generate a preview in this :class:`GeoExt.PrintMapPanel` with a
+ * completely different extent than the one that would appear on the
+ * printed map. Default is false.
+ */
+
+ /** api: property[previewScales]
+ * ``Ext.data.Store`` A data store with a subset of the printProvider's
+ * scales. By default, this contains all the scales of the printProvider.
+ * If ``limitScales`` is set to true, it will only contain print scales
+ * that can properly be previewed with this :class:`GeoExt.PrintMapPanel`.
+ */
+ previewScales: null,
+
/** api: config[center]
* ``OpenLayers.LonLat`` or ``Array(Number)`` A location for the map
- * center. Do not set, as this will be overridden with the
- * ``sourceMap`` center.
+ * center. Do not set, as this will be overridden with the ``sourceMap``
+ * center.
*/
center: null,
/** api: config[zoom]
- * ``Number`` An initial zoom level for the map. Do not set, as this
- * will be overridden with a zoom level matching the ``sourceMap``.
+ * ``Number`` An initial zoom level for the map. Do not set, because the
+ * initial extent will be determined by the ``sourceMap``.
*/
zoom: null,
/** api: config[extent]
* ``OpenLayers.Bounds or Array(Number)`` An initial extent for the map.
- * Do not set, as this will be overridden with an extent matching the
- * ``sourceMap`` resolution.
+ * Do not set, because the initial extent will be determined by the
+ * ``sourceMap``.
*/
extent: null,
- /** private: property[printResolutions]
- * ``Array`` The resolutions available for printing
+ /** private: property[currentZoom]
+ * ``Number``
*/
- printResolutions: null,
+ currentZoom: null,
/**
* private: method[initComponent]
@@ -151,6 +168,17 @@
if(this.sourceMap instanceof GeoExt.MapPanel) {
this.sourceMap = this.sourceMap.map;
}
+
+ if (!this.map) {
+ this.map = {};
+ }
+ Ext.applyIf(this.map, {
+ projection: this.sourceMap.getProjection(),
+ maxExtent: this.sourceMap.getMaxExtent(),
+ maxResolution: this.sourceMap.getMaxResolution(),
+ units: this.sourceMap.getUnits()
+ });
+
if(!(this.printProvider instanceof GeoExt.data.PrintProvider)) {
this.printProvider = new GeoExt.data.PrintProvider(
this.printProvider);
@@ -159,35 +187,8 @@
printProvider: this.printProvider
});
- this.updatePrintResolutions();
-
- var me = this;
- var center = this.sourceMap.getCenter();
- this.map = Ext.apply(this.map || {}, {
- // override zoomToMaxExtent so it brings us back to the original
- // extent
- zoomToMaxExtent: function() {
- this.setCenter(center, me.getZoomForResolution(
- me.printResolutions[0]));
- },
- // override zoomIn and zoomOut to make sure that we only zoom to
- // resolutions supported by the print module
- zoomIn: function() {
- this.zoomTo(me.getZoomForResolution(me.printResolutions[
- Math.min(
- me.printResolutions.indexOf(this.getResolution()) + 1,
- me.printResolutions.length - 1
- )
- ]));
- },
- zoomOut: function() {
- this.zoomTo(me.getZoomForResolution(me.printResolutions[
- Math.max(
- me.printResolutions.indexOf(this.getResolution()) - 1, 0
- )
- ]));
- }
- });
+ this.previewScales = new Ext.data.Store();
+ this.previewScales.add(this.printProvider.scales.getRange());
this.layers = [];
var layer;
@@ -196,106 +197,149 @@
layer.getVisibility() === true && this.layers.push(clone);
}, this);
- // set an initial size with the same aspect ratio as the print page.
- // This is crucial for the first fitSize call to determine the correct
- // resolution, otherwise we may be one zoom level off.
- var size = this.printProvider.layout.get("size");
- this.width = size.width;
- this.height = size.height;
+ this.extent = this.sourceMap.getExtent();
- var extent = this.sourceMap.getExtent();
- var idealResolution = Math.max(
- extent.getWidth() / this.width,
- extent.getHeight() / this.height
- );
- this.zoom = this.getZoomForResolution(idealResolution);
+ GeoExt.PrintMapPanel.superclass.initComponent.call(this);
- this.center = this.sourceMap.getCenter();
- this.extent = null;
- GeoExt.PrintMapPanel.superclass.initComponent.call(this);
-
- this.fitSize();
- this.printProvider.on("layoutchange", this.fitSize, this);
- this.printProvider.on("layoutchange", this.updatePrintResolutions, this);
+ this.printProvider.on("layoutchange", this.updateExtent, this);
this.printPage.on("change", this.fitZoom, this);
this.map.events.register("moveend", this, this.updatePage);
},
- /** private: method[updatePrintResolutions]
- * Creates an array of resolutions supported by the print module.
+ /** private: method[afterRender]
+ * Private method called after the panel has been rendered.
*/
- updatePrintResolutions: function() {
- this.printResolutions = [];
- var units = this.sourceMap.getUnits();
- this.printProvider.scales.each(function(s){
- var res = OpenLayers.Util.getResolutionFromScale(
- s.get("value"), units
- );
- var zoom = this.sourceMap.getZoomForResolution(res)
- this.printResolutions.push(
- this.sourceMap.getResolutionForZoom(zoom)
- );
- }, this);
+ afterRender: function() {
+ GeoExt.PrintMapPanel.superclass.afterRender.apply(this, arguments);
+ this.updateExtent();
},
- /** private: method[getZoomForResolution]
- * :param resolution: ``Number``
- *
- * Gets a zoom level that gives us a map extent fitting the print page at
- * the print resolution closest to the provided resolution.
+ /** private: method[adjustSize]
+ * :param width: ``Number``
+ * :param height: ``Number``
+ * Private override - sizing this component always takes the aspect ratio
+ * of the print page into account.
*/
- getZoomForResolution: function(resolution) {
- for (var i=0, len=this.printResolutions.length; i<len; i++) {
- if (this.printResolutions[i] < resolution) {
- break;
+ adjustSize: function(width, height) {
+ var printSize = this.printProvider.layout.get("size");
+ var ratio = printSize.width / printSize.height;
+ // respect width & height when sizing according to the print page's
+ // aspect ratio - do not exceed either, but don't take values for
+ // granted if container is configured with autoWidth or autoHeight.
+ var ownerCt = this.ownerCt;
+ var targetWidth = (ownerCt && ownerCt.autoWidth) ? 0 : width;
+ var targetHeight = (ownerCt && ownerCt.autoHeight) ? 0 : height;
+ if (targetWidth) {
+ height = targetWidth / ratio;
+ if (targetHeight && height > targetHeight) {
+ height = targetHeight;
+ width = height * ratio;
+ } else {
+ width = targetWidth;
}
+ } else if (targetHeight) {
+ width = targetHeight * ratio;
+ height = targetHeight;
}
- return this.sourceMap.getZoomForResolution(
- this.printResolutions[Math.max(0, i-1)]
- );
+
+ return {width: width, height: height};
},
- /** private: method[fitSize]
- * Fits this PrintMapPanel's width and height to the print extent. This
- * calculation is based on the print extent for the first available scale,
- * which means that the print view extent is only guaranteed to be
- * accurate at that scale. The aspect ratio, however, can be taken for
- * granted at any scale, because it depends on the layout.
+ /** private: method[updateExtent]
+ * Makes sure that this :class:`PrintMapPanel` gets the aspect ratio that
+ * matches the print page, and update the previewable scales.
*/
- fitSize: function() {
- var extent = this.printPage.calculatePageBounds(
- this.printProvider.scales.getAt(0),
- this.sourceMap.getUnits()
- );
- var resolution = this.printResolutions[0];
- this.setSize(
- extent.getWidth() / resolution,
- extent.getHeight() / resolution
- );
+ updateExtent: function() {
+ this.syncSize();
+ if (this.initialConfig.limitScales === true) {
+ this.calculatePreviewScales();
+ }
},
/** private: method[fitZoom]
* Fits this PrintMapPanel's zoom to the print scale.
*/
fitZoom: function() {
- var zoom = this.getZoomForResolution(
- OpenLayers.Util.getResolutionFromScale(
- this.printPage.scale.get("value"),
- this.map.baseLayer.units));
- this._updating = true;
- this.map.getZoom() != zoom && this.map.zoomTo(zoom);
- delete this._updating;
+ if (!this._updating && this.printPage.scale) {
+ this._updating = true;
+ var printBounds = this.printPage.getPrintExtent(this.map);
+ this.currentZoom = this.map.getZoomForExtent(printBounds);
+ this.map.zoomToExtent(printBounds);
+ delete this._updating;
+ }
},
-
+
/** private: method[updatePage]
* updates the print page to match this PrintMapPanel's center and scale.
*/
updatePage: function() {
- if(!this._updating) {
- this.printPage.fit(this.map, true);
+ if (!this._updating) {
+ var zoom = this.map.getZoom();
+ this._updating = true;
+ if (zoom === this.currentZoom) {
+ this.printPage.setCenter(this.map.getCenter());
+ } else {
+ this.printPage.fit(this.map);
+ }
+ delete this._updating;
+ this.currentZoom = zoom;
}
},
+ /** private: method[calculatePreviewScales]
+ */
+ calculatePreviewScales: function() {
+ this.previewScales.removeAll();
+
+ this.printPage.suspendEvents();
+ var scale = this.printPage.scale;
+
+ // group print scales by the zoom level they would be previewed at
+ var viewSize = this.map.getSize();
+ var scalesByZoom = {};
+ var zooms = [];
+ this.printProvider.scales.each(function(rec) {
+ this.printPage.setScale(rec);
+ var extent = this.printPage.getPrintExtent(this.map);
+ var zoom = this.map.getZoomForExtent(extent);
+
+ var idealResolution = Math.max(
+ extent.getWidth() / viewSize.w,
+ extent.getHeight() / viewSize.h
+ );
+ var resolution = this.map.getResolutionForZoom(zoom);
+ // the closer to the ideal resolution, the better the fit
+ var diff = Math.abs(idealResolution - resolution);
+ if (!(zoom in scalesByZoom) || scalesByZoom[zoom].diff > diff) {
+ scalesByZoom[zoom] = {
+ rec: rec,
+ diff: diff
+ };
+ zooms.indexOf(zoom) == -1 && zooms.push(zoom);
+ }
+ }, this);
+
+ // add only the preview scales that closely fit print extents
+ for (var i=0, ii=zooms.length; i<ii; ++i) {
+ this.previewScales.add(scalesByZoom[zooms[i]].rec);
+ }
+
+ scale && this.printPage.setScale(scale);
+ this.printPage.resumeEvents();
+
+ if (scale && this.previewScales.getCount() > 0) {
+ var maxScale = this.previewScales.getAt(0);
+ var minScale = this.previewScales.getAt(this.previewScales.getCount()-1);
+ if (scale.get("value") < minScale.get("value")) {
+ this.printPage.setScale(minScale);
+ } else if (scale.get("value") > maxScale.get("value")) {
+ this.printPage.setScale(maxScale);
+ }
+ }
+
+ this.fitZoom();
+ },
+
/** api: method[print]
* :param options: ``Object`` options for
* the :class:`GeoExt.data.PrintProvider` :: ``print`` method.
@@ -312,8 +356,7 @@
beforeDestroy: function() {
this.map.events.unregister("moveend", this, this.updatePage);
this.printPage.un("change", this.fitZoom, this);
- this.printProvider.un("layoutchange", this.fitSize, this);
- this.printProvider.un("layoutchange", this.updatePrintResolutions, this);
+ this.printProvider.un("layoutchange", this.updateExtent, this);
GeoExt.PrintMapPanel.superclass.beforeDestroy.apply(this, arguments);
}
});
Modified: core/trunk/geoext/tests/lib/GeoExt/widgets/PrintMapPanel.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/PrintMapPanel.html 2010-08-11 00:52:52 UTC (rev 2267)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/PrintMapPanel.html 2010-08-12 08:58:07 UTC (rev 2268)
@@ -10,7 +10,7 @@
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_initComponent(t) {
- t.plan(9);
+ t.plan(6);
var mapPanel = new GeoExt.MapPanel({
renderTo: "mappanel",
@@ -26,6 +26,7 @@
var log = {};
var printMapPanel = new GeoExt.PrintMapPanel({
renderTo: "printmappanel",
+ height: 256,
map: {
controls: [new OpenLayers.Control.PanPanel()],
eventListeners: {
@@ -40,20 +41,18 @@
sourceMap: mapPanel
});
- var size = printMapPanel.printProvider.layout.get("size");
+ var printSize = printMapPanel.printProvider.layout.get("size");
+ var size = printMapPanel.getSize();
var center = mapPanel.map.getCenter();
var pageCenter = printMapPanel.printPage.center;
t.eq(printMapPanel.map.controls.length, printMapPanel.map.controls[0].controls.length+1, "Preview map has only the control we added,");
t.ok(printMapPanel.map.controls[0] instanceof OpenLayers.Control.PanPanel, "which is a PanPanel.");
- t.eq(printMapPanel.map.getResolution(), mapPanel.map.getResolution(), "Preview map has the same resolution as the source map.");
- t.ok(printMapPanel.map.getCenter().equals(center), "Preview map has the same center as the source map.");
t.eq(printMapPanel.map.layers[0].name, mapPanel.map.layers[0].name, "Preview map has the same visible layer as the source map.");
t.eq(log.preaddlayer.name, printMapPanel.map.layers[0].name, "preaddlayer listener noticed addition of the layer.");
- t.eq((printMapPanel.width/printMapPanel.height).toPrecision(8), (size.width/size.height).toPrecision(8), "Aspect ratio of the preview map is the same as of the print layout.");
+ t.eq((size.width/size.height).toPrecision(2), (printSize.width/printSize.height).toPrecision(2), "Aspect ratio of the preview map is the same as of the print layout.");
t.ok(Math.abs(center.lon - pageCenter.lon) < 0.0000001 && Math.abs(center.lat - pageCenter.lat) < 0.0000001, "Print page has the same center as the source map.");
- t.eq(printMapPanel.printPage.scale.get("value"), 2000000, "Print page has the correct scale to fit the source map.");
-
+
printMapPanel.destroy();
mapPanel.destroy();
}
More information about the Commits
mailing list