的SelectFeature方法在Control类提供添加和通过分别监听事件featureselected和featureunselected除去矢量层上的弹出窗口的方式。下面示出了从我an example在网站的OpenLayers获得的样品的代码:如何在点击和鼠标悬停时显示不同的弹出窗口?
// create the layer with listeners to create and destroy popups
var vector = new OpenLayers.Layer.Vector("Points",{
eventListeners:{
'featureselected':function(evt){
var feature = evt.feature;
var popup = new OpenLayers.Popup.FramedCloud("popup",
OpenLayers.LonLat.fromString(feature.geometry.toShortString()),
null,
"
Foo:
null,
true
);
feature.popup = popup;
map.addPopup(popup);
},
'featureunselected':function(evt){
var feature = evt.feature;
map.removePopup(feature.popup);
feature.popup.destroy();
feature.popup = null;
}
}
});
vector.addFeatures(features);
// create the select feature control
var selector = new OpenLayers.Control.SelectFeature(vector,{
hover:true, # this line
autoActivate:true
});
上面的代码将允许在所述几何对象(在地图上的图标或标记物)上鼠标可显示的弹出。如果行hover:true被删除,弹出窗口将仅在鼠标点击几何对象时显示。
我想要的,是能够显示在鼠标悬停一种类型的弹出窗口(例如,图像加标题)和另一种类型(例如,详细描述)在鼠标点击。我不确定如何做到这一点。一些帮助将不胜感激。谢谢。
+0
我希望你能找到从这里的解决方案:http://www.openlayers.org/dev/examples/highlight-feature.html –
+0
@ user1702401,谢谢你的提示。我注意到该示例使用仅在版本2.13中提供的新事件侦听器。不能等待的稳定版本:) –
+0
如果你的意思是“beforefeaturehighlighted”,“featurehighlighted”和“featureunhighlighted”事件,那么那些已经存在了很长一段时间(2.11以来至少)。用2.12测试这个例子并且工作正常。 –