I'm trying to select features from different WFS layers but unfortunatelly it doesn't works in my code.
This is my code:
var select = new OpenLayers.Layer.Vector("Selection", {styleMap: new OpenLayers.Style(OpenLayers.Feature.Vector.style["select"])});
var hover = new OpenLayers.Layer.Vector("Hover");
map.addLayers([hover,select]);
controles = new OpenLayers.Control.GetFeature({
protocol: new OpenLayers.Protocol.WFS({
url: "http://demo.opengeo.org/geoserver/wfs",
featureType: ["states","world"]}),
box: true,
hover: true,
multipleKey: "shiftKey",
toggleKey: "ctrlKey",
});
controles.events.register("featureselected", this, function(e) {
select.addFeatures([e.feature]);
});
controles.events.register("featureunselected", this, function(e) {
select.removeFeatures([e.feature]);
});
controles.events.register("hoverfeature", this, function(e) {
hover.addFeatures([e.feature]);
});
controles.events.register("outfeature", this, function(e) {
hover.removeFeatures([e.feature]);
});
map.addControl(controles);
controles.activate();
As you can see, I've put in the featureType two layers but only the first one can be selected. What am I doing wrong?
Best Answer
The documentation and source code say featureType has the type 'String' not array
It's better to create each layer in a single step and pass them to a OpenLayers.Control.SelectFeature instance.
Here the link to the official example: http://openlayers.org/dev/examples/select-feature-multilayer.html