简体   繁体   中英

How to bring a marker popup to the front in OpenLayers?

I have a popup that I'm declaring like so in OpenLayers:

var feature = new O[penLayers.Feature(markers, lonLat);
feature.popupClass = OpenLayers.Class(OpenLayers.Popup.FramedCloud, {
    'autoSize': true;
    'maxSize': new OpenLayers.Size(500, 300)
});

The issue is that the multiple popups on my map are being created with consecutive z-indexes, so the popups will always be shown in the order the markers were added, with the popup of the most recent marker always being on top.

Is there a way to change it so that the most recently-clicked marker popup is on top, instead of that of the most recently-added marker? I've tried manually changing the z-index in firebug (as a test) but it doesn't bring it to the front. I'd rather avoid deleting and remaking the popup or marker, but it seems to be the only solution I can find.

You can use jQuery to make the trick of the zindex like this

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标记克隆来解决我的问题。

call ms.setZIndex(100000); where ms is the container of the marker (an instance of OpenLayers.Layer.Markers );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM