You need to use a combination of the SelectFeature control and one of the OpenLayers.Popup classes, such as OpenLayers.Popup.FramedCloud . Here is an example of what:
http://openlayers.org/dev/examples/select-feature-openpopup.html
In this example, try using the "draw polygon" option to draw a polygon (double-click on the map to complete the polygon). Then use "select polygon on click" and click on the polygon and you will get a popup with a frame.
You can view the source of the page to find out how to do this. Here are the relevant parts of the code. Of course, you can change the message to what you want to display in the cloud frame:
var map = <your OpenLayers.Map object>; var polygonLayer = <your vector layer>; selectControl = new OpenLayers.Control.SelectFeature(polygonLayer, {onSelect: onFeatureSelect, onUnselect: onFeatureUnselect}); map.addControl(selectControl); // not in the example, but do this function onPopupClose(evt) { selectControl.unselect(selectedFeature); } function onFeatureSelect(feature) { var message = "<div style='font-size:.8em'>Feature: " + feature.id +"<br>Area: " + feature.geometry.getArea()+"</div>"; selectedFeature = feature; popup = new OpenLayers.Popup.FramedCloud("chicken", feature.geometry.getBounds().getCenterLonLat(), null, message, null, true, onPopupClose); feature.popup = popup; map.addPopup(popup); } function onFeatureUnselect(feature) { map.removePopup(feature.popup); feature.popup.destroy(); feature.popup = null; }
Below are links to the controls you will use:
source share