[英]How to bring a marker popup to the front in OpenLayers?
我在OpenLayers中聲明了一個彈出窗口:
var feature = new O[penLayers.Feature(markers, lonLat);
feature.popupClass = OpenLayers.Class(OpenLayers.Popup.FramedCloud, {
'autoSize': true;
'maxSize': new OpenLayers.Size(500, 300)
});
問題在於,我的地圖上的多個彈出式窗口是使用連續的z-indexs創建的,因此將始終按照添加標記的順序顯示彈出式窗口,而最新標記的彈出式窗口始終位於頂部。
有沒有一種方法可以更改它,以使最近單擊的標記彈出窗口位於頂部,而不是最近添加的標記彈出窗口? 我已經嘗試過手動更改Firebug中的z-index(作為測試),但是並沒有將其顯示在最前面。 我寧願避免刪除和重新制作彈出窗口或標記,但這似乎是我能找到的唯一解決方案。
您可以使用jQuery這樣的zindex
技巧
clientesLayer = new OpenLayers.Layer.Vector("PuntosVentas");
feature = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(vectorFatri.puntos[index][0],vectorFatri.puntos[index][1]),
{description: '<div><div class="popup_title"><h4>'+vectorFatri.imei+'</h4></div><div class="popup_content">'+vectorFatri.fecha[index]+'</div></div>'} ,
{
strokeColor: "#00FF00",
strokeOpacity: 1,
strokeWidth: 2,
fillColor: "#FF5500",
fillOpacity: 0.5,
pointRadius: 6,
pointerEvents: "visiblePainted"
}
);
controls = {
selector: new OpenLayers.Control.SelectFeature(clientesLayer, {
onSelect: function (feature) {
feature.popup = new OpenLayers.Popup.FramedCloud("pop",
feature.geometry.getBounds().getCenterLonLat(),
new OpenLayers.Size(300,200),
'<div class="markerContent">'+feature.attributes.description+'</div>',
null,
true,
function() { controls['selector'].unselectAll(); }
);
map.addPopup(feature.popup);
{# console.log('me seleccionaron');#}
//jquery trick to make the popup front of everything
$(".olPopup").css("z-index", 10000)
{# setTimeout(function(){$(".olPopup").css("z-index", 10000);}, 2000);#}
},
onUnselect: function (feature) {
map.removePopup(feature.popup);
feature.popup.destroy();
feature.popup = null;
}
})
}
map.addControl(controls['selector']);
controls['selector'].activate();
clientesLayer.addFeatures(feature);
我無法弄清楚如何可靠地更改z-index並使其正常工作,但是我可以通過完全刪除並在需要時創建一個新的map標記克隆來解決我的問題。
調用ms.setZIndex(100000);
其中ms
是標記的容器( OpenLayers.Layer.Markers
的實例);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.