Tell me more ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm using an OpenLayers.Control.SelectFeature for selections on multiple layers. However, when I add a layer using setLayer(), my selections on the other layers are lost.

Anyone know how to work around this? I would like to keep my existing selections on other layers when I add a layer to the SelectFeature control.

Here is an example: MY EXAMPLE

Update:

I'm aware that this is part of the API. But i'm looking for a work around.

/**
 * APIMethod: setLayer
 * Attach a new layer to the control, overriding any existing layers.
 *
 * Parameters:
 * layers - Array of {<OpenLayers.Layer.Vector>} or a single
 *     {<OpenLayers.Layer.Vector>}
 */
setLayer: function(layers) {
    var isActive = this.active;
    this.unselectAll();
    this.deactivate();
    if(this.layers) {
        this.layer.destroy();
        this.layers = null;
    }
    this.initLayer(layers);
    this.handlers.feature.layer = this.layer;
    if (isActive) {
        this.activate();
    }
},
share|improve this question

1 Answer

up vote 5 down vote accepted

You could modify setLayer method of SelectFeature control:

OpenLayers.Control.SelectFeature.prototype.setLayer = function(layers) {
    var isActive = this.active;
    //this.unselectAll(); <- what you need
    this.deactivate();
    if(this.layers) {
        this.layer.destroy();
        this.layers = null;
    }
    this.initLayer(layers);
    this.handlers.feature.layer = this.layer;
    if (isActive) {
        this.activate();
    }
}
share|improve this answer
Of course i can! Don't know why i didn't think of that. Thanks! (+1) – CaptDragon Nov 29 '11 at 13:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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