[Commits] r1541 - in sandbox/ahocevar/playground/ux/Printing: examples ux ux/data ux/plugins ux/widgets
commits at geoext.org
commits at geoext.org
Thu Dec 3 00:34:15 CET 2009
Author: ahocevar
Date: 2009-12-03 00:34:15 +0100 (Thu, 03 Dec 2009)
New Revision: 1541
Added:
sandbox/ahocevar/playground/ux/Printing/ux/plugins/
sandbox/ahocevar/playground/ux/Printing/ux/plugins/PrintLayoutField.js
sandbox/ahocevar/playground/ux/Printing/ux/plugins/PrintPageAttributeField.js
sandbox/ahocevar/playground/ux/Printing/ux/widgets/
sandbox/ahocevar/playground/ux/Printing/ux/widgets/SimplePrint.js
Modified:
sandbox/ahocevar/playground/ux/Printing/examples/Printing.html
sandbox/ahocevar/playground/ux/Printing/examples/Printing.js
sandbox/ahocevar/playground/ux/Printing/ux/data/PrintProvider.js
Log:
created simple print form widget and helper plugins - not working yet.
Modified: sandbox/ahocevar/playground/ux/Printing/examples/Printing.html
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/examples/Printing.html 2009-12-02 18:01:45 UTC (rev 1540)
+++ sandbox/ahocevar/playground/ux/Printing/examples/Printing.html 2009-12-02 23:34:15 UTC (rev 1541)
@@ -9,6 +9,9 @@
<script src="../../../trunk/openlayers/lib/OpenLayers.js"></script>
<script type="text/javascript" src="../../../trunk/geoext/lib/GeoExt.js"></script>
<script type="text/javascript" src="../ux/data/PrintProvider.js"></script>
+ <script type="text/javascript" src="../ux/plugins/PrintLayoutField.js"></script>
+ <script type="text/javascript" src="../ux/plugins/PrintPageAttributeField.js"></script>
+ <script type="text/javascript" src="../ux/widgets/SimplePrint.js"></script>
<script type="text/javascript" src="Printing.js"></script>
<script type="text/javascript" src="http://demo.mapfish.org/mapfishsample/1.2/print/info.json?var=printCapabilities"></script>
Modified: sandbox/ahocevar/playground/ux/Printing/examples/Printing.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/examples/Printing.js 2009-12-02 18:01:45 UTC (rev 1540)
+++ sandbox/ahocevar/playground/ux/Printing/examples/Printing.js 2009-12-02 23:34:15 UTC (rev 1541)
@@ -35,5 +35,10 @@
zoom: 5
});
mapPanel.map.addLayer(redline);
+ var printForm = new GeoExt.ux.SimplePrint({
+ map: mapPanel,
+ printProvider: printProvider,
+ renderTo: document.body
+ });
});
Modified: sandbox/ahocevar/playground/ux/Printing/ux/data/PrintProvider.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/ux/data/PrintProvider.js 2009-12-02 18:01:45 UTC (rev 1540)
+++ sandbox/ahocevar/playground/ux/Printing/ux/data/PrintProvider.js 2009-12-02 23:34:15 UTC (rev 1541)
@@ -204,14 +204,15 @@
* * customData - ``Object`` Additional data that will be sent to the
* print service. Optional.
* * layer - ``OpenLayers.Layer.Vector`` a layer containing one or more
- * features created by :ref:`GeoExt.ux.PrintProvider.createFeature`.
- * For each feature, a page will be created. The center and the
- * rotation of the page will be determined from the feature geometry,
- * the scale will be taken from the feature's ``scale`` attribute. A
- * page title can be provided in the feature's ``title`` property, and
- * a page comment in the feature's ``comment`` property. If the
- * ``layer`` option is not provided, the following additional options
- * will be used to create a single page PDF:
+ * features with geometries and attributes set by
+ * :ref:`GeoExt.ux.PrintProvider.updateFeature`. For each feature, a
+ * page will be created. The center and the rotation of the page will
+ * be determined from the feature geometry, the scale will be taken
+ * from the feature's ``scale`` attribute. A page title can be provided
+ * in the feature's ``title`` property, and a page comment in the
+ * feature's ``comment`` property. If the ``layer`` option is not
+ * provided, the following additional options will be used to create a
+ * single page PDF:
* * center - ``OpenLayers.LonLat``|``Array`` center of a single-page
* map. If not provided, the center of the map will be used.
* * scale - ``Ext.data.Record``|``Float`` The scale of the page. One of
@@ -302,10 +303,14 @@
* :param feature: ``OpenLayers.Feature.Vector``
* :return: ``Float``
*
- * Gets the rotation of a feature that was originally created with
- * :ref:`GeoExt.ux.PrintProvider.createFeature`.
+ * Gets the rotation of a feature with a geometry originally created
+ * using ``OpenLayers.Bounds.toGeometry()``. Rotation is measured
+ * clockwise from North.
*/
getRotation: function(feature) {
+ if(!feature.geometry) {
+ return 0;
+ }
var points = feature.geometry.components[0].components;
var top = new OpenLayers.Geometry.LineString([points[2], points[3]]);
var right = new OpenLayers.Geometry.LineString([points[1], points[2]]);
@@ -358,35 +363,39 @@
* :param map: ``OpenLayers.Map``
* :param scale: ``Float``
* :param layout: ``Ext.data.Record``
+ * :param center: ``Openlayers.LonLat`` optional.
* :return: ``OpenLayers.Bounds``
*
* gets the bounds for a given map, scale and layout
*/
- getLayoutBounds: function(map, scale, layout) {
+ getLayoutBounds: function(map, scale, layout, center) {
var size = layout.get("size");
var unitsRatio = OpenLayers.INCHES_PER_UNIT[map.baseLayer.units];
var w = size.width / 72 / unitsRatio * scale / 2;
var h = size.height / 72 / unitsRatio * scale / 2;
- var center = map.getCenter();
+ var center = center || map.getCenter();
return new OpenLayers.Bounds(center.lon - w, center.lat - h,
center.lon + w, center.lat + h);
},
/** api:method[getBestScale]
* :param map: ``OpenLayers.Map``
- * :param layoutName: ``String``
+ * :param layoutName: ``String`` Optional layout. If not provided, the
+ * first available layout will be used.
* :return: ``Float``
*
* Calculates the best scale for a given map and layout. The best scale
* is considered the smallest one where the print page entirely fits
- * the currentmap extent.
+ * the current map extent.
*/
getBestScale: function(map, layoutName) {
if(map instanceof GeoExt.MapPanel) {
map = map.map;
}
- var layout = this.layouts.getAt(this.layouts.find("name", layoutName));
+ var layoutIndex = layoutName ?
+ this.layouts.find("name", layoutName) : 0;
+ var layout = this.layouts.getAt(layoutIndex);
var extent = map.getExtent();
var bounds, scale;
@@ -400,37 +409,35 @@
return scale;
},
- /** api:method[createFeature]
- * :param map: ``GeoExt.MapPanel``|``OpenLayers.Map`` the map to create a
- * layout feature for.
- * :param scale: ``Ext.data.Record``|``Float`` the scale of the print page.
- * If not provided, :ref:`GeoExt.ux.PrintProvider.getBestScale` will
- * be used.
- * :param layout: ``Ext.data.Record``|``String`` the layout of the print
- * page.
- * :return: ``OpenLayers.Feature.Vector`` A feature to be used for the
- * layer that determines the print pages in
- * :ref:`GeoExt.ux.PrintProvider.print`.
- *
- * Creates a vector feature that represents the extent of a print page
- * for a given map, scale and layout.
+ /** api:function[updateFeature]
+ * :param feature: ``OpenLayers.Feature.Vector`` The feature to update.
+ * :param attributes: ``Object`` Attributes that will be applied to the
+ * feature, overriding existing attributes.
+ *
+ * Updates a feature to represent a print page. The updated feature will
+ * have a ``scale``, ``layout`` and ``rotation`` attribute. The geometry
+ * will be the bounds of the print page in map units.
*/
- createFeature: function(map, scale, layout) {
- if(map instanceof GeoExt.MapPanel) {
- map = map.map;
- }
- layout = layout || this.layouts.get(0);
- if(typeof layout === "string") {
- layout = this.layouts.getAt(this.layouts.find("name", layout));
- }
- scale = scale || this.getBestScale(map, layout.get("name"));
- if(scale instanceof Ext.data.Record) {
- scale = this.scales.get("value");
- }
- return new OpenLayers.Feature.Vector(
- this.getLayoutBounds(map, scale, layout).toGeometry(),
- {scale: scale}
+ updateFeature: function(feature, attributes) {
+ var map = feature.layer.map;
+ var scale = attributes.scale || feature.attributes.scale;
+ var layout = attributes.layout || feature.attributes.layout;
+ var geom = this.getLayoutBounds(
+ map,
+ scale || this.getBestScale(map, layout),
+ layout,
+ feature.geometry ?
+ feature.geometry.getBounds().getCenterLonLat() :
+ map.getCenter()
);
+ attributes.rotation = attributes.rotation || feature.getRotation();
+ geom.rotate(-rotation, geom.getCentroid());
+ feature.geometry = geom;
+ Ext.apply(feature.attributes, attributes);
+ feature.layer.events.triggerEvent("featuremodified", {
+ feature: feature
+ });
+ feature.layer.drawFeature(feature);
}
});
Added: sandbox/ahocevar/playground/ux/Printing/ux/plugins/PrintLayoutField.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/ux/plugins/PrintLayoutField.js (rev 0)
+++ sandbox/ahocevar/playground/ux/Printing/ux/plugins/PrintLayoutField.js 2009-12-02 23:34:15 UTC (rev 1541)
@@ -0,0 +1,35 @@
+Ext.namespace("GeoExt.ux.plugins");
+
+GeoExt.ux.plugins.PrintLayoutField = Ext.extend(Ext.util.Observable, {
+
+ printProvider: null,
+
+ layer: null,
+
+ /** private: method[constructor]
+ */
+ constructor: function(config) {
+ this.initialConfig = config;
+ Ext.apply(this, config);
+
+ GeoExt.ux.plugins.PrintLayoutField.superclass.constructor.apply(this, arguments);
+ },
+
+ init: function(target) {
+ target.on({
+ "change": function(field, newValue){
+ this.setLayout(newValue);
+ },
+ scope: this
+ });
+ },
+
+ setLayout: function(layout) {
+ Ext.each(this.layer.features, function(feature){
+ this.printProvider.updateFeature(feature, {layout: layout});
+ }, this);
+ }
+});
+
+/** api: ptype = gx-printlayoutfield */
+Ext.preg && Ext.preg("gx-printlayoutfield", GeoExt.ux.plugins.PrintLayoutField);
Added: sandbox/ahocevar/playground/ux/Printing/ux/plugins/PrintPageAttributeField.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/ux/plugins/PrintPageAttributeField.js (rev 0)
+++ sandbox/ahocevar/playground/ux/Printing/ux/plugins/PrintPageAttributeField.js 2009-12-02 23:34:15 UTC (rev 1541)
@@ -0,0 +1,37 @@
+Ext.namespace("GeoExt.ux.plugins");
+
+GeoExt.ux.plugins.PrintPageAttributeField = Ext.extend(Ext.util.Observable, {
+
+ printProvider: null,
+
+ feature: null,
+
+ attribute: null,
+
+ /** private: method[constructor]
+ */
+ constructor: function(config) {
+ this.initialConfig = config;
+ Ext.apply(this, config);
+
+ GeoExt.ux.plugins.PrintPageAttributeField.superclass.constructor.apply(this, arguments);
+ },
+
+ init: function(target) {
+ target.on({
+ "change": function(field, newValue) {
+ this.setAttribute(newValue);
+ },
+ scope: this
+ });
+ },
+
+ setAttribute: function(value) {
+ var attributes = {};
+ attributes[this.attribute] = value;
+ this.printProvider.updateFeature(this.feature, attributes);
+ }
+});
+
+/** api: ptype = gx-printscalescombo */
+Ext.preg && Ext.preg("gx-printpageattributefield", GeoExt.ux.plugins.PrintPageAttributeField);
Added: sandbox/ahocevar/playground/ux/Printing/ux/widgets/SimplePrint.js
===================================================================
--- sandbox/ahocevar/playground/ux/Printing/ux/widgets/SimplePrint.js (rev 0)
+++ sandbox/ahocevar/playground/ux/Printing/ux/widgets/SimplePrint.js 2009-12-02 23:34:15 UTC (rev 1541)
@@ -0,0 +1,89 @@
+Ext.namespace("GeoExt.ux")
+
+GeoExt.ux.SimplePrint = Ext.extend(Ext.Panel, {
+
+ titleText: "Title",
+ commentsText: "Comments",
+ layoutText: "Layout",
+ dpiText: "DPI",
+ scaleText: "Scale",
+ rotationText: "Rotation",
+
+ layout: "form",
+
+ printProvider: null,
+
+ map: null,
+
+ initComponent: function() {
+ if(this.map instanceof GeoExt.MapPanel) {
+ this.map = this.map.map;
+ }
+
+ this.layer = new OpenLayers.Layer.Vector(null, {
+ displayInLayerSwitcher: false
+ });
+ this.layer.addFeatures(new OpenLayers.Feature.Vector(null, {}));
+ this.map.addLayer(this.layer);
+
+ this.add({
+ xtype: "textfield",
+ label: this.titleText,
+ plugins: new GeoExt.ux.plugins.PrintPageAttributeField({
+ printProvider: this.printProvider,
+ attribute: "title",
+ feature: this.layer.features[0]
+ })
+ });
+ this.add({
+ xtype: "textfield",
+ label: this.commentsText,
+ plugins: new GeoExt.ux.plugins.PrintPageAttributeField({
+ printProvider: this.printProvider,
+ attribute: "comment",
+ feature: this.layer.features[0]
+ })
+ });
+ this.add({
+ xtype: "combo",
+ label: this.layoutText,
+ store: this.printProvider.layouts,
+ valueField: "value",
+ displayField: "name",
+ plugins: new GeoExt.ux.plugins.PrintLayoutField({
+ printProvider: this.printProvider,
+ layer: this.layer
+ })
+ });
+ this.add({
+ xtype: "combo",
+ label: this.dpiText,
+ store: this.printProvider.dpis,
+ valueField: "value",
+ displayField: "name"
+ });
+ this.add({
+ xtype: "combo",
+ label: this.scaleText,
+ store: this.printProvider.scales,
+ valueField: "value",
+ displayField: "name",
+ plugins: new GeoExt.ux.plugins.PrintPageAttributeField({
+ printProvider: this.printProvider,
+ attribute: "scale",
+ feature: this.layer.features[0]
+ })
+ });
+ this.add({
+ xtype: "textfield",
+ label: this.rotationText,
+ plugins: new GeoExt.ux.plugins.PrintPageAttributeField({
+ printProvider: this.printProvider,
+ attribute: "rotation",
+ feature: this.layer.features[0]
+ })
+ });
+ this.doLayout();
+ }
+
+});
More information about the Commits
mailing list