[OpenLayers-Users] Problem with SelectFeature in OpenLayers.Layer.Vector.clone()

Robert Kulawik rob-news at gmx.de
Wed Sep 7 06:03:09 EDT 2011


Hello list,

i have a problem with selecting features by selectfeature control in
cloned vector layer.

For example, when i select features in a layer like this:

(...)
var layer = new OpenLayers.Layer.Vector();
layer = map.getLayer(layerID);

layer.setVisibility(true);
layer.redraw();

var selectControl = new OpenLayers.Control.SelectFeature(
    layer, {
        clickout: false, toggle: false,
        multiple: false, hover: false,
        toggleKey: "ctrlKey", // ctrl key removes from selection
        multipleKey: "shiftKey", // shift key adds to selection
        box: true
        }       
 );
layer.map.addControl(selectControl);
selectControl.activate();

e.g.
for (var point in layer.features){
    (...)
       selectControl.select(layer.features[point]);
}

it works fine.

but i need this with a cloned layer. when I do this with:

var oldLayer = new OpenLayers.Layer.Vector();
oldLayer = map.getLayer(layerID);

var layer = new OpenLayers.Layer.Vector();
layer = oldLayer.clone();
...etc. see above

i get by the first selection an error:

"c is null" in OpenLayers.js (Zeile 805)

(else{if(a._prevHighlighter!=this.id)a._lastHighlighter=a._prevHighlighter;delete
a._prevHighlighter}b.drawFeature(a,a.style||a.layer.style||"default");this.events.triggerEvent("featureunhighlighted",{feature:a})},select:function(a){var
b=this.onBeforeSelect.call(this.scope,a),c=a.layer;if(b!==false){b=c.events.triggerEvent("beforefeatureselected",{feature:a});if(b!==false){c.selectedFeatures.push(a);this.highlight(a);if(!this.handlers.feature.lastFeature)this.handlers.feature.lastFeature=c.selectedFeatures[0];)

I use Openlayers.js 2.10 $Revision: 10995

Has somebody an idea to solve this?

Best Regards
Robert




More information about the Users mailing list