[Commits] r749 - sandbox/bartvde/legend/geoext/lib/GeoExt/widgets
commits at geoext.org
commits at geoext.org
Fri May 15 10:45:58 CEST 2009
Author: bartvde
Date: 2009-05-15 10:45:58 +0200 (Fri, 15 May 2009)
New Revision: 749
Modified:
sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/LegendPanel.js
Log:
add support for reordering of layers, depends on ticket:65
Modified: sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/LegendPanel.js
===================================================================
--- sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/LegendPanel.js 2009-05-15 05:46:02 UTC (rev 748)
+++ sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/LegendPanel.js 2009-05-15 08:45:58 UTC (rev 749)
@@ -73,8 +73,8 @@
/** private: method[onRender]
* Private method called when the legend panel is being rendered.
*/
- onRender: function(ct, position) {
- GeoExt.LegendPanel.superclass.onRender.call(this, ct, position);
+ onRender: function() {
+ GeoExt.LegendPanel.superclass.onRender.apply(this, arguments);
if(!this.layerStore) {
this.layerStore = GeoExt.MapPanel.guess().layers;
}
@@ -82,6 +82,7 @@
if (!this.static) {
this.layerStore.on({
"add": this.onStoreAdd,
+ "move": this.onStoreMove,
"remove": this.onStoreRemove,
scope: this
});
@@ -89,6 +90,40 @@
this.doLayout();
},
+ /** private: method[onStoreMove]
+ * Relocate a layer within the legend panel. Gets called when the store
+ * fires the move event.
+ *
+ * :param store: ``Ext.data.Store`` The store in which the record was
+ * moved.
+ * :param record: ``Ext.data.Record`` The record object(s) corresponding
+ * to the moved layer.
+ * :param from: ``Integer`` The previous index of the moved record.
+ * :param to: ``Integer`` The new index of the moved record.
+ */
+ onStoreMove: function(store, record, from, to) {
+ this.moveLegend(record, to);
+ },
+
+ /** private: method[moveLegend]
+ * Relocate a layer within the legend panel. Removes the existing panel
+ * and then inserts it at the right index.
+ *
+ * :param record: ``Ext.data.Record`` The record object(s) corresponding
+ * to the moved layer.
+ * :param index: ``Integer`` The new index of the moved record.
+ */
+ moveLegend: function(record, index) {
+ var legend = this.getComponent(record.get('layer').id);
+ legend = this.remove(legend);
+ if (this.ascending) {
+ this.insert(index, legend);
+ } else {
+ this.insert((this.items.length-index), legend);
+ }
+ this.doLayout();
+ },
+
/** private: method[onStoreAdd]
* Private method called when a layer is added to the store.
*
@@ -131,6 +166,32 @@
}
},
+ /** private: method[createLegendSubpanel]
+ * Create a legend sub panel for the layer.
+ *
+ * :param record: ``Ext.data.Record`` The record object from the layer
+ * store.
+ */
+ createLegendSubpanel: function(record) {
+ var layer = record.get('layer');
+ var mainPanel = this.createMainPanel(record);
+ // the default legend can be overridden by specifying a
+ // legendURL property
+ if (record.get('legendURL')) {
+ var legend = new GeoExt.legend.Image({url:
+ record.get('legendURL')});
+ mainPanel.add(legend);
+ } else {
+ var legendGenerator = GeoExt.legend[layer.CLASS_NAME.replace(
+ 'OpenLayers.Layer.', '')];
+ if (legendGenerator) {
+ var legend = new legendGenerator({layer: layer});
+ mainPanel.add(legend);
+ }
+ }
+ return mainPanel;
+ },
+
/** private: method[addLegend]
* Add a legend for the layer.
*
@@ -144,26 +205,11 @@
var hideInLegend = record.get('hideInLegend');
// only show visible layers
if (layer && layer.getVisibility() && !hideInLegend) {
- var mainPanel = this.createMainPanel(record);
- // the default legend can be overridden by specifying a
- // legendURL property
- if (record.get('legendURL')) {
- var legend = new GeoExt.legend.Image({url:
- record.get('legendURL')});
- mainPanel.add(legend);
- this.add(mainPanel);
- } else {
- var legendGenerator = GeoExt.legend[layer.CLASS_NAME.replace(
- 'OpenLayers.Layer.', '')];
- if (legendGenerator) {
- var legend = new legendGenerator({layer: layer});
- mainPanel.add(legend);
- }
- }
+ var legendSubpanel = this.createLegendSubpanel(record);
if (this.ascending) {
- this.add(mainPanel);
+ this.add(legendSubpanel);
} else {
- this.insert(0, mainPanel);
+ this.insert(0, legendSubpanel);
}
}
},
More information about the Commits
mailing list