Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

Thanks for your help, Best Regards, Rafael

share|improve this question
add comment

1 Answer 1

The documentation and source code say featureType has the type 'String' not array

controles = new OpenLayers.Control.GetFeature({
    protocol: new OpenLayers.Protocol.WFS({
        url: "http://demo.opengeo.org/geoserver/wfs",
        featureType: "states"}),
    box: true,
    hover: true,
    multipleKey: "shiftKey",
    toggleKey: "ctrlKey",
});

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.