* 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:
@@ -137,7 +137,7 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
|
||||
);
|
||||
},
|
||||
"UserStyle": function(node, layer) {
|
||||
var obj = {rules: []};
|
||||
var obj = {defaultsPerSymbolizer: true, rules: []};
|
||||
this.readChildNodes(node, obj);
|
||||
var style = new OpenLayers.Style(this.defaultSymbolizer, obj);
|
||||
layer.userStyles.push(style);
|
||||
@@ -232,9 +232,11 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
|
||||
rule.symbolizer["Point"] = symbolizer;
|
||||
},
|
||||
"Stroke": function(node, symbolizer) {
|
||||
symbolizer.stroke = true;
|
||||
this.readChildNodes(node, symbolizer);
|
||||
},
|
||||
"Fill": function(node, symbolizer) {
|
||||
symbolizer.fill = true;
|
||||
this.readChildNodes(node, symbolizer);
|
||||
},
|
||||
"CssParameter": function(node, symbolizer) {
|
||||
@@ -250,6 +252,7 @@ OpenLayers.Format.SLD.v1 = OpenLayers.Class(OpenLayers.Format.Filter.v1_0_0, {
|
||||
}
|
||||
},
|
||||
"Graphic": function(node, symbolizer) {
|
||||
symbolizer.graphic = true;
|
||||
var graphic = {};
|
||||
// painter's order not respected here, clobber previous with next
|
||||
this.readChildNodes(node, graphic);
|
||||
|
||||
@@ -244,21 +244,27 @@ OpenLayers.Renderer.Canvas = OpenLayers.Class(OpenLayers.Renderer, {
|
||||
* style - {Object}
|
||||
*/
|
||||
drawPoint: function(geometry, style) {
|
||||
var pt = this.getLocalXY(geometry);
|
||||
|
||||
if (style.externalGraphic) {
|
||||
this.drawExternalGraphic(pt, style);
|
||||
} else {
|
||||
this.setCanvasStyle("fill", style);
|
||||
this.canvas.beginPath();
|
||||
this.canvas.arc(pt[0], pt[1], 6, 0, Math.PI*2, true);
|
||||
this.canvas.fill();
|
||||
if(style.graphic !== false) {
|
||||
var pt = this.getLocalXY(geometry);
|
||||
|
||||
this.setCanvasStyle("stroke", style);
|
||||
this.canvas.beginPath();
|
||||
this.canvas.arc(pt[0], pt[1], 6, 0, Math.PI*2, true);
|
||||
this.canvas.stroke();
|
||||
this.setCanvasStyle("reset");
|
||||
if (style.externalGraphic) {
|
||||
this.drawExternalGraphic(pt, style);
|
||||
} else {
|
||||
if(style.fill !== false) {
|
||||
this.setCanvasStyle("fill", style);
|
||||
this.canvas.beginPath();
|
||||
this.canvas.arc(pt[0], pt[1], 6, 0, Math.PI*2, true);
|
||||
this.canvas.fill();
|
||||
}
|
||||
|
||||
if(style.stroke !== false) {
|
||||
this.setCanvasStyle("stroke", style);
|
||||
this.canvas.beginPath();
|
||||
this.canvas.arc(pt[0], pt[1], 6, 0, Math.PI*2, true);
|
||||
this.canvas.stroke();
|
||||
this.setCanvasStyle("reset");
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -271,15 +277,17 @@ OpenLayers.Renderer.Canvas = OpenLayers.Class(OpenLayers.Renderer, {
|
||||
* style - {Object}
|
||||
*/
|
||||
drawLineString: function(geometry, style) {
|
||||
this.setCanvasStyle("stroke", style);
|
||||
this.canvas.beginPath();
|
||||
var start = this.getLocalXY(geometry.components[0]);
|
||||
this.canvas.moveTo(start[0], start[1]);
|
||||
for(var i = 1; i < geometry.components.length; i++) {
|
||||
var pt = this.getLocalXY(geometry.components[i]);
|
||||
this.canvas.lineTo(pt[0], pt[1]);
|
||||
if(style.stroke !== false) {
|
||||
this.setCanvasStyle("stroke", style);
|
||||
this.canvas.beginPath();
|
||||
var start = this.getLocalXY(geometry.components[0]);
|
||||
this.canvas.moveTo(start[0], start[1]);
|
||||
for(var i = 1; i < geometry.components.length; i++) {
|
||||
var pt = this.getLocalXY(geometry.components[i]);
|
||||
this.canvas.lineTo(pt[0], pt[1]);
|
||||
}
|
||||
this.canvas.stroke();
|
||||
}
|
||||
this.canvas.stroke();
|
||||
this.setCanvasStyle("reset");
|
||||
},
|
||||
|
||||
@@ -292,26 +300,30 @@ OpenLayers.Renderer.Canvas = OpenLayers.Class(OpenLayers.Renderer, {
|
||||
* style - {Object}
|
||||
*/
|
||||
drawLinearRing: function(geometry, style) {
|
||||
this.setCanvasStyle("fill", style);
|
||||
this.canvas.beginPath();
|
||||
var start = this.getLocalXY(geometry.components[0]);
|
||||
this.canvas.moveTo(start[0], start[1]);
|
||||
for(var i = 1; i < geometry.components.length - 1 ; i++) {
|
||||
var pt = this.getLocalXY(geometry.components[i]);
|
||||
this.canvas.lineTo(pt[0], pt[1]);
|
||||
if(style.fill !== false) {
|
||||
this.setCanvasStyle("fill", style);
|
||||
this.canvas.beginPath();
|
||||
var start = this.getLocalXY(geometry.components[0]);
|
||||
this.canvas.moveTo(start[0], start[1]);
|
||||
for(var i = 1; i < geometry.components.length - 1 ; i++) {
|
||||
var pt = this.getLocalXY(geometry.components[i]);
|
||||
this.canvas.lineTo(pt[0], pt[1]);
|
||||
}
|
||||
this.canvas.fill();
|
||||
}
|
||||
this.canvas.fill();
|
||||
|
||||
var oldWidth = this.canvas.lineWidth;
|
||||
this.setCanvasStyle("stroke", style);
|
||||
this.canvas.beginPath();
|
||||
var start = this.getLocalXY(geometry.components[0]);
|
||||
this.canvas.moveTo(start[0], start[1]);
|
||||
for(var i = 1; i < geometry.components.length; i++) {
|
||||
var pt = this.getLocalXY(geometry.components[i]);
|
||||
this.canvas.lineTo(pt[0], pt[1]);
|
||||
if(style.stroke !== false) {
|
||||
var oldWidth = this.canvas.lineWidth;
|
||||
this.setCanvasStyle("stroke", style);
|
||||
this.canvas.beginPath();
|
||||
var start = this.getLocalXY(geometry.components[0]);
|
||||
this.canvas.moveTo(start[0], start[1]);
|
||||
for(var i = 1; i < geometry.components.length; i++) {
|
||||
var pt = this.getLocalXY(geometry.components[i]);
|
||||
this.canvas.lineTo(pt[0], pt[1]);
|
||||
}
|
||||
this.canvas.stroke();
|
||||
}
|
||||
this.canvas.stroke();
|
||||
this.setCanvasStyle("reset");
|
||||
},
|
||||
|
||||
@@ -345,6 +357,10 @@ OpenLayers.Renderer.Canvas = OpenLayers.Class(OpenLayers.Renderer, {
|
||||
* style - {Object}
|
||||
*/
|
||||
drawText: function(location, style) {
|
||||
style = OpenLayers.Util.extend({
|
||||
fontColor: "#000000",
|
||||
labelAlign: "cm"
|
||||
}, style);
|
||||
var pt = this.getLocalXY(location);
|
||||
|
||||
this.setCanvasStyle("reset");
|
||||
|
||||
@@ -661,12 +661,20 @@ OpenLayers.Renderer.Elements = OpenLayers.Class(OpenLayers.Renderer, {
|
||||
OpenLayers.Util.applyDefaults(style, this.minimumSymbolizer);
|
||||
|
||||
var options = {
|
||||
'isFilled': true,
|
||||
'isStroked': !!style.strokeWidth
|
||||
'isFilled': style.fill === undefined ?
|
||||
true :
|
||||
style.fill,
|
||||
'isStroked': style.stroke === undefined ?
|
||||
!!style.strokeWidth :
|
||||
style.stroke
|
||||
};
|
||||
var drawn;
|
||||
switch (geometry.CLASS_NAME) {
|
||||
case "OpenLayers.Geometry.Point":
|
||||
if(style.graphic === false) {
|
||||
options.isFilled = false;
|
||||
options.isStroked = false;
|
||||
}
|
||||
drawn = this.drawPoint(node, geometry);
|
||||
break;
|
||||
case "OpenLayers.Geometry.LineString":
|
||||
|
||||
@@ -254,7 +254,10 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, {
|
||||
var widthFactor = 1;
|
||||
var pos;
|
||||
if (node._geometryClass == "OpenLayers.Geometry.Point" && r) {
|
||||
if (style.externalGraphic) {
|
||||
node.style.visibility = "";
|
||||
if (style.graphic === false) {
|
||||
node.style.visibility = "hidden";
|
||||
} else if (style.externalGraphic) {
|
||||
pos = this.getPosition(node);
|
||||
|
||||
if (style.graphicTitle) {
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user