[OpenLayers-Users] unselect did not work

Sarah Schuessler sarah_flip at yahoo.de
Wed Apr 28 10:24:39 EDT 2010


Hi Arnd,

thanks for your explanation about styleMap and wms-wfs layer for select control. I thought I could use that with original wfs layer instead of having a wfs.fromwmslayer.
I solved my issue with adding a new default and select Style to my wfs layer and remove lines with selectLayer.addFeatures and selectLayer. removeFeatures (so that I can see my wfs styles and not selectlayer select style).


Thanks for your time and help!
best regards
Sarah




________________________________


 
Hi Sarah,
 
the example shows how to retrieve features from a wms 
layer. But you have a vector layer (wfs layer). So you can link the 
SelectFeatureControl to that layer. 
 
ctrlSelectFeatureOptions = { 
clickout: true, toggle: true, multiple: false, hover: false, toggleKey: 
"ctrlKey", multipleKey: "none", box: false };
ctrlSelectFeature = new 
OpenLayers.Control.SelectFeature(layerWFS, 
ctrlSelectFeatureOptions);
 
//optional
ctrlSelectFeature.onSelect    = function (ft) {  
};
ctrlSelectFeature.onUnselect  = function (ft) {  };
 
ctrlSelectFeature.activate();

If you 
now click on a feature from your wfs it will be selected. If you do not add 
a own styleMap to your wfs layer, the default styleMap is used to display the 
features for the different modes (unselected, selected or 
temporarily).
 
If you want use your own 
styleMap, you have to declare the styles for the different modes (at last 
'default' for unselected features and 'select' for selected features) to see 
that you have select a feature.
 
Arnd
 
 

________________________________
 Von: Sarah Schuessler 
[mailto:sarah_flip at yahoo.de] 
Gesendet: Dienstag, 27. April 2010 
09:57
An: Arnd Wippermann
Cc: users at openlayers.org
Betreff: AW: [OpenLayers-Users] unselect did not 
work


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/20100428/cf3a3c3e/attachment.html


More information about the Users mailing list