如何动态应用OpenLayers Stymbolizer上下文?
出于中详细说明的原因,我有一些样式代码如下所示:如何动态应用OpenLayers Stymbolizer上下文?,openlayers,Openlayers,出于中详细说明的原因,我有一些样式代码如下所示: myStyle.Events = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']); myStyle.Events.extendDefault = true; myStyle.Events.maxScaleDenominator = 200000000; myStyle.Events.graphicWidth = 36; myStyle.Events.gr
myStyle.Events = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
myStyle.Events.extendDefault = true;
myStyle.Events.maxScaleDenominator = 200000000;
myStyle.Events.graphicWidth = 36;
myStyle.Events.graphicHeight = 36;
myStyle.Events.graphicOpacity = 0.75;
myStyle.Events.externalGraphic = "/img/icons/${icon}.png";
myStyle.Events.label = "${count}";
myStyle.Events.labelOutlineWidth = 1;
myStyle.Events.labelOutlineColor = "#000";
myStyle.Events.fontColor = "#000";
myStyle.Events.fontOpacity = 8.0;
myStyle.Events.fontSize = "11px";
myStyle.Events.labelYOffset = 3;
myStyle.Events.context = {
icon: function(feature) {
var iconMap,
iconPath,
type = "single";
iconMap = {
...
}
if(feature.attributes.count) {
type = "clustered";
}
return iconMap[feature.attributes.name][type];
},
count: function(feature) {
var labelText = "";
if(feature.attributes.count) {
labelText = feature.attributes.count;
}
return labelText;
}
};
我怎样才能像那样在飞行中正确地应用该上下文?我不能使用典型的OpenLayers.Style({},{context:context});语法。必须将
上下文
属性应用于OpenLayers.Style
实例,如下所示:
var style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style["default"]);
style.pointRadius = "${radius}";
style.fillColor = '${colorFunction}';
var defaultStyle = new OpenLayers.Style(style, {
context: {
colorFunction: function(feature) {
return colors[feature.attributes.temp];
}
}
});
我建议您使用(主题7样式)或查看源代码示例(第7章-使用样式图和功能的属性替换改进样式)
干杯