* 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

@@ -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");