* Remove default styling from the Feature.Vector class.

* Add a 'style' property to the layer.
 * When a feature is added to a layer, either uses the style on the 
   layer, or uses the default feature style.
 * Add test to Layer.Vector for this funcionality 
 * Adds a preFeatureInsert hook to change a feature *before* 
   drawing it.
 * Change openmnnd demo to include the use of preFeatureInsert
   and style attribute on layer.


git-svn-id: http://svn.openlayers.org/trunk/openlayers@2949 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2007-04-01 12:08:13 +00:00
parent adee1fb217
commit 53977cf840
4 changed files with 68 additions and 6 deletions

View File

@@ -36,6 +36,9 @@ OpenLayers.Layer.Vector.prototype =
/** @type {Boolean} */
reportError: true,
/** @type {Object} */
style: null,
/**
* List of supported Renderer classes. Add to this list to
* add support for additional renderers. This list is ordered:
@@ -224,6 +227,16 @@ OpenLayers.Layer.Vector.prototype =
//give feature reference to its layer
feature.layer = this;
if (!feature.style) {
if (this.style) {
feature.style = OpenLayers.Util.extend({}, this.style);
} else {
feature.style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
}
}
this.preFeatureInsert(feature);
if (this.drawn) {
this.renderer.drawGeometry(feature.geometry, feature.style);
}
@@ -315,6 +328,17 @@ OpenLayers.Layer.Vector.prototype =
*/
onFeatureInsert: function(feature) {
},
/**
* method called before a feature is inserted.
* Does nothing by default. Override this if you
* need to do something when features are first added to the
* layer, but before they are drawn, such as adjust the style.
*
* @param {OpenLayers.Feature.Vector} feature
*/
preFeatureInsert: function(feature) {
},
/** @final @type String */
CLASS_NAME: "OpenLayers.Layer.Vector"