[Commits] r2304 - in core/trunk/geoext: lib/GeoExt/data lib/GeoExt/plugins lib/GeoExt/widgets tests/lib/GeoExt/data tests/lib/GeoExt/widgets
commits at geoext.org
commits at geoext.org
Fri Sep 3 08:33:22 CEST 2010
Author: ahocevar
Date: 2010-09-03 08:33:22 +0200 (Fri, 03 Sep 2010)
New Revision: 2304
Modified:
core/trunk/geoext/lib/GeoExt/data/PrintPage.js
core/trunk/geoext/lib/GeoExt/data/PrintProvider.js
core/trunk/geoext/lib/GeoExt/plugins/PrintExtent.js
core/trunk/geoext/lib/GeoExt/widgets/MapPanel.js
core/trunk/geoext/lib/GeoExt/widgets/PrintMapPanel.js
core/trunk/geoext/tests/lib/GeoExt/data/PrintPage.html
core/trunk/geoext/tests/lib/GeoExt/widgets/PrintMapPanel.html
Log:
better documentation on how to configure the legend in the print module's config.yaml. Non-functional change.
Modified: core/trunk/geoext/lib/GeoExt/data/PrintPage.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/data/PrintPage.js 2010-09-02 21:18:45 UTC (rev 2303)
+++ core/trunk/geoext/lib/GeoExt/data/PrintPage.js 2010-09-03 06:33:22 UTC (rev 2304)
@@ -166,15 +166,23 @@
/** api: method[fit]
* :param fitTo: :class:`GeoExt.MapPanel` or ``OpenLayers.Map`` or ``OpenLayers.Feature.Vector``
* The map or feature 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.
- *
+ * :param options: ``Object`` Additional options to determine how to fit
+ *
* Fits the page layout to a map or feature extent. If the map extent has
* not been centered yet, this will do nothing.
+ *
+ * Available options:
+ *
+ * * mode - ``String`` How to calculate the print extent? If "closest",
+ * the closest matching print extent will be chosen. If "printer", the
+ * chosen print extent will be the closest one that can show the entire
+ * ``fitTo`` extent on the printer. If "screen", it will be the closest
+ * one that is entirely visible inside the ``fitTo`` extent. Default is
+ * "printer".
+ *
*/
- fit: function(fitTo, loose) {
+ fit: function(fitTo, options) {
+ options = options || {};
var map = fitTo, extent;
if(fitTo instanceof GeoExt.MapPanel) {
map = fitTo.map;
@@ -193,33 +201,30 @@
this.setCenter(center);
var units = map.getUnits();
var scale = this.printProvider.scales.getAt(0);
- var closest = {
- diff: Number.POSITIVE_INFINITY,
- scale: scale
- };
+ var closest = Number.POSITIVE_INFINITY;
var mapWidth = extent.getWidth();
var mapHeight = extent.getHeight();
this.printProvider.scales.each(function(rec) {
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;
+ if (options.mode == "closest") {
+ var diff =
+ Math.abs(bounds.getWidth() - mapWidth) +
+ Math.abs(bounds.getHeight() - mapHeight);
+ if (diff < closest) {
+ closest = diff;
+ scale = rec;
}
} else {
- // no need to continue if not contained and not loose
+ var contains = options.mode == "screen" ?
+ !extent.containsBounds(bounds) :
+ bounds.containsBounds(extent);
+ if (contains || (options.mode == "screen" && !contains)) {
+ scale = rec;
+ }
return contains;
}
}, this);
- this.setScale(loose ? closest.scale : scale, units);
+ this.setScale(scale, units);
delete this._updating;
this.updateFeature(this.feature.geometry, {
center: center,
Modified: core/trunk/geoext/lib/GeoExt/data/PrintProvider.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/data/PrintProvider.js 2010-09-02 21:18:45 UTC (rev 2303)
+++ core/trunk/geoext/lib/GeoExt/data/PrintProvider.js 2010-09-03 06:33:22 UTC (rev 2304)
@@ -335,14 +335,18 @@
*
* * ``legend`` - :class:`GeoExt.LegendPanel` If provided, the legend
* will be added to the print document. For the printed result to
- * look like the LegendPanel, the following settings in the
- * ``!legends`` block of the print module are recommended:
+ * look like the LegendPanel, the following ``!legends`` block
+ * should be included in the ``items`` of your page layout in the
+ * print module's configuration file:
*
* .. code-block:: none
*
- * maxIconWidth: 0
- * maxIconHeight: 0
- * classIndentation: 0
+ * - !legends
+ * maxIconWidth: 0
+ * maxIconHeight: 0
+ * classIndentation: 0
+ * layerSpace: 5
+ * layerFontSize: 10
*
* * ``overview`` - :class:`OpenLayers.Control.OverviewMap` If provided,
* the layers for the overview map in the printout will be taken from
Modified: core/trunk/geoext/lib/GeoExt/plugins/PrintExtent.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/plugins/PrintExtent.js 2010-09-02 21:18:45 UTC (rev 2303)
+++ core/trunk/geoext/lib/GeoExt/plugins/PrintExtent.js 2010-09-03 06:33:22 UTC (rev 2304)
@@ -88,9 +88,9 @@
control: null,
/** api: config[pages]
- * Array of :class:`GeoExt.data.PrintPage` The pages that this form
+ * Array of :class:`GeoExt.data.PrintPage` The pages that this plugin
* controls. Optional. If not provided, it will be created with one page
- * that fits the current map extent.
+ * that is completely contained within the visible map extent.
*
* .. note:: All pages must use the same PrintProvider.
*/
@@ -335,7 +335,7 @@
e.center.toShortString()
));
} else {
- page.fit(e.object.box);
+ page.fit(e.object.box, {mode: "closest"});
var minScale = this.printProvider.scales.getAt(0);
var maxScale = this.printProvider.scales.getAt(
this.printProvider.scales.getCount() - 1);
@@ -363,7 +363,7 @@
*/
fitPage: function() {
if(this.page) {
- this.page.fit(this.map);
+ this.page.fit(this.map, {mode: "screen"});
}
},
Modified: core/trunk/geoext/lib/GeoExt/widgets/MapPanel.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/MapPanel.js 2010-09-02 21:18:45 UTC (rev 2303)
+++ core/trunk/geoext/lib/GeoExt/widgets/MapPanel.js 2010-09-03 06:33:22 UTC (rev 2304)
@@ -343,9 +343,6 @@
if(this.ownerCt) {
this.ownerCt.un("move", this.updateMapSize, this);
}
- GeoExt.MapPanel.superclass.beforeDestroy.apply(this, arguments);
- // if the map panel was passed a map instance, this map instance
- // is under the user's responsibility
if(this.map && this.map.events) {
this.map.events.un({
"moveend": this.onMoveend,
@@ -353,6 +350,8 @@
scope: this
});
}
+ // if the map panel was passed a map instance, this map instance
+ // is under the user's responsibility
if(!this.initialConfig.map ||
!(this.initialConfig.map instanceof OpenLayers.Map)) {
// we created the map, we destroy it
@@ -361,6 +360,7 @@
}
}
delete this.map;
+ GeoExt.MapPanel.superclass.beforeDestroy.apply(this, arguments);
}
});
Modified: core/trunk/geoext/lib/GeoExt/widgets/PrintMapPanel.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/PrintMapPanel.js 2010-09-02 21:18:45 UTC (rev 2303)
+++ core/trunk/geoext/lib/GeoExt/widgets/PrintMapPanel.js 2010-09-03 06:33:22 UTC (rev 2304)
@@ -201,7 +201,7 @@
GeoExt.PrintMapPanel.superclass.initComponent.call(this);
- this.printProvider.on("layoutchange", this.updateExtent, this);
+ this.printProvider.on("layoutchange", this.syncSize, this);
this.printPage.on("change", this.fitZoom, this);
this.map.events.register("moveend", this, this.updatePage);
},
@@ -211,12 +211,28 @@
*/
afterRender: function() {
GeoExt.PrintMapPanel.superclass.afterRender.apply(this, arguments);
- this.updateExtent();
+ this.syncSize();
+ if (this.initialConfig.limitScales === true) {
+ if (!this.ownerCt) {
+ this.calculatePreviewScales()
+ } else {
+ this.ownerCt.on({
+ "afterlayout": {
+ fn: this.calculatePreviewScales,
+ scope: this,
+ single: true
+ }
+ });
+ }
+ this.on("resize", this.calculatePreviewScales, this);
+ }
},
/** private: method[adjustSize]
- * :param width: ``Number``
- * :param height: ``Number``
+ * :param width: ``Number`` If not provided or 0, initialConfig.width will
+ * be used.
+ * :param height: ``Number`` If not provided or 0, initialConfig.height
+ * will be used.
* Private override - sizing this component always takes the aspect ratio
* of the print page into account.
*/
@@ -227,8 +243,10 @@
// 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;
+ var targetWidth = (ownerCt && ownerCt.autoWidth) ? 0 :
+ (width || this.initialConfig.width);
+ var targetHeight = (ownerCt && ownerCt.autoHeight) ? 0 :
+ (height || this.initialConfig.height);
if (targetWidth) {
height = targetWidth / ratio;
if (targetHeight && height > targetHeight) {
@@ -245,17 +263,6 @@
return {width: width, height: height};
},
- /** private: method[updateExtent]
- * Makes sure that this :class:`PrintMapPanel` gets the aspect ratio that
- * matches the print page, and update the previewable scales.
- */
- updateExtent: function() {
- this.syncSize();
- if (this.initialConfig.limitScales === true) {
- this.calculatePreviewScales();
- }
- },
-
/** private: method[fitZoom]
* Fits this PrintMapPanel's zoom to the print scale.
*/
@@ -356,7 +363,7 @@
beforeDestroy: function() {
this.map.events.unregister("moveend", this, this.updatePage);
this.printPage.un("change", this.fitZoom, this);
- this.printProvider.un("layoutchange", this.updateExtent, this);
+ this.printProvider.un("layoutchange", this.syncSize, this);
GeoExt.PrintMapPanel.superclass.beforeDestroy.apply(this, arguments);
}
});
Modified: core/trunk/geoext/tests/lib/GeoExt/data/PrintPage.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/data/PrintPage.html 2010-09-02 21:18:45 UTC (rev 2303)
+++ core/trunk/geoext/tests/lib/GeoExt/data/PrintPage.html 2010-09-03 06:33:22 UTC (rev 2304)
@@ -79,14 +79,14 @@
}
function test_fit(t) {
- t.plan(3);
+ t.plan(4);
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"})],
+ width: 272,
+ height: 272,
+ layers: [new OpenLayers.Layer("empty", {isBaseLayer: true})],
center: center,
zoom: 7
});
@@ -97,12 +97,15 @@
})
});
- printPage.fit(mapPanel);
+ printPage.fit(mapPanel, {mode: "printer"});
t.eq(printPage.center.toString(), center.toString(), "Print page centered correctly.");
- t.eq(printPage.scale.get("value"), 2000000, "Print scale set correctly.");
+ t.eq(printPage.scale.get("value"), 4000000, "Print scale set correctly.");
- printPage.fit(mapPanel, true);
- t.eq(printPage.scale.get("value"), 4000000, "Print scale for 'loose' option set correctly.");
+ printPage.fit(mapPanel, {mode: "closest"});
+ t.eq(printPage.scale.get("value"), 2000000, "Print scale for 'closest' mode set correctly.");
+
+ printPage.fit(mapPanel, {mode: "screen"});
+ t.eq(printPage.scale.get("value"), 1000000, "Print scale for 'screen' mode set correctly.");
printPage.destroy();
mapPanel.destroy();
Modified: core/trunk/geoext/tests/lib/GeoExt/widgets/PrintMapPanel.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/PrintMapPanel.html 2010-09-02 21:18:45 UTC (rev 2303)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/PrintMapPanel.html 2010-09-03 06:33:22 UTC (rev 2304)
@@ -16,9 +16,9 @@
renderTo: "mappanel",
width: 256,
height: 256,
- layers: [new OpenLayers.Layer.WMS("Tasmania State Boundaries",
- "http://demo.opengeo.org/geoserver/wms",
- {layers: "topp:tasmania_state_boundaries"}, {singleTile: true})],
+ layers: [new OpenLayers.Layer("Empty",
+ {isBaseLayer: true}
+ )],
center: [146.56, -41.56],
zoom: 7
});
@@ -42,7 +42,7 @@
});
var printSize = printMapPanel.printProvider.layout.get("size");
- var size = printMapPanel.getSize();
+ var size = printMapPanel.map.getSize();
var center = mapPanel.map.getCenter();
var pageCenter = printMapPanel.printPage.center;
@@ -50,7 +50,7 @@
t.ok(printMapPanel.map.controls[0] instanceof OpenLayers.Control.PanPanel, "which is a PanPanel.");
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((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.eq((size.w/size.h).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.");
printMapPanel.destroy();
More information about the Commits
mailing list