you create 2 styles, one standard, one temp , which is what you typically use when the feature is hovered, then you apply rules, that is the magic.
var halte_temp_styled = new OpenLayers.Style({
fillColor: "red",
fontColor: "#000000",
fontWeight: "normal",
pointRadius: 8,
fontSize: "11px",
strokeColor: "#ff9933",
strokeWidth: 2,
pointerEvents: "all",
fillOpacity: 0.3,
label : "${name}",
labelOutlineColor: "white",
labelAlign: "rb",
labelOutlineWidth: 8,
cursor: "pointer",
fontFamily: "sans-serif"
});
var halte_styled = new OpenLayers.Style({
fillColor: "red",
fillOpacity: 0.6,
fontColor: "#000000",
fontWeight: "light",
pointRadius: 8,
fontSize: "11px",
strokeColor: "#ff9963",
strokeWidth: 3,
pointerEvents: "all",
labelOutlineColor: "white",
labelOutlineWidth: 8,
labelAlign: "cm",
cursor: "pointer",
fontFamily: "sans-serif"
});
var halte_style = new OpenLayers.StyleMap({
'default' : halte_styled,
'temporary' : halte_temp_styled
});
Then add the rules , who will influence the behavior of the (default) style, in the example below it will follow the scale of the layer and act accordingly. In this example, once you are zoomed at level 18, the labels of the feature will be displayed, else they will only be displayed when hovered over.
/* Style the halte layer acc to res */
halte_style.styles['default'].addRules([
new OpenLayers.Rule({
maxScaleDenominator: 215000,
minScaleDenominator: 27000,
symbolizer: {
fillColor: "red",
fillOpacity: 0.6,
fontColor: "#000000",
fontWeight: "light",
pointRadius: 4,
fontSize: "11px",
strokeColor: "#ff9963",
strokeWidth: 2,
pointerEvents: "all",
labelOutlineColor: "white",
labelOutlineWidth: 8,
labelAlign: "cm",
cursor: "pointer",
fontFamily: "sans-serif"
}
}),
new OpenLayers.Rule({
maxScaleDenominator: 27000,
minScaleDenominator: 3384,
symbolizer: {
fillColor: "red",
fillOpacity: 0.6,
fontColor: "#000000",
fontWeight: "light",
pointRadius: 10,
fontSize: "11px",
strokeColor: "#ff9963",
strokeWidth: 3,
pointerEvents: "all",
labelOutlineColor: "white",
labelOutlineWidth: 8,
labelAlign: "cm",
cursor: "pointer",
fontFamily: "sans-serif"
}
}),
new OpenLayers.Rule({
maxScaleDenominator: 3384,
minScaleDenominator: 1,
symbolizer: {
fillColor: "red",
fillOpacity: 0.6,
fontColor: "#000000",
fontWeight: "light",
pointRadius: 10,
fontSize: "11px",
strokeColor: "#ff9963",
strokeWidth: 3,
label : "${name}",
labelAlign: "cm",
//labelAlign: "cm",
pointerEvents: "all",
labelOutlineColor: "white",
labelOutlineWidth: 8,
cursor: "pointer",
fontFamily: "sans-serif"
}
})
]);
In the vector layer in question you set this stylemap:
styleMap: halte_style,
You probably could play as well with
minScale: 54168.1
On your vector layer. But that isn't as fine-grained as rules.