* added stroke, fill and graphic symbolizer properties (all boolean) to

control whether or not to render a stroke, fill and graphic.
 * added a defaultsPerSymbolizer property to OpenLayers.Style to allow 
for extending incomplete symbolizers with defaults for stroke, fill or 
graphic. This also makes Format.SLD read/write round trips possible 
without modifying empty or incomplete <Stroke/>, <Fill/> and <Graphic/> 
constructs. r=tschaub (closes #1876)


git-svn-id: http://svn.openlayers.org/trunk/openlayers@9278 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2009-04-13 13:35:13 +00:00
parent 13e42ec59b
commit 2aa7f22926
7 changed files with 327 additions and 45 deletions

View File

@@ -64,10 +64,21 @@ OpenLayers.Style = OpenLayers.Class({
* Property: defaultStyle
* {Object} hash of style properties to use as default for merging
* rule-based style symbolizers onto. If no rules are defined,
* createSymbolizer will return this style.
* createSymbolizer will return this style. If <defaultsPerSymbolizer> is set to
* true, the defaultStyle will only be taken into account if there are
* rules defined.
*/
defaultStyle: null,
/**
* Property: defaultsPerSymbolizer
* {Boolean} If set to true, the <defaultStyle> will extend the symbolizer
* of every rule. Properties of the <defaultStyle> will also be used to set
* missing symbolizer properties if the symbolizer has stroke, fill or
* graphic set to true. Default is false.
*/
defaultsPerSymbolizer: false,
/**
* Property: propertyStyles
* {Hash of Boolean} cache of style properties that need to be parsed for
@@ -135,7 +146,7 @@ OpenLayers.Style = OpenLayers.Class({
* {Object} symbolizer hash
*/
createSymbolizer: function(feature) {
var style = this.createLiterals(
var style = this.defaultsPerSymbolizer ? {} : this.createLiterals(
OpenLayers.Util.extend({}, this.defaultStyle), feature);
var rules = this.rules;
@@ -191,6 +202,40 @@ OpenLayers.Style = OpenLayers.Class({
OpenLayers.Style.SYMBOLIZER_PREFIXES[0];
var symbolizer = rule.symbolizer[symbolizerPrefix] || rule.symbolizer;
if(this.defaultsPerSymbolizer === true) {
var defaults = this.defaultStyle;
OpenLayers.Util.applyDefaults(symbolizer, {
pointRadius: defaults.pointRadius
})
if(symbolizer.stroke === true || symbolizer.graphic === true) {
OpenLayers.Util.applyDefaults(symbolizer, {
strokeWidth: defaults.strokeWidth,
strokeColor: defaults.strokeColor,
strokeOpacity: defaults.strokeOpacity,
strokeDashstyle: defaults.strokeDashstyle,
strokeLinecap: defaults.strokeLinecap
});
}
if(symbolizer.fill === true || symbolizer.graphic === true) {
OpenLayers.Util.applyDefaults(symbolizer, {
fillColor: defaults.fillColor,
fillOpacity: defaults.fillOpacity
});
}
if(symbolizer.graphic === true) {
OpenLayers.Util.applyDefaults(symbolizer, {
pointRadius: this.defaultStyle.pointRadius,
externalGraphic: this.defaultStyle.externalGraphic,
graphicName: this.defaultStyle.graphicName,
graphicOpacity: this.defaultStyle.graphicOpacity,
graphicWidth: this.defaultStyle.graphicWidth,
graphicHeight: this.defaultStyle.graphicHeight,
graphicXOffset: this.defaultStyle.graphicXOffset,
graphicYOffset: this.defaultStyle.graphicYOffset
});
}
}
// merge the style with the current style
return this.createLiterals(