[OpenLayers-Users] SelectFeature working at the same time in two different overlays?

Willy gruppi at willygroup.org
Wed May 26 03:41:14 EDT 2010


Hi,
I've two overlays, one is a Vector layers of markers built from a kml file,
the other is a GML geometric layer from an xml file.
I've added a SelectFeature for each layer, but if I add first layer1 then
layer2
only selectFeature for layer2 work. On otherwise if I add layer2 then layer1
only
selectFeature for layer1 work, there is a way to make working both layers?
Here the code:

var layer1 = new OpenLayers.Layer.Vector("Segnalazioni", {
    'displayInLayerSwitcher':false,
    styleMap: new OpenLayers.StyleMap(style),
    projection: map.displayProjection,
    strategies: [new OpenLayers.Strategy.Fixed()],
    protocol: new OpenLayers.Protocol.HTTP({
        url: "file.kml",
        format: new OpenLayers.Format.KML({
            extractStyles: false,
            extractAttributes: true
        })
    })
});

var  layer2 = new OpenLayers.Layer.GML(
    "GML",
    "file.xml",
    {
        projection: map.displayProjection,
        styleMap: myStyleMap,
        'displayInLayerSwitcher':false,
        'isBaseLayer':false
    }
);




selectControl = new OpenLayers.Control.SelectFeature(
    layer2,
    {
        clickout: true, toggle: true,
        multiple: false, hover: true
    }
);

layer2.events.on(
    {
        "featureselected": function(e) {
            alert("Selected.");
        },
        "featureunselected": function(e) {
            alert("Unselected.");
        }
    }
);

map.addControl(selectControl);
selectControl.activate();

select = new OpenLayers.Control.SelectFeature(layer1);
layer1.events.on(
    {
        "featureselected": onFeatureSelect,
        "featureunselected": onFeatureUnselect
    }
);

map.addControl(select);
select.activate();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20100526/0807993f/attachment.html


More information about the Users mailing list