[Commits] r1837 - in sandbox/ahocevar/playground/trunk/geoext: examples lib/GeoExt/data lib/GeoExt/widgets tests/lib/GeoExt/data tests/lib/GeoExt/widgets
commits at geoext.org
commits at geoext.org
Fri Jan 29 00:22:45 CET 2010
Author: ahocevar
Date: 2010-01-29 00:22:45 +0100 (Fri, 29 Jan 2010)
New Revision: 1837
Modified:
sandbox/ahocevar/playground/trunk/geoext/examples/print-extent.html
sandbox/ahocevar/playground/trunk/geoext/examples/print-extent.js
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/lib/GeoExt/widgets/PrintExtent.js
sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/data/PrintPage.html
sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/widgets/PrintExtent.html
sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/widgets/PrintMapPanel.html
Log:
PrintPage and PrintExtent changes to use OpenLayers.Control.TransformFeature
Modified: sandbox/ahocevar/playground/trunk/geoext/examples/print-extent.html
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/examples/print-extent.html 2010-01-28 19:46:52 UTC (rev 1836)
+++ sandbox/ahocevar/playground/trunk/geoext/examples/print-extent.html 2010-01-28 23:22:45 UTC (rev 1837)
@@ -6,7 +6,7 @@
<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 src="../../../trunk/openlayers/lib/OpenLayers.js"></script>
<script type="text/javascript" src="../lib/GeoExt.js"></script>
<script type="text/javascript" src="print-extent.js"></script>
@@ -25,9 +25,10 @@
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>Drag one of the handles to control scale and rotation. Hold the
- SHIFT key to rotate in 45° increments. Drag the extent rectangle to
- change the center.</p>
+ <p>Drag one of the handles to control the scale. Grab one of the
+ corner handles at its edge to rotate the extent. Hold the SHIFT key to
+ rotate in 45° increments only. Drag the extent rectangle to change the
+ center.</p>
<p>The js is not minified so it is readable. See <a href="print-extent.js">print-extent.js</a>.</p>
<div id="content"></div>
</body>
Modified: sandbox/ahocevar/playground/trunk/geoext/examples/print-extent.js
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/examples/print-extent.js 2010-01-28 19:46:52 UTC (rev 1836)
+++ sandbox/ahocevar/playground/trunk/geoext/examples/print-extent.js 2010-01-28 23:22:45 UTC (rev 1837)
@@ -6,17 +6,18 @@
* of the license.
*/
-/** api: example[print-page]
- * Printing contents from a MapPanel
- * ---------------------------------
- * Using PrintPage and PrintProvider to print the visible extent of a MapPanel.
+/** api: example[print-extent]
+ * Setting the Print Extent interactively
+ * --------------------------------------
+ * Using the PrintExtent component to interactively change scale, center and
+ * rotation of a print page.
*/
-var mapPanel, printPage;
+var mapPanel, printProvider;
Ext.onReady(function() {
// The printProvider that connects us to the print service
- var printProvider = new GeoExt.data.PrintProvider({
+ printProvider = new GeoExt.data.PrintProvider({
method: "GET", // "POST" recommended for production use
capabilities: printCapabilities, // from the info.json script in the html
customParams: {
Modified: sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/data/PrintPage.js
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/data/PrintPage.js 2010-01-28 19:46:52 UTC (rev 1836)
+++ sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/data/PrintPage.js 2010-01-28 23:22:45 UTC (rev 1837)
@@ -19,8 +19,7 @@
* Provides a representation of a print page for
* :class:`GeoExt.data.PrintProvider`. The extent of the page is stored as
* ``OpenLayers.Feature.Vector``. Widgets can use this to display the print
- * extent on the map. In addition, a handle feature is also provided, which
- * controls can use to modify the print extent's scale and rotation.
+ * extent on the map.
*/
GeoExt.data.PrintPage = Ext.extend(Ext.util.Observable, {
@@ -40,12 +39,6 @@
*/
feature: null,
- /** private: property[handles]
- * Array(``OpenLayers.Feature.Vector``) Features providing the four
- * scale/rotation handles for the page.
- */
- handles: null,
-
/** api: property[scale]
* ``Ext.data.Record`` The current scale record of the page. Read-only.
*/
@@ -84,6 +77,9 @@
*
* Listener arguments:
* * printPage - :class:`GeoExt.data.PrintPage` this printPage
+ * * modifications - ``Object`` Object with one or more of
+ * ``scale``, ``center`` and ``rotation``, notifying
+ * listeners of the changed properties.
*/
"change"
);
@@ -92,21 +88,7 @@
this.feature = new OpenLayers.Feature.Vector(
OpenLayers.Geometry.fromWKT("POLYGON((-1 -1,1 -1,1 1,-1 1,-1 -1))"));
- this.handles = [
- new OpenLayers.Feature.Vector(
- new OpenLayers.Geometry.Point(-1,-1)
- ),
- new OpenLayers.Feature.Vector(
- new OpenLayers.Geometry.Point(1,-1)
- ),
- new OpenLayers.Feature.Vector(
- new OpenLayers.Geometry.Point(1,1)
- ),
- new OpenLayers.Feature.Vector(
- new OpenLayers.Geometry.Point(-1,1)
- )
- ];
-
+
this.printProvider.on({
"layoutchange": this.onLayoutChange,
scope: this
@@ -125,8 +107,8 @@
/** api: method[setScale]
* :param scale: ``Ext.data.Record`` The new scale record.
* :param units: ``String`` map units to use for the scale calculation.
- * Optional if a ``layer`` that is added to a map was configured.
- * If neither is provided, "dd" will be assumed.
+ * Optional if the ``feature`` is on a layer which is added to a map.
+ * If not found, "dd" will be assumed.
*
* Updates the page geometry to match a given scale. Since this takes the
* current layout of the printProvider into account, this can be used to
@@ -139,8 +121,7 @@
if(rotation != 0) {
geom.rotate(-rotation, geom.getCentroid());
}
- this.scale = scale;
- this.updateFeature(geom);
+ this.updateFeature(geom, {scale: scale});
},
/** api: method[setCenter]
@@ -154,7 +135,7 @@
var dx = center.lon - oldCenter.lon;
var dy = center.lat - oldCenter.lat;
geom.move(dx, dy);
- this.updateFeature(geom);
+ this.updateFeature(geom, {center: center});
},
/** api: method[setRotation]
@@ -166,35 +147,40 @@
if(this.printProvider.layout.get("rotation") === true) {
var geom = this.feature.geometry;
geom.rotate(this.rotation - rotation, geom.getCentroid());
- this.rotation = rotation;
- this.updateFeature(geom);
+ this.updateFeature(geom, {rotation: rotation});
}
},
/** api: method[fit]
- * :param map: :class:`GeoExt.MapPanel`|``OpenLayers.Map`` The map to fit
- * the page to.
+ * :param fitTo: :class:`GeoExt.MapPanel`|``OpenLayers.Map``|``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.
*
- * Fits the page layout to the current map extent. If the map has not
- * been centered yet, this will do nothing.
+ * Fits the page layout to a map or feature extent. If the map extent has
+ * not been centered yet, this will do nothing.
*/
- fit: function(map, loose) {
- if(map instanceof GeoExt.MapPanel) {
- map = map.map;
+ fit: function(fitTo, loose) {
+ var map = fitTo, extent;
+ if(fitTo instanceof GeoExt.MapPanel) {
+ map = fitTo.map;
+ } else if(fitTo instanceof OpenLayers.Feature.Vector) {
+ map = fitTo.layer.map;
+ extent = fitTo.geometry.getBounds();
}
- var center = map.getCenter();
- if(!center) {
- return;
+ if(!extent) {
+ extent = map.getExtent();
+ if(!extent) {
+ return;
+ }
}
+ var center = extent.getCenterLonLat();
this.suspendEvents();
this.setCenter(center);
this.resumeEvents();
- var extent = map.getExtent();
- var units = map.baseLayer.units;
+ var units = map.getUnits();
var scale, looseScale, contains;
this.printProvider.scales.each(function(rec) {
looseScale = scale || rec;
@@ -206,140 +192,40 @@
this.setScale(loose && contains ? looseScale : scale, units);
},
- /** private: method[updateByHandle]
- * :param handle: ``OpenLayers.Feature.Vector`` the handle to use.
- * :param updateHandles: ``Boolean`` If set to false, only the feature
- * will be updated, but the handles will not be aligned. Defaults to
- * false.
- * :param rotationIncrement: ``Float`` Optional rotation increment.
- * Defaults to 1.
- *
- * Updates scale and rotation based on the current handle location. This
- * method is useful for drag handlers on the handle geometry, when
- * displayed on a layer.
- */
- updateByHandle: function(handle, updateHandles, rotationIncrement) {
- rotationIncrement = rotationIncrement || 1;
- var handles = this.handles;
- handle = handle || handles[0];
- var handleIndex = handles.indexOf(handle);
- if(handleIndex === -1) {
- return;
- }
-
- var rotate = this.printProvider.layout.get("rotation");
- var vertices = this.feature.geometry.components[0].components;
- var fGeom = this.feature.geometry;
- var hGeom = handle.geometry;
- var origin = fGeom.getCentroid();
-
- // resize handles
- var resizeBy = origin.distanceTo(handle.geometry) /
- origin.distanceTo(vertices[handleIndex]);
- var handleRect = fGeom.clone();
- handleRect.resize(resizeBy, origin);
-
- // rotate handles
- if(rotate) {
- var dxH = hGeom.x - origin.x;
- var dyH = hGeom.y - origin.y;
- var dxRef = vertices[handleIndex].x - origin.x;
- var dyRef = vertices[handleIndex].y - origin.y;
- var handleRot = Math.round(Math.atan2(dxH, dyH) * 180 / Math.PI) -
- Math.round(Math.atan2(dxRef, dyRef) * 180 / Math.PI);
- handleRot && handleRect.rotate(-handleRot, origin);
- }
-
- this.updateHandles(handleRect, handle);
-
- // fit scale of the page to the handle rectangle
- var top = new OpenLayers.Geometry.LineString([
- handles[2].geometry, handles[3].geometry]);
- var topCenter = top.getBounds().getCenterLonLat();
- var dist = new OpenLayers.Geometry.Point(
- topCenter.lon, topCenter.lat).distanceTo(origin);
- var scaleFits = [], distHash = {};
- this.printProvider.scales.each(function(rec){
- var bounds = this.calculatePageBounds(rec);
- var d = Math.abs((bounds.getHeight() / 2) - dist);
- scaleFits.push(d);
- distHash[d.toPrecision(8)] = rec;
- }, this);
- var min = scaleFits.concat().sort(function(a,b){return a<b?-1:1;})[0];
- var scale = distHash[min.toPrecision(8)];
- var bounds = this.calculatePageBounds(scale);
- var geom = bounds.toGeometry();
-
- // fit rotation of the page to the handle rectangle
- var rotation = 0;
- if(rotate) {
- var dx = topCenter.lon - origin.x;
- var dy = topCenter.lat - origin.y;
- rotation = Math.round(
- Math.atan2(dx, dy) * 180 / Math.PI / rotationIncrement) *
- rotationIncrement;
- geom.rotate(-rotation, geom.getCentroid());
- }
-
- this.scale = scale;
- this.rotation = rotation;
- this.updateFeature(geom, updateHandles === true);
- },
-
/** private: method[updateFeature]
* :param geometry: ``OpenLayers.Geometry`` New geometry for the feature.
* If not provided, the existing geometry will be left unchanged.
- * :param updateHandles: ``Boolean`` If set to false, only the feature
- * will be updated, but the handles will not be aligned. Defaults to
- * true.
+ * :param mods: ``Object`` An object with one or more of ``scale``,
+ * ``center`` and ``rotation``, reflecting the page properties to
+ * update.
*
- * Updates the page feature with a new geometry and aligns the handle
- * with it.
+ * Updates the page feature with a new geometry and notifies listeners
+ * of changed page properties.
*/
- updateFeature: function(geometry, updateHandles) {
+ updateFeature: function(geometry, mods) {
+ var modified = false;
+ for(var property in mods) {
+ if(mods[property] === this[property]) {
+ delete mods[property];
+ } else {
+ this[property] = mods[property];
+ modified = true;
+ }
+ }
+ Ext.apply(this, mods);
var f = this.feature;
geometry.id = f.geometry.id;
f.geometry = geometry;
f.layer && f.layer.drawFeature(f);
- if(updateHandles !== false) {
- this.updateHandles();
- }
- this.fireEvent("change", this);
- },
+ modified && this.fireEvent("change", this, mods);
+ },
- /** private: method[updateHandles]
- * :param geometry: ``OpenLayers.Geometry.Polygon`` Optional. If provided,
- * handle geometries will be taken from the vertices of the provided
- * polygon instead of this page's feature's geometry.
- * :param excludeHandle: ``OpenLayers.Feature``. Optional. If one of the
- * features of the handles array is provided, its geometry will not be
- * updated.
- */
- updateHandles: function(geometry, excludeHandle) {
- var f = this.feature;
- var h = this.handles;
- var c = (geometry || f.geometry).components[0].components;
- var layer = h[0].layer;
- var id, handle, hGeom;
- for(var i=0; i<4; ++i) {
- handle = h[i];
- if(handle !== excludeHandle) {
- hGeom = handle.geometry;
- id = hGeom.id;
- hGeom = c[i].clone();
- hGeom.id = id;
- handle.geometry = hGeom;
- layer && layer.drawFeature(handle);
- }
- }
- },
-
/** private: method[calculatePageBounds]
* :param scale: ``Ext.data.Record`` Scale record to calculate the page
* bounds for.
* :param units: ``String`` Map units to use for the scale calculation.
- * Optional if ``feature`` is added to layer which is added to a
+ * Optional if ``feature`` is added to a layer which is added to a
* map. If not provided, "dd" will be assumed.
* :return: ``OpenLayers.Bounds``
*
@@ -353,7 +239,7 @@
var size = this.printProvider.layout.get("size");
var units = units ||
- (f.layer && f.layer.map && f.layer.map.baseLayer.units) ||
+ (f.layer && f.layer.map && f.layer.map.getUnits()) ||
"dd";
var unitsRatio = OpenLayers.INCHES_PER_UNIT[units];
var w = size.width / 72 / unitsRatio * s / 2;
@@ -367,7 +253,10 @@
* Handler for the printProvider's layoutchange event.
*/
onLayoutChange: function() {
- this.updateByHandle(this.handles[0], true);
+ if(this.printProvider.layout.get("rotation") === false) {
+ this.rotation = 0;
+ }
+ this.setScale(this.scale);
},
/** private: method[destroy]
@@ -376,4 +265,4 @@
this.printProvider.un("layoutchange", this.onLayoutChange, this);
}
-});
\ 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-28 19:46:52 UTC (rev 1836)
+++ sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/data/PrintProvider.js 2010-01-28 23:22:45 UTC (rev 1837)
@@ -325,9 +325,8 @@
var encodedPages = [];
Ext.each(pages, function(page) {
- var center = page.getCenter();
encodedPages.push(Ext.apply({
- center: [center.lon, center.lat],
+ center: [page.center.lon, page.center.lat],
scale: page.scale.get("value"),
rotation: page.rotation
}, page.customParams));
Modified: sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/widgets/PrintExtent.js
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/widgets/PrintExtent.js 2010-01-28 19:46:52 UTC (rev 1836)
+++ sandbox/ahocevar/playground/trunk/geoext/lib/GeoExt/widgets/PrintExtent.js 2010-01-28 23:22:45 UTC (rev 1837)
@@ -76,8 +76,8 @@
layer: null,
/** private: property[control]
- * ``OpenLayers.Control.DragFeature`` The control used to change extent
- * center, rotation and scale.
+ * ``OpenLayers.Control.TransformFeature`` The control used to change
+ * extent, center, rotation and scale.
*/
control: null,
@@ -95,6 +95,12 @@
*/
pages: null,
+ /** private: property[currentPage]
+ * :class:`GeoExt.data.PrintPage` The page currently set for
+ * transformation.
+ */
+ currentPage: null,
+
/** private: method[initComponent]
*/
initComponent: function() {
@@ -129,6 +135,7 @@
this.map = mapPanel.map;
this.initLayer();
this.initControl();
+ this.printProvider.on("layoutchange", this.onLayoutChange, this);
if(!this.initialConfig.pages) {
this.map.getCenter() ?
@@ -145,11 +152,13 @@
* :param mapPanel: class:`GeoExt.MapPanel`
*/
removeFromMapPanel: function(mapPanel) {
+ this.printProvider.un("layoutchange", this.onLayoutChange, this);
this.control.deactivate();
this.map.removeControl(this.control);
for(var i=0, len=this.pages.length; i<len; ++i) {
var page = this.pages[i];
- this.layer.removeFeatures([page.feature].concat(page.handles));
+ page.un("change", this.onPageChange, this);
+ this.layer.removeFeatures([page.feature]);
}
this.initialConfig.layer || this.map.removeLayer(this.layer);
this.map = null;
@@ -165,7 +174,8 @@
}
for(var i=0, len=this.pages.length; i<len; ++i) {
var page = this.pages[i];
- this.layer.addFeatures([page.feature].concat(page.handles));
+ this.layer.addFeatures([page.feature]);
+ page.on("change", this.onPageChange, this);
}
if(!this.layer.map) {
this.map.addLayer(this.layer);
@@ -183,28 +193,77 @@
pages[i].updateHandles();
};
}
- this.control = new OpenLayers.Control.DragFeature(this.layer, {
- onDrag: function(feature) {
- var geom = feature.geometry;
- if(geom instanceof OpenLayers.Geometry.Polygon) {
- // a page geometry was dragged
- updateHandles();
- } else if(geom instanceof OpenLayers.Geometry.Point) {
- // a scale/rotation handle was dragged
- for(var i=0, len=pages.length; i<len; ++i) {
- pages[i].updateByHandle(feature, false,
- this.handlers.drag.evt.shiftKey && 45);
+ this.control = new OpenLayers.Control.TransformFeature(this.layer, {
+ preserveAspectRatio: true,
+ eventListeners: {
+ "beforesetfeature": function(e) {
+ for(var i=0, len=this.pages.length; i<len; ++i) {
+ if(this.pages[i].feature === e.feature) {
+ this.currentPage = this.pages[i];
+ e.object.rotation = -this.pages[i].rotation;
+ break;
+ }
}
- }
- },
- onComplete: updateHandles
+ },
+ "beforetransform": function(e) {
+ var page = this.currentPage;
+ if(e.rotation) {
+ if(this.printProvider.layout.get("rotation")) {
+ page.setRotation(-e.object.rotation);
+ } else {
+ e.object.setFeature(this.currentPage.feature);
+ }
+ } else {
+ page.fit(e.object.box);
+ var minScale = this.printProvider.scales.getAt(0);
+ var maxScale = this.printProvider.scales.getAt(
+ this.printProvider.scales.getCount() - 1);
+ var boxBounds = e.object.box.geometry.getBounds();
+ var pageBounds = page.feature.geometry.getBounds();
+ var tooLarge = page.scale === minScale &&
+ boxBounds.containsBounds(pageBounds);
+ var tooSmall = page.scale === maxScale &&
+ pageBounds.containsBounds(boxBounds);
+ if(tooLarge === true || tooSmall === true) {
+ e.object.setFeature(this.currentPage.feature,
+ {rotation: this.currentPage.rotation});
+ }
+ }
+ return false;
+ },
+ "transformcomplete": function(e) {
+ this.control.setFeature(this.currentPage.feature, {
+ rotation: -this.currentPage.rotation
+ });
+ },
+ scope: this
+ }
});
}
this.map.addControl(this.control);
- this.control.activate();
},
+ /** private: method[onLayoutChange]
+ * Handler for the printProvider's layoutchange event.
+ */
+ onLayoutChange: function(printProvider, layout) {
+ this.control.setFeature(this.currentPage.feature, {
+ rotation: -this.currentPage.rotation
+ });
+ },
+
+ /** private: method[onPageChange]
+ * Handler for a page's change event.
+ */
+ onPageChange: function(page, mods) {
+ if(this.control.feature !== page.feature) {
+ this.control.setFeature(page.feature, {
+ rotation: -page.rotation
+ });
+ }
+ },
+
/** private: method[beforeDestroy]
*/
beforeDestroy: function() {
@@ -215,6 +274,7 @@
}
delete this.layer;
delete this.control;
+ delete this.currentPage;
this.rendered = false;
GeoExt.PrintExtent.superclass.beforeDestroy.apply(this, arguments);
}
Modified: sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/data/PrintPage.html
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/data/PrintPage.html 2010-01-28 19:46:52 UTC (rev 1836)
+++ sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/data/PrintPage.html 2010-01-28 23:22:45 UTC (rev 1837)
@@ -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_constructor(t) {
- t.plan(4);
+ t.plan(3);
var log = {};
var printProvider = new GeoExt.data.PrintProvider({
@@ -22,7 +22,6 @@
});
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));
@@ -32,7 +31,7 @@
}
function test_setCenter(t) {
- t.plan(2);
+ t.plan(1);
var printPage = new GeoExt.data.PrintPage({
printProvider: new GeoExt.data.PrintProvider({
@@ -42,14 +41,13 @@
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.");
+ t.eq(printPage.center.toString(), center.toString(), "center set correctly.");
printPage.destroy();
}
function test_setScale(t) {
- t.plan(3);
+ t.plan(1);
var printProvider = new GeoExt.data.PrintProvider({
capabilities: printCapabilities
@@ -62,16 +60,11 @@
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);
+ t.plan(1);
var printPage = new GeoExt.data.PrintPage({
printProvider: new GeoExt.data.PrintProvider({
@@ -81,8 +74,6 @@
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();
}
@@ -107,7 +98,7 @@
});
printPage.fit(mapPanel);
- t.eq(printPage.getCenter().toString(), center.toString(), "Print page centered correctly.");
+ t.eq(printPage.center.toString(), center.toString(), "Print page centered correctly.");
t.eq(printPage.scale.get("value"), 2000000, "Print scale set correctly.");
printPage.fit(mapPanel, true);
@@ -117,29 +108,6 @@
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>
Modified: sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/widgets/PrintExtent.html
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/widgets/PrintExtent.html 2010-01-28 19:46:52 UTC (rev 1836)
+++ sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/widgets/PrintExtent.html 2010-01-28 23:22:45 UTC (rev 1837)
@@ -24,7 +24,7 @@
}
function test_addToMapPanel_removeFromMapPanel(t) {
- t.plan(9);
+ t.plan(8);
var printExtent = new GeoExt.PrintExtent({
printProvider: new GeoExt.data.PrintProvider({
@@ -48,7 +48,6 @@
t.ok(printExtent.map === mapPanel.map, "map property of printExtent set.");
t.ok(printExtent.pages[0].getCenter().equals(printExtent.map.getCenter()), "Print page centered to map center.");
t.ok(printExtent.layer.map == mapPanel.map, "Auto-generated layer added to map.");
- t.eq(printExtent.layer.features.length, 5, "Extent and handle features added to the auto-generated layer.");
t.ok(printExtent.pages[0].feature.layer == printExtent.layer, "Extent feature was added to the layer.");
t.ok(printExtent.control.map == mapPanel.map, "Control created and added to map.");
Modified: sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/widgets/PrintMapPanel.html
===================================================================
--- sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/widgets/PrintMapPanel.html 2010-01-28 19:46:52 UTC (rev 1836)
+++ sandbox/ahocevar/playground/trunk/geoext/tests/lib/GeoExt/widgets/PrintMapPanel.html 2010-01-28 23:22:45 UTC (rev 1837)
@@ -50,7 +50,7 @@
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.ok(printMapPanel.printPage.getCenter().equals(center), "Print page has the same center as the source map.");
+ t.ok(printMapPanel.printPage.center.equals(center), "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();
More information about the Commits
mailing list