[GIS] Using multiple Openlayers.Control.SelectFeature controls

openlayers-2

I am working with Openlayers 2. The problem that I am facing right now is that I have multiple editable layers in my application I want to add, delete, modify features as well as Displaying Feature information regarding features. So that I uses one SelectFeature Control for displaying info and one for deleting feature. when I select control from one of them it results conflicting with each other.

How can i remove this problem?

Best Answer

Try defining seperate events like this:

        vectors1.addFeatures(createFeatures());
        vectors2.addFeatures(createFeatures());

        vectors1.events.on({
            "featureselected": function(e) {
                showStatus("selected feature "+e.feature.id+" on Vector Layer 1");
            },
            "featureunselected": function(e) {
                showStatus("unselected feature "+e.feature.id+" on Vector Layer 1");
            }
        });
        vectors2.events.on({
            "featureselected": function(e) {
                showStatus("selected feature "+e.feature.id+" on Vector Layer 2");
            },
            "featureunselected": function(e) {
                showStatus("unselected feature "+e.feature.id+" on Vector Layer 2");
            }
        });

There is a working example in offical OpenLayers example site http://dev.openlayers.org/examples/select-feature-multilayer.html