[fusion-commits] r2432 - in trunk: text widgets
svn_fusion at osgeo.org
svn_fusion at osgeo.org
Tue Oct 4 07:17:44 EDT 2011
Author: jng
Date: 2011-10-04 04:17:44 -0700 (Tue, 04 Oct 2011)
New Revision: 2432
Modified:
trunk/text/en.json
trunk/text/fr.json
trunk/widgets/Legend.js
Log:
#460: More legend performance enhancements from my github fork. If a given scale range has the theme compression flag set (isCompressed = true), then we only add a placeholder node to the theme node, bookended by the first and last style rule nodes. The placeholder node includes a context menu action to expand the theme node to include all the style rules in the scale range. The action includes a confirmation prompt, because we wouldn't want to load a several-hundred rule theme by accident (arguments aside about why you would have a themed layer with several-hundred styles in the first place!)
Modified: trunk/text/en.json
===================================================================
--- trunk/text/en.json 2011-09-26 16:17:34 UTC (rev 2431)
+++ trunk/text/en.json 2011-10-04 11:17:44 UTC (rev 2432)
@@ -32,6 +32,9 @@
'refresh': 'Refresh',
'expandAll': 'Expand All',
'expand': 'Expand',
+'expandTheme': 'Expand Theme',
+'otherThemeItems': '... (${count} other styles)',
+'expandCompressedThemeConfirmation': 'Expand this theme?',
'collapseAll': 'Collapse All',
'collapse': 'Collapse',
'defaultMapTitle': 'Map',
Modified: trunk/text/fr.json
===================================================================
--- trunk/text/fr.json 2011-09-26 16:17:34 UTC (rev 2431)
+++ trunk/text/fr.json 2011-10-04 11:17:44 UTC (rev 2432)
@@ -30,6 +30,9 @@
'refresh': 'Refresh',
'expandAll': 'Expand All',
'expand': 'Expand',
+'expandTheme': 'Expand Theme',
+'otherThemeItems': '... (${count} other styles)',
+'expandCompressedThemeConfirmation': 'Expand this theme?',
'collapseAll': 'Collapse All',
'collapse': 'Collapse',
'defaultMapTitle': 'Map',
Modified: trunk/widgets/Legend.js
===================================================================
--- trunk/widgets/Legend.js 2011-09-26 16:17:34 UTC (rev 2431)
+++ trunk/widgets/Legend.js 2011-10-04 11:17:44 UTC (rev 2432)
@@ -581,9 +581,26 @@
} else {
layer.legend.treeItem.empty();
}
- for (var i=0; i<range.styles.length; i++) {
- var item = this.createTreeItem(layer, range.styles[i], fScale, false);
- layer.legend.treeItem.add(item);
+ //This style range has the compression flag set. This would have been set server-side
+ //if it contains more than a pre-defined number of style rules (see LoadScaleRanges.php for
+ //more information)
+ if (range.isCompressed) {
+ //Attach required data for theme expansion later on
+ layer.legend.treeItem.layer = layer;
+ layer.legend.treeItem.range = range;
+ layer.legend.treeItem.scale = fScale;
+ layer.legend.treeItem.hasDecompressedTheme = false;
+ //console.assert(range.styles.length > 2);
+ layer.legend.treeItem.add(this.createTreeItem(layer, range.styles[0], fScale, false));
+ layer.legend.treeItem.add(this.createThemeCompressionItem(range.styles.length - 2, layer.legend.treeItem));
+ layer.legend.treeItem.add(this.createTreeItem(layer, range.styles[range.styles.length-1], fScale, false));
+ } else {
+ //FIXME: JxLib really needs an API to add these in a single batch that doesn't hammer
+ //the DOM (if it's even possible)
+ for (var i=0; i<range.styles.length; i++) {
+ var item = this.createTreeItem(layer, range.styles[i], fScale, false);
+ layer.legend.treeItem.add(item);
+ }
}
/* if there is only one style, we represent it as a tree item */
} else {
@@ -634,7 +651,39 @@
layer.legend.treeItem.check(layer.visible);
}
},
-
+ getThemeExpandContextMenu: function(node) {
+ return new Jx.Menu.Context(this.name).add([
+ new Jx.Menu.Item({
+ label: OpenLayers.i18n('expandTheme'),
+ onClick: OpenLayers.Function.bind(function() { this.expandTheme(node); }, this)
+ })]
+ );
+ },
+ expandTheme: function(node) {
+ if (node.hasDecompressedTheme !== true && confirm(OpenLayers.i18n('expandCompressedThemeConfirmation'))) {
+ var range = node.range;
+ var layer = node.layer;
+ var fScale = node.scale;
+ node.empty();
+ //FIXME: JxLib really needs an API to add these in a single batch that doesn't hammer
+ //the DOM (if it's even possible)
+ for (var i = 0; i < range.styles.length; i++) {
+ var item = this.createTreeItem(layer, range.styles[i], fScale, false);
+ node.add(item);
+ }
+ node.hasDecompressedTheme = true;
+ }
+ },
+ createThemeCompressionItem: function(number, node) {
+ var opt = {
+ label: OpenLayers.i18n('otherThemeItems', { count: number }),
+ draw: this.renderItem,
+ contextMenu: this.getThemeExpandContextMenu(node),
+ image: this.imgBlankIcon
+ };
+ var item = new Jx.TreeItem(opt);
+ return item;
+ },
createFolderItem: function(layer) {
var opt = {
label: layer.legendLabel == '' ? ' ' : layer.legendLabel,
More information about the fusion-commits
mailing list