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

Bart van den Eijnden (OSGIS) bartvde at osgis.nl
Wed May 26 03:43:54 EDT 2010


Use 1 SelectFeature Control and initialize it with an array of layers.

    /**
     * Constructor: OpenLayers.Control.SelectFeature
     * Create a new control for selecting features.
     *
     * Parameters:
     * layers - {<OpenLayers.Layer.Vector>}, or an array of vector layers.
The
     *     layer(s) this control will select features from.
     * options - {Object}
     */

Best regards,
Bart

> 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();
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>





More information about the Users mailing list