[Commits] r676 - in sandbox/bartvde/legend/geoext: examples lib lib/GeoExt/widgets lib/GeoExt/widgets/legend lib/GeoExt/widgets/tree
commits at geoext.org
commits at geoext.org
Mon May 11 11:24:03 CEST 2009
Author: bartvde
Date: 2009-05-11 11:24:03 +0200 (Mon, 11 May 2009)
New Revision: 676
Added:
sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/FeatureRenderer.js
sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend/Vector.js
Modified:
sandbox/bartvde/legend/geoext/examples/legendpanel.js
sandbox/bartvde/legend/geoext/lib/GeoExt.js
sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/LegendPanel.js
sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend/WMS.js
sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/tree/LayerNode.js
Log:
more experimental legend changes, include vector legend
Modified: sandbox/bartvde/legend/geoext/examples/legendpanel.js
===================================================================
--- sandbox/bartvde/legend/geoext/examples/legendpanel.js 2009-05-11 08:57:58 UTC (rev 675)
+++ sandbox/bartvde/legend/geoext/examples/legendpanel.js 2009-05-11 09:24:03 UTC (rev 676)
@@ -18,7 +18,8 @@
"Cities and Roads",
"http://publicus.opengeo.org/geoserver/wms?",
{layers: 'topp:tasmania_cities,topp:tasmania_roads', format: 'image/png', transparent: true},
- {singleTile: true})
+ {singleTile: true}),
+ new OpenLayers.Layer.Vector("Vector")
]);
mapPanel = new GeoExt.MapPanel({
Added: sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/FeatureRenderer.js
===================================================================
--- sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/FeatureRenderer.js (rev 0)
+++ sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/FeatureRenderer.js 2009-05-11 09:24:03 UTC (rev 676)
@@ -0,0 +1,310 @@
+/**
+ * Copyright (c) 2008 The Open Planning Project
+ */
+
+Ext.namespace("GeoExt");
+
+GeoExt.FeatureRenderer = Ext.extend(Ext.BoxComponent, {
+
+ /**
+ * Property: feature
+ * {OpenLayers.Feature.Vector} Optional vector to be drawn. If a feature
+ * is not provided, <symbolType> should be specified.
+ */
+ feature: undefined,
+
+ /**
+ * Property: symbolizer
+ * {Object} If no symbolizer is provided, the OpenLayers default will be
+ * used.
+ */
+ symbolizer: OpenLayers.Feature.Vector.style["default"],
+
+ /**
+ * Property: symbolType
+ * {String} One of "Point", "Line", or "Polygon". If <feature> is
+ * provided, it will be preferred. Default is "Point".
+ */
+ symbolType: "Point",
+
+ /**
+ * Property: resolution
+ */
+ resolution: 1,
+
+ /**
+ * Property: minWidth
+ */
+ minWidth: 20,
+
+ /**
+ * Property: minHeight
+ */
+ minHeight: 20,
+
+ /**
+ * Property: renderers
+ * {Array(String)} List of supported Renderer classes. Add to this list to
+ * add support for additional renderers. This list is ordered:
+ * the first renderer which returns true for the 'supported()'
+ * method will be used, if not defined in the 'renderer' option.
+ */
+ renderers: ['SVG', 'VML', 'Canvas'],
+
+ /**
+ * Property: rendererOptions
+ * {Object} Options for the renderer. See {OpenLayers.Renderer} for
+ * supported options.
+ */
+ rendererOptions: null,
+
+ /**
+ * Property: pointFeature
+ * {OpenLayers.Feature.Vector} Feature with point geometry.
+ */
+ pointFeature: undefined,
+
+ /**
+ * Property: lineFeature
+ * {OpenLayers.Feature.Vector} Feature with LineString geometry. Default
+ * zig-zag is provided.
+ */
+ lineFeature: undefined,
+
+ /**
+ * Property: polygonFeature
+ * {OpenLayers.Feature.Vector} Feature with Polygon geometry. Default is
+ * a soft cornered rectangle.
+ */
+ polygonFeature: undefined,
+
+ /**
+ * Property: renderer
+ * {OpenLayers.Renderer}
+ */
+ renderer: null,
+
+ initComponent: function() {
+ GeoExt.FeatureRenderer.superclass.initComponent.call(this);
+ Ext.applyIf(this, {
+ pointFeature: new OpenLayers.Feature.Vector(
+ new OpenLayers.Geometry.Point(0, 0)
+ ),
+ lineFeature: new OpenLayers.Feature.Vector(
+ new OpenLayers.Geometry.LineString([
+ new OpenLayers.Geometry.Point(-8, -3),
+ new OpenLayers.Geometry.Point(-3, 3),
+ new OpenLayers.Geometry.Point(3, -3),
+ new OpenLayers.Geometry.Point(8, 3)
+ ])
+ ),
+ polygonFeature: new OpenLayers.Feature.Vector(
+ new OpenLayers.Geometry.Polygon([
+ new OpenLayers.Geometry.LinearRing([
+ new OpenLayers.Geometry.Point(-8, -4),
+ new OpenLayers.Geometry.Point(-6, -6),
+ new OpenLayers.Geometry.Point(6, -6),
+ new OpenLayers.Geometry.Point(8, -4),
+ new OpenLayers.Geometry.Point(8, 4),
+ new OpenLayers.Geometry.Point(6, 6),
+ new OpenLayers.Geometry.Point(-6, 6),
+ new OpenLayers.Geometry.Point(-8, 4)
+ ])
+ ])
+ )
+ });
+ if(!this.feature) {
+ this.setFeature(null, {draw: false});
+ }
+ this.addEvents(
+ /**
+ * Event: click
+ * Fires when the feature is clicked on.
+ *
+ * Listener arguments:
+ * renderer - {GeoExt.FeatureRenderer} This feature renderer.
+ */
+ "click"
+ );
+ },
+
+ // private
+ initClickEvents: function() {
+ this.el.removeAllListeners();
+ this.el.on("click", this.onClick, this);
+ },
+
+ onClick: function() {
+ this.fireEvent("click", this);
+ },
+
+ onRender: function(ct, position) {
+ if(!this.el) {
+ this.el = document.createElement("div");
+ this.el.id = this.getId();
+ }
+ if(!this.renderer || !this.renderer.supported()) {
+ this.assignRenderer();
+ }
+ // monkey-patch renderer so we always get a resolution
+ this.renderer.map = {
+ getResolution: (function() {
+ return this.resolution;
+ }).createDelegate(this)
+ };
+
+ this.drawFeature();
+ GeoExt.FeatureRenderer.superclass.onRender.call(this, ct, position);
+ },
+
+ afterRender: function() {
+ GeoExt.FeatureRenderer.superclass.afterRender.call(this);
+ this.initClickEvents();
+ },
+
+ onResize: function(w, h) {
+ this.setRendererDimensions();
+ GeoExt.FeatureRenderer.superclass.onResize.call(this, w, h);
+ },
+
+ setRendererDimensions: function() {
+ var gb = this.feature.geometry.getBounds();
+ var gw = gb.getWidth();
+ var gh = gb.getHeight();
+ /**
+ * Determine resolution based on the following rules:
+ * 1) always use value specified in config
+ * 2) if not specified, use max res based on width or height of element
+ * 3) if no width or height, assume a resolution of 1
+ */
+ var resolution = this.initialConfig.resolution;
+ if(!resolution) {
+ resolution = Math.max(gw / this.width || 0, gh / this.height || 0) || 1;
+ }
+ this.resolution = resolution;
+ // determine height and width of element
+ var width = Math.max(this.width || this.minWidth, gw / resolution);
+ var height = Math.max(this.height || this.minHeight, gh / resolution);
+ // determine bounds of renderer
+ var center = gb.getCenterPixel();
+ var bhalfw = width * resolution / 2;
+ var bhalfh = height * resolution / 2;
+ var bounds = new OpenLayers.Bounds(
+ center.x - bhalfw, center.y - bhalfh,
+ center.x + bhalfw, center.y + bhalfh
+ );
+ this.renderer.setSize(new OpenLayers.Size(Math.round(width), Math.round(height)));
+ this.renderer.setExtent(bounds, true);
+ },
+
+ /**
+ * Method: assignRenderer
+ * Iterates through the available renderer implementations and selects
+ * and assigns the first one whose "supported()" function returns true.
+ */
+ assignRenderer: function() {
+ for(var i=0, len=this.renderers.length; i<len; ++i) {
+ var rendererClass = OpenLayers.Renderer[this.renderers[i]];
+ if(rendererClass && rendererClass.prototype.supported()) {
+ this.renderer = new rendererClass(
+ this.el, this.rendererOptions
+ );
+ break;
+ }
+ }
+ },
+
+ /**
+ * APIMethod: setSymbolizer
+ * Update the symbolizer used to render the feature.
+ *
+ * Parameters:
+ * symbolizer - {Object} A symbolizer object.
+ * options - {Object}
+ *
+ * Valid options:
+ * draw - {Boolean} Draw the feature after setting it. Default is true.
+ */
+ setSymbolizer: function(symbolizer, options) {
+ this.symbolizer = symbolizer;
+ if(!options || options.draw) {
+ this.drawFeature();
+ }
+ },
+
+ /**
+ * APIMethod: setGeometryType
+ * Create a new feature based on the geometry type and render it.
+ *
+ * Paramters:
+ * type - {String} One of the FeatureRenderer constants.
+ * options - {Object}
+ *
+ * Valid options:
+ * draw - {Boolean} Draw the feature after setting it. Default is true.
+ */
+ setGeometryType: function(type, options) {
+ this.symbolType = type;
+ this.setFeature(null, options);
+ },
+
+ /**
+ * APIMethod: setFeature
+ * Update the feature and redraw.
+ *
+ * Parameters:
+ * feature - {OpenLayers.Feature.Vector} The feature to be rendered. If
+ * none is provided, one will be created based on <symbolType>.
+ * options - {Object}
+ *
+ * Valid options:
+ * draw - {Boolean} Draw the feature after setting it. Default is true.
+ */
+ setFeature: function(feature, options) {
+ this.feature = feature || this[this.symbolType.toLowerCase() + "Feature"];
+ if(!options || options.draw) {
+ this.drawFeature();
+ }
+ },
+
+ /**
+ * Method: drawFeature
+ * Render the feature with the symbolizer.
+ */
+ drawFeature: function() {
+ this.renderer.clear();
+ this.setRendererDimensions();
+ this.renderer.drawFeature(this.feature,
+ Ext.apply({}, this.symbolizer));
+ },
+
+ /**
+ * Method: update
+ * Update the <symbolType> or <feature> and <symbolizer>.
+ *
+ * Parameters:
+ * options - {Object} Object with properties to be updated. Without options
+ * <drawFeature> will still be called.
+ *
+ * Valid options:
+ * feature - {OpenLayers.Feature.Vector} The new or updated feature. If
+ * provided, the feature gets precedence over symbolType.
+ * symbolType - {String} One of the allowed <symbolType> values.
+ * symbolizer - {Object} A symbolizer object.
+ */
+ update: function(options) {
+ options = options || {};
+ if(options.feature) {
+ this.setFeature(options.feature, {draw: false});
+ } else if(options.symbolType) {
+ this.setGeometryType(options.symbolType, {draw: false});
+ }
+ if(options.symbolizer) {
+ this.setSymbolizer(options.symbolizer, {draw: false});
+ }
+ this.drawFeature();
+ }
+
+});
+
+Ext.reg('gx_renderer', GeoExt.FeatureRenderer);
Modified: sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/LegendPanel.js
===================================================================
--- sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/LegendPanel.js 2009-05-11 08:57:58 UTC (rev 675)
+++ sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/LegendPanel.js 2009-05-11 09:24:03 UTC (rev 676)
@@ -1,5 +1,20 @@
-Ext.namespace('GeoExt');
+Ext.namespace('GeoExt', 'GeoExt.legend');
+GeoExt.legend.generateLegendImage = function(options) {
+ if (options.layer instanceof OpenLayers.Layer.WMS) {
+ return options.layer.getFullRequestString({
+ REQUEST: "GetLegendGraphic",
+ WIDTH: options.width,
+ HEIGHT: options.height,
+ EXCEPTIONS: "application/vnd.ogc.se_xml",
+ LAYER: options.layer.params.LAYERS,
+ LAYERS: null,
+ SRS: null,
+ FORMAT: 'image/png'
+ });
+ }
+};
+
GeoExt.LegendPanel = Ext.extend(Ext.Panel, {
/**
@@ -27,12 +42,35 @@
// use the right legend generator for this layer type
var legendGenerator = GeoExt.legend[layer.CLASS_NAME.replace(
'OpenLayers.Layer.', '')];
+
+ var mainPanel = this.createTitlePanel(layer, layer.name);
var legend = new legendGenerator({layer: layer});
- this.add(legend);
+ mainPanel.add(legend);
+ this.add(mainPanel);
}, this);
this.doLayout();
+ },
+
+ createTitlePanel: function(layer, title) {
+ var panelConfig = {
+ id: layer.id,
+ border: false,
+ bodyBorder: false,
+ bodyStyle: this.bodyStyle,
+ items: [
+ new Ext.form.Label({
+ text: title,
+ cls: 'x-form-item x-form-item-label' +
+ (this.labelCls ? ' ' + this.labelCls : '')
+ })
+ ]
+ };
+
+ panelConfig = Ext.applyIf(panelConfig, this.childDefaults);
+
+ var panel = new Ext.Panel(panelConfig);
+ return panel;
}
-
});
Ext.reg('gx_legend', GeoExt.LegendPanel);
Added: sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend/Vector.js
===================================================================
--- sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend/Vector.js (rev 0)
+++ sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend/Vector.js 2009-05-11 09:24:03 UTC (rev 676)
@@ -0,0 +1,7 @@
+Ext.namespace('GeoExt', 'GeoExt.legend');
+
+GeoExt.legend.Vector = function(config) {
+ return new GeoExt.FeatureRenderer({
+ symbolizer: config.layer.styleMap.styles.default.defaultStyle
+ });
+};
Modified: sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend/WMS.js
===================================================================
--- sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend/WMS.js 2009-05-11 08:57:58 UTC (rev 675)
+++ sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/legend/WMS.js 2009-05-11 09:24:03 UTC (rev 676)
@@ -134,7 +134,9 @@
// TODO: we probably need the ability to change the css class
// of the label
var panelConfig = {
- id: id,
+ border: false,
+ bodyBorder: false,
+ id: id/*,
bodyStyle: this.bodyStyle,
items: [
new Ext.form.Label({
@@ -142,7 +144,7 @@
cls: 'x-form-item x-form-item-label' +
(this.labelCls ? ' ' + this.labelCls : '')
})
- ]
+ ]*/
};
panelConfig = Ext.applyIf(panelConfig, this.childDefaults);
Modified: sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/tree/LayerNode.js
===================================================================
--- sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/tree/LayerNode.js 2009-05-11 08:57:58 UTC (rev 675)
+++ sandbox/bartvde/legend/geoext/lib/GeoExt/widgets/tree/LayerNode.js 2009-05-11 09:24:03 UTC (rev 676)
@@ -161,7 +161,9 @@
// checked status will be set by layer event, so setting it to false
// to always get the checkbox rendered
config.checked = false;
-
+
+ config.icon = GeoExt.legend.generateLegendImage({layer: config.layer, height: 18, width: 16});
+
this.defaultUI = this.defaultUI || GeoExt.tree.LayerNodeUI;
this.addEvents(
/**
@@ -177,6 +179,7 @@
layerStore: config.layerStore,
childNodeType: config.childNodeType
});
+
GeoExt.tree.LayerNode.superclass.constructor.apply(this, arguments);
},
Modified: sandbox/bartvde/legend/geoext/lib/GeoExt.js
===================================================================
--- sandbox/bartvde/legend/geoext/lib/GeoExt.js 2009-05-11 08:57:58 UTC (rev 675)
+++ sandbox/bartvde/legend/geoext/lib/GeoExt.js 2009-05-11 09:24:03 UTC (rev 676)
@@ -68,6 +68,8 @@
"GeoExt/data/WMSCapabilitiesReader.js",
"GeoExt/data/WMSCapabilitiesStore.js",
"GeoExt/data/ProtocolProxy.js",
+ "GeoExt/widgets/FeatureRenderer.js",
+ "GeoExt/widgets/legend/Vector.js",
"GeoExt/widgets/legend/WMS.js",
"GeoExt/widgets/LegendPanel.js",
"GeoExt/widgets/MapPanel.js",
More information about the Commits
mailing list