I've added a MapLayerTable to my application, and I'm loading multiple layers using shape files successfully. Now I would like to select features on the map of the selected layer. For this, I would need to find the currently clicked layer.

I've already used the following code to check whether the layers are active and selected.

for (Layer layer : mapPane.getMapContent().layers()) {
    if (layer.isSelected()) {
        System.out.println("Layer selected : " + layer.getTitle());

But what I need is a method to select only one layer. E.g.: clicked layer, right clicked layer. I hope there would be a method to select one layer.


Since the MapLayerTable allows you to select 0 to many layers there is no way to have a getSelected() method easily implemented. But when you select a layer in the table it calls setSelected on the layer which fires a MapLayerEvent.SELECTIONCHANGED event to any MapLayerListeners that are registered. So you can maintain your own list of selected layers that is updated via the MapLayerTable.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.