When I zoom or move the map my layer is redrawn. This is what I want, because I have allot of features to load at once. This is the code:
wfs = new OpenLayers.Layer.Vector("WFS", {
strategies: [new OpenLayers.Strategy.BBOX({
resFactor: 1,
ratio:1
})],
protocol: new OpenLayers.Protocol.WFS({
maxFeatures:1000,
url: myUrl,
featureType: myFeatureType,
featureNS: myFeaturedNS,
version: "1.1.0"
}),
filter: setFilter(year, variant)
});
The following code is my selectioncode. This all works as I wan't it to. However, when the layer is redrawn the selection is lost and the onFeatureUnselect is not fired (which it should). I'm not sure if the selection is really lost or that the style is resetted.
selectCtrl = new OpenLayers.Control.SelectFeature(
wfs,
{
clickout: true, toggle: false,
multiple: false, hover: false,
box: true,
toggleKey: "shiftKey", // ctrl key removes from selection
multipleKey: "shiftKey",
eventListeners: {
featurehighlighted: onFeatureSelect,
featureunhighlighted: onFeatureUnselect
}
}
);
@geographika
My onFeatureSelect and onFeatureUnselect functions:
function onFeatureSelect(e) {
var feature = e.feature.attributes;
var featureclone = e.feature.clone();
var style = {
pointRadius: 10,
fillOpacity:0,
strokeColor: "#000000"
};
featureclone.style = style;
layer2.addFeatures([featureclone]);
selectedFeatures[featureclone.attributes.receptor_id] = featureclone;
}
function onFeatureUnselect(e) {
var feature = e.feature.attributes;
layer2.removeFeatures(selectedFeatures[feature.receptor_id]);
delete selectedFeatures[feature.receptor_id];
}