[Commits] r1874 - in core/trunk/geoext: lib/GeoExt/data tests/lib/GeoExt/data
commits at geoext.org
commits at geoext.org
Mon Feb 8 14:48:19 CET 2010
Author: ahocevar
Date: 2010-02-08 14:48:18 +0100 (Mon, 08 Feb 2010)
New Revision: 1874
Modified:
core/trunk/geoext/lib/GeoExt/data/PrintPage.js
core/trunk/geoext/lib/GeoExt/data/PrintProvider.js
core/trunk/geoext/tests/lib/GeoExt/data/PrintPage.html
core/trunk/geoext/tests/lib/GeoExt/data/PrintProvider.html
Log:
Removed unused handle code from GeoExt.data.PrintPage. r=elemoine (closes #210)
Modified: core/trunk/geoext/lib/GeoExt/data/PrintPage.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/data/PrintPage.js 2010-02-08 10:43:52 UTC (rev 1873)
+++ core/trunk/geoext/lib/GeoExt/data/PrintPage.js 2010-02-08 13:48:18 UTC (rev 1874)
@@ -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,46 +135,53 @@
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]
* :param rotation: ``Float`` The new rotation.
+ * :param force: ``Boolean`` If set to true, the rotation will also be
+ * set when the layout does not support it. Default is false.
*
* Sets a new rotation for the page geometry.
*/
- setRotation: function(rotation) {
- if(this.printProvider.layout.get("rotation") === true) {
+ setRotation: function(rotation, force) {
+ if(force || 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.getUnits();
var scale, looseScale, contains;
this.printProvider.scales.each(function(rec) {
@@ -206,140 +194,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``
*
@@ -367,7 +255,10 @@
* Handler for the printProvider's layoutchange event.
*/
onLayoutChange: function() {
- this.updateByHandle(this.handles[0], true);
+ if(this.printProvider.layout.get("rotation") === false) {
+ this.setRotation(0, true);
+ }
+ this.setScale(this.scale);
},
/** private: method[destroy]
Modified: core/trunk/geoext/lib/GeoExt/data/PrintProvider.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/data/PrintProvider.js 2010-02-08 10:43:52 UTC (rev 1873)
+++ core/trunk/geoext/lib/GeoExt/data/PrintProvider.js 2010-02-08 13:48:18 UTC (rev 1874)
@@ -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: core/trunk/geoext/tests/lib/GeoExt/data/PrintPage.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/data/PrintPage.html 2010-02-08 10:43:52 UTC (rev 1873)
+++ core/trunk/geoext/tests/lib/GeoExt/data/PrintPage.html 2010-02-08 13:48:18 UTC (rev 1874)
@@ -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: core/trunk/geoext/tests/lib/GeoExt/data/PrintProvider.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/data/PrintProvider.html 2010-02-08 10:43:52 UTC (rev 1873)
+++ core/trunk/geoext/tests/lib/GeoExt/data/PrintProvider.html 2010-02-08 13:48:18 UTC (rev 1874)
@@ -177,4 +177,4 @@
<div id="map" style="width:400px; height:300px"></div>
<div id="legend" style="width:200px; height:300px"></div>
</body>
-</html>
+</html>
\ No newline at end of file
More information about the Commits
mailing list