Search code examples
javascriptopenlayers

Openlayers how to show polygon only on mouseover, and hide on mouseout?


Any suggestions on how i can show a polygon only on mouseover? I am thinking it must be possible to set the initial fillOpacity and strokeOpacity to 0 on the style object.

And then attach a mouseover and mouseout listener to the polygon itself, and modify the fillOpacity and strokeOpacity style upon invocation of the listeners?

However, im a bit stuck on actually how to get started with this.

Any guidance and help is appreciated!


Solution

  • Solved it using:

               new OpenLayers.Control.SelectFeature(this.layer,{
                    clickout: true, toggle: false,
                    multiple: true, hover: true,
                    callbacks: {
                        'over':function(feature){
    
                        },
                        'out':function(feature){
    
                        },
                        'click':function(feature){
    
                        }
                    }
                })