[OpenLayers-Users] problem with hover and click on same vector layer
David Doyle
David.Doyle at riverbed.com
Tue Apr 1 07:46:10 PDT 2014
Hi there. I'm extremely new to OpenLayers and am still early in the learning process.
I found a couple of threads on the subject of putting hover and click on the same vector layer, and got this to mostly work. But I'm running into a problem that I can't solve. I can mousein and out of the vector and get my popup to show up, and I can click on the vector and get the correct click behavior. But after clicking on a vector, any time I hover over it, both the mousein AND click get triggered.
Does anyone know why this happens and what I can do to prevent the click from getting re-triggered?
If it helps, here's the relevant part of the code
selectCtrl = new OpenLayers.Control.SelectFeature(mydata, {
clickout: true,
hover: false,
eventListeners: {
featurehighlighted: function(e) { // clicked
console.log('click');
onFeatureSelect(e.feature);
}
}
});
highlightCtrl = new OpenLayers.Control.SelectFeature(mydata, {
hover: true,
highlightOnly: true,
eventListeners: {
featurehighlighted: function(e) { // mousein
console.log('mousein');
feature = e.feature;
popup = new OpenLayers.Popup.Anchored("",
feature.geometry.getBounds().getCenterLonLat(),
/*new OpenLayers.Size(100,100),*/ null,
"<div>You're over it</div>",
null, false, null);
popup.autoSize = true;
popup.calculateRelativePosition = function () {
return 'tr';
}
feature.popup = popup;
map.addPopup(popup);
return true;
},
featureunhighlighted: function(e) {
console.log('mouseout');
feature = e.feature;
if(feature.popup) {
map.removePopup(feature.popup);
feature.popup.destroy();
feature.popup=null;
}
}
}
});
map.addControl(highlightCtrl);
highlightCtrl.activate();
map.addControl(selectCtrl);
selectCtrl.activate();
Thanks,
Dave
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20140401/1662eafa/attachment.html>
More information about the Users
mailing list