3
votes

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

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

When an user clicks on the map it should select the feature on the WFS layer. So I have added the 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 features get selected when clicked.

But my overlay layer is beneath the WFS layer and I want it to be on top. The overlay layer is a non-filled polygon layer. So I added

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

after map.addLayers. This looks OK. My overlay layer is now above my WFS layer. But when I now click on the map, nothing gets selected.

Most likely I'm not doing it right. How can I make my overlay layer on top and my WFS layer selectable?

[EDIT]

As mentioned by Christophe I tried

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

But that resulted in an OL Error, probably because the overlay layer is a WMS layer.

[EDIT #2]

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

1
Try passing multiple layers to the SelectFeature constructor: [wfsLayer, overlayLayer]Christophe Roussy
Thanks Christophe. I did try that but then I get this error: TypeError: a.renderer is undefined The overlayLayer is a GWC layer (using GeoServer)Paul Meems
Maybe try the GIS stackexchange forums, I never used a GWC layer.Christophe Roussy

1 Answers

1
votes

I would suggest that you are using the wrong method to change your layer order.

I would suggest trying

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

If you only have one other layer this should bring your wfs layer to the top and allow your control to work correctly.

If you have more than one other layer or you wish to set a specific index you could try

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

Please note your select control constructor should only list your wfs layer if that is the only layer you want to select from.