如何在OpenLayers中将标记弹出窗口置于前面?

时间:2012-06-19 18:03:09

标签: javascript popup 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索引创建的,因此弹出窗口将始终按照添加标记的顺序显示,最新标记的弹出窗口始终位于顶部。

有没有办法更改它,以便最近点击的标记弹出窗口位于顶部,而不是最近添加的标记?我已经尝试手动更改firebug中的z-index(作为测试),但它没有将它带到前面。我宁愿避免删除和重新设置弹出窗口或标记,但它似乎是我能找到的唯一解决方案。

3 个答案:

答案 0 :(得分:3)

您可以使用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);

答案 1 :(得分:1)

我无法弄清楚如何可靠地更改z-index并使其工作,但我能够通过完全删除然后创建地图标记的新克隆来解决我的问题

答案 2 :(得分:0)

致电ms.setZIndex(100000);,其中ms是标记的容器(OpenLayers.Layer.Markers的实例);