[OpenLayers-Users] unselect did not work

Sarah Schuessler sarah_flip at yahoo.de
Tue Apr 27 03:57:27 EDT 2010


Hi Arnd,

thanks for your answer!
Please read below.




________________________________


 
Hi,
 
i'm not sure, why you need a layer for your selected 
feature. Why not use the selectFeatureControl on the wfs 
layer.
I use my Control.SelectFeature with my wfs layer(wfs2)- or don`t I use the event right? (event.register instead of events.on). I get along with this example: http://dev.openlayers.org/releases/OpenLayers-2.9/examples/getfeature-wfs.html to get back a visual selecting for the user and get back some information about the selected feature.


About your question. 
 
The problem is the feature object. You add not a new 
feature to a new layer. Instead it seems, that you move the selected 
feature from the wfs layer  to the new layer. That means 
wfs.event.on("unselected") cann't work, because your selectFeatureControl works 
only for the wfs layer.
Yes I thought something like that, but could not manage to solve this. Thanks for your example! 

Use a 
clone of the feature and remove the only feature on your select 
layer.
 
    layerWFS.events.on({'featureselected': 
function(feature){
                        
selectLayer.addFeatures([feature.feature.clone()]);
                        
//selectLayer.addFeatures([feature.feature]);
                        
alert(this.selectedFeatures.length);
                    
},
                    
'featureunselected': 
function(feature){
                        
selectLayer.removeFeatures([selectLayer.features[0]]);
                        
//selectLayer.removeFeatures([feature.feature]);
                        
alert(this.selectedFeatures.length + " - 
unselected");
                    
},
                
});

 
A bit confusing is also the style you add as default 
style to the select layer. It looks like you select a feature on the wfs layer, 
but it's really the not selected feature on the select 
layer.
So I have to register a select style to my wfs layer and cancel select layer, am I right? 

best regards
Sarah

Arnd


________________________________
 Von: users-bounces at openlayers.org 
[mailto:users-bounces at openlayers.org] Im Auftrag von Sarah 
Schuessler
Gesendet: Montag, 26. April 2010 10:28
An: users at openlayers.org
Betreff: [OpenLayers-Users] unselect did not 
work


Hi list,

I try to use Control.SelectFeature but I can`t unselect 
(selection layer does not get removed). Here is my code:
var selectFeature = 
new OpenLayers.Control.SelectFeature(wfs2, {clickout: true, multiple: false, 
hover: false, toggle:false, toggleKey: "shiftKey", box: true, multipleKey: 
"ctrlKey"});

var wfs2 = new OpenLayers.Layer.Vector("WFS_Waldschutz", 
                
{ styleMap: styleMap,
        
         strategies: [new 
OpenLayers.Strategy.Fixed()],
        
         protocol: new 
OpenLayers.Protocol.WFS({ 
        
           url: "http://myserver:81/geoserver/wfs?service=wfs", 
            
        featureNS: "http://mycomp.org", 
            
        featureType: "mylayer", 
                
    geometryName: "SHAPE", 
    
                
srsName: "EPSG:4326",
        
            version: "1.1.0" 
                
  
            
        }),
    
               
projection: new OpenLayers.Projection("EPSG:4326")
    
            });    

wfs2.events.on({'featureselected': function(feature){ 
                
            
select.addFeatures([feature.feature]); 
        
                
    alert(this.selectedFeatures.length); 
    
                
    }, 
        
                
'featureunselected': function(feature){
        
                
    
select.removeFeatures([feature.feature]);
    
                
        alert(this.selectedFeatures.length); 
alert("unselected");
            
            
},
            
        });  

var select = new 
OpenLayers.Layer.Vector("Selection", { 
        
    styleMap: new 
OpenLayers.Style(OpenLayers.Feature.Vector.style["select"]), 
            
displayInLayerSwitcher: true, visibility: true});

featureselected works 
(at firebug I can see that my app does not get to this break point). What`s 
wrong?

Thank you for any hints.
best 
regards
Sarah

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20100427/b2a2ebbf/attachment.html


More information about the Users mailing list