[GIS] How to change the default color used by openlayers hover

openlayers-2

It is possible to change the color of highlightCtrl when I use onselectedHover? Default is light blue.

I want to change it to another one eg. red? Does anyone know where this value is defined?

Best Answer

When you define your layer you could specify your styleMaps as well:

_layer = new OpenLayers.Layer.Vector("My Layer Name", {
    styleMap: new OpenLayers.StyleMap({
        "default": new OpenLayers.Style({
            strokeColor: "#ff0000",
            strokeOpacity: .7,
            strokeWidth: 1,
            fillColor: "#ff0000",
            fillOpacity: 0,
            cursor: "pointer"
        }),
        "temporary": new OpenLayers.Style({
            strokeColor: "#ffff33",
            strokeOpacity: .9,
            strokeWidth: 2,
            fillColor: "#ffff33",
            fillOpacity: .3,
            cursor: "pointer"
        }),
        "select": new OpenLayers.Style({
            strokeColor: "#0033ff",
            strokeOpacity: .7,
            strokeWidth: 2,
            fillColor: "#0033ff",
            fillOpacity: 0,
            graphicZIndex: 2,
            cursor: "pointer"
        })
    })
});

Then specify your renderintent:

_highlightControl = new OpenLayers.Control.SelectFeature(layer, {
    hover: true,
    highlightOnly: true,
    renderIntent: "temporary"
});