简体   繁体   English

在OpenLayers中的选定元素之前设置功能

[英]Set feature before selected element in OpenLayers

I have a some features that must be always in front of any other feature, the problem is that when I draw new feature or select current one it overlaps all other features. 我有一些功能必须始终位于其他任何功能的前面,问题是当我绘制新功能或选择当前功能时,它会与所有其他功能重叠。 Is there a way I can set some features or a layer to be always on top of everything ? 有没有一种方法可以将某些要素或图层设置为始终位于一切之上?

I suspect you are not specifying zIndex in the selected style for the interaction. 我怀疑您不是在交互的选定样式中指定zIndex。 In this code sample for hover on features in certain layers I set the selected style to be the same as the normal unselected style for the layer and only change the cursor 在此代码示例中,将鼠标悬停在某些图层上的要素中,我将所选样式设置为与该图层的常规未选择样式相同,仅更改了光标

var interStyle;

function interFilter(feature, layer) {
    for (var i = 0; i < layerTypes.length; i++) {
        if (layer && layer.get("jsonName") && layer.get("jsonName").slice(-7) == layerTypes[i] + ".json") {
            interStyle = layer.getStyle();
            return true;
        }
    }
    return false;
}

var interHover = new ol.interaction.Select({ condition: ol.events.condition.pointerMove,
                                             style: function(feature) { return interStyle; },
                                             filter: interFilter });

interHover.on( "select",
               function(event) { rowMap.getViewport().style.cursor = event.selected.length > 0 ? "pointer" : "";
                                 // optional callback to inform the calling page the mouse is over/off a feature
                                 if (options.setMouseOver) { options.setMouseOver(event.selected.length > 0); } }
);

The purple line remains below the green line at all times: 紫色线始终保持在绿色线以下:

在此处输入图片说明

However if I comment out the style setting 但是,如果我注释掉样式设置

var interHover = new ol.interaction.Select({ condition: ol.events.condition.pointerMove,
                                             // style: function(feature) { return interStyle; },
                                             filter: interFilter });

When hovering over the purple line it takes OpenLayers default blue selected style and appears above the green line 将鼠标悬停在紫色线上时,它将使用OpenLayers默认的蓝色选定样式,并显示在绿色线上方

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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