Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

make a hover/mouseover label for a polygon in Openlayers?

I made a map with draw, delete and drag polygon function.

Now I need to make a hover mouseover for this.

How to get a hover label for polygon

        var polygonLayer = new OpenLayers.Layer.Vector("Polygon Layer");

        map.addLayers([wmsLayer, polygonLayer]);

        polyOptions = {sides: 40};
        polygonControl = new OpenLayers.Control.DrawFeature(polygonLayer,
                                        OpenLayers.Handler.RegularPolygon,
                                        {handlerOptions: polyOptions} );

       var myStyles = new OpenLayers.StyleMap({
            "default": new OpenLayers.Style({
                pointRadius: "${type}", // sized according to type attribute
                fillColor: "#ffcc66",
                strokeColor: "#ff9933",
                strokeWidth: 2,
                graphicZIndex: 1
            }),
            "select": new OpenLayers.Style({
                fillColor: "#66ccff",
                strokeColor: "#3399ff",
                graphicZIndex: 2
            })
        });

         var select = new OpenLayers.Control.SelectFeature(polygonLayer, {hover: true});
        map.addControl(select);
        select.activate();
share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

Hover

http://openlayers.org/dev/examples/highlight-feature.html

Popup

http://openlayers.org/dev/examples/popupMatrix.html

http://openlayers.org/dev/examples/sundials.html

share|improve this answer
    
I actually just wanted an alt image hover label for my polgonLayer –  Blake Loizides Feb 8 '12 at 8:17
    
@CaptDragon I managed to get a hover effect, But how do I get a label when i hover. A simple label? Your help is always greatly appreciated. Thank you. –  Blake Loizides Feb 8 '12 at 10:41
    
@CaptDragon, Found it thanks. –  Blake Loizides Feb 8 '12 at 11:28
    
thanks alot, found a way to put text on mouseover in the styleMap –  Blake Loizides Feb 8 '12 at 11:29
    
@BlakeLoizides : I'm interested in something similar. Can you tell me how you managed t o put text on mouseover ? –  Sergiu Feb 7 '13 at 19:15
show 1 more comment

The SelectFeature control provides event hooks for this purpose:

var selectControl = new OpenLayers.Control.SelectFeature(
  polygonLayer, {
    hover: true,
    onBeforeSelect: function(feature) {
       // add code to create tooltip/popup
       popup = new OpenLayers.Popup.FramedCloud(
          "",
          feature.geometry.getBounds().getCenterLonLat(),
          new OpenLayers.Size(100,100),
          "<div>some text here</div>",
          null,
          true,
          null);

       feature.popup = popup;

       map.addPopup(popup);
       // return false to disable selection and redraw
       // or return true for default behaviour
       return true;
    },
    onUnselect: function(feature) {
       // remove tooltip
       map.removePopup(feature.popup);
       feature.popup.destroy();
       feature.popup=null;
    }
});
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.