[OpenLayers-Users] unselect did not work
Arnd Wippermann
arnd.wippermann at web.de
Mon Apr 26 13:12:16 EDT 2010
Hi,
i'm not sure, why you need a layer for your selected feature. Why not use
the selectFeatureControl on the wfs layer.
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.
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.
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/20100426/e7c49389/attachment.html
More information about the Users
mailing list