[OpenLayers-Users] select multiple features with a click

Pierre Giraud pierre.giraud at camptocamp.com
Fri Feb 24 06:25:09 EST 2012


Hi,

Unfortunately, the SelectFeature relies on OL.Handler.Feature for
selection by click. This handler isn't able to do multiple selection
due to DOM events limitations.


The following is kind of a hack but the following should work (tested
quickly in the select-feature.html example).
The trick is to disable the feature handler, and to use the select by
box even if the user doesn't drag a box.

The problem is that you won't be able to navigate the map while using
this control. There may be a better a solution.

{{{
var vectors = map.getLayersByName('Vector Layer')[0];
SelectMultipleControl = OpenLayers.Class(OpenLayers.Control.SelectFeature, {
    selectBox: function(position) {
        if (position instanceof OpenLayers.Pixel) {
            position = new OpenLayers.Bounds(position.x, position.y,
position.x, position.y);
        }
        OpenLayers.Control.SelectFeature.prototype.selectBox.call(this,
position);
    }
});
var control = new SelectMultipleControl(vectors, {
    box: true,
    multiple: true,
    clickout: true
});
map.addControl(control);
control.activate();
control.handlers.feature.deactivate();
}}}

Pierre

On Thu, Feb 23, 2012 at 11:03 PM, Jim White <jbw2003 at earthlink.net> wrote:
> I have a vector layer of points with images. I want to click on the map and
> select one or more features if several points are close together.
>
>  var select_control = new OpenLayers.Control.SelectFeature(vector_layer,
>            {"onSelect": test,
>               "multiple": true});
>
> This doesn't seem to work. It selects one feature, but not two if two points
> are close together. How to do this?
>
> Jim White
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users



-- 
Pierre GIRAUD
Géomaticien, Analyste

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 93
Mail : pierre.giraud at camptocamp.com
http://www.camptocamp.com


More information about the Users mailing list