[OpenLayers-Users] Canvas renderer causing fill in style map to be ignored

Rob Hyx robhyx at gmail.com
Mon Jul 30 10:17:00 PDT 2012


Hello all, I have a single vector layer with a style map associated
with it. Everything renders fine except for the fill color, but when I
comment out the canvas renderer it works. I set a break-point in the
'getFill' method and the attribute is set correctly. It's almost as if
OpenLayers is just ignoring it.

Code:

VECTOR_STYLE = new OpenLayers.Style({strokeColor: "\${getStroke}",
strokeWidth:  "\${getStrokeWidth}", strokeOpacity:
"\${getStrokeOpacity}",
        fillColor: "\${getFill}", fillOpacity: "\${getFillOpacity}",
graphicWidth: "\${getWidth}", graphicHeight: "\${getHeight}",
pointRadius: 10,
        externalGraphic: "\${getIcon}", label: "\${getLabel}"},
    	{context: {
            getStroke: function(feature) {
                if(feature.attributes.strokeColor != null) return
feature.attributes.strokeColor;
                return "black";
            },
            getStrokeWidth: function(feature) {
                if(feature.attributes.strokeWidth != null) return
feature.attributes.strokeWidth;
                return 2;
            },
            getStrokeOpacity: function(feature) {
                if(feature.attributes.strokeOpacity != null) return
parseFloat(feature.attributes.strokeOpacity);
                return parseFloat(1);
            },
            getFillOpacity: function(feature) {
                if(feature.attributes.fillOpacity != null) return
parseFloat(feature.attributes.fillOpacity);
                return parseFloat(1);
            },
            getFill: function(feature) {
                if(feature.attributes.fill != null) return
feature.attributes.fill;
                return "grey";
            },
            getWidth: function(feature) {
                if(feature.attributes.graphicWidth != null) return
Number(feature.attributes.graphicWidth);
                return Number(35);
            },
            getHeight: function(feature) {
                if(feature.attributes.graphicHeight != null) return
Number(feature.attributes.graphicHeight);
                return Number(35);
            },
            getIcon: function(feature) {
                if(feature.attributes.icon != null) return
feature.attributes.icon;
                return "img/default_icon.png";
            },
            getLabel: function(feature) {
                if(feature.attributes.label != null) return
feature.attributes.label;
                return "";
            }
        }
    });

		
var styleMap = new OpenLayers.StyleMap({
	"default": VECTOR_STYLE, "hidden" : {
		strokeColor: "black",
		strokeWidth:  0.0,
        	strokeOpacity:  0.0,
        	fillColor: "black",
        	fillOpacity: 0.0,
        	graphicWidth: 0.0,
        	graphicHeight: 0.0,
        	pointRadius: 0,
        	externalGraphic: ""
	}
});

var options = {};
		
options.styleMap = styleMap;
options.renderers = ["Canvas"]; // Comment out this line and it works.
		
vectorLayer = map.addVectorLayer({layerName: "asdf", alwaysOnTop:
true, options: options});

Has anyone encountered this? Thanks in advance!

-- 
HYX
http://hyx-music.com


More information about the Users mailing list