Choose features of a layer that is not on top

I have a map with 3 layers: 1 base layer, 1 overlay and 1 WFS layer. I load them as follows:

map.addLayers([baseLayer, wfsLayer, overlayLayer]); 

When the user clicks on the card, he must select a function at the WFS level. So I added a select control after calling map.addLayers:

  selectControl = new OpenLayers.Control.SelectFeature( [wfsLayer], { clickout: true, toggle: false, multiple: false, hover: false } ); map.addControl(selectControl); selectControl.activate(); 

This works great, my functions are selected when clicked.

But my layer with the label is below the WFS level, and I want it to be on top. The overlay layer is an unfilled polygonal layer. Therefore I added

 map.setLayerZIndex(overlayLayer, map.Z_INDEX_BASE[ "Feature" ]+10); 

after map.addLayers. It looks ok. My labeled layer is now above my WFS level. But when I click on the card, nothing is selected.

Most likely, I am not doing it right. How can I make a layer with an inscription on top and my WFS level can be selected?

[EDIT]

As mentioned by Christoph, I tried

  selectControl = new OpenLayers.Control.SelectFeature( [wfsLayer, overlayLayer], { clickout: true, toggle: false, multiple: false, hover: false } ); 

But this led to an OL error, probably because the overlay layer is a WMS layer.

[EDIT # 2]

I tried this question at https://gis.stackexchange.com/questions/59619/select-features-of-layer-which-is-not-on-top-in-openlayers

+4
source share
1 answer

I would suggest that you use the wrong method to reorder your layer.

I would suggest trying

 var wfsLayer = map.getLayersByName('WFS_Layer_Name')[0]; map.raiseLayer(wfsLayer, map.layers.length); 

If you have only one other layer, this should cause your wfs layer to be on top and allow your controls to work correctly.

If you have more than one level or want to set a specific index, you can try

 var wfsLayer = map.getLayersByName('WFS_Layer_Name')[0]; map.setLayerIndex(wfsLayer, 99); 

Note that your select select constructor should only specify your wfs level if this is the only layer you want to select.

+1
source

All Articles