Hi All
I'm sure this has been asked many times and yes I've found samples but I just
can't make it work. I want to have a popup when I hover the mouse over the
objects on the layer.
My code is below.
I've spent several hours on this and really would appreciate some help
kind regards
Grant
this.addVectorLayer = function(name){
var drawControls, selectedFeature = null, selectControl = null;
var newLayer = new OpenLayers.Layer.Vector(name);
selectControl = new OpenLayers.Control.SelectFeature(newLayer, {
hover: true,
onSelect: onFeatureSelect,
onUnselect: onFeatureUnselect
});
function onPopupClose(evt) {
selectControl.unselect(selectedFeature);
}
function onFeatureSelect(feature) {
selectedFeature = feature;
popup = new OpenLayers.Popup.FramedCloud("popup",
feature.geometry.getBounds().getCenterLonLat(),
null,
"<div style='font-size:.8em'>Feature: "
+ feature.id +"<br>Area: " + feature.geometry.getArea()+"</div>",
null, true, onPopupClose);
feature.popup = popup;
map.addPopup(popup);
}
function onFeatureUnselect(feature) {
map.removePopup(feature.popup);
feature.popup.destroy();
feature.popup = null;
}
drawControls = {
polygon: new
OpenLayers.Control.DrawFeature(newLayer, OpenLayers.Handler.Polygon),
select: selectControl
};
for(var key in drawControls) {
map.addControl(drawControls[key]);
}
layers.push({"id":name, "layer":newLayer, "features":[]});
};
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users