[OpenLayers-Users] select multiple features with a click

Jim White jbw2003 at earthlink.net
Fri Feb 24 09:33:42 EST 2012


Thanks Pierre,

I haven't tried it but will keep this code in case someone asks for this 
feature. It looks like it will work!

Jim



On 02/24/2012 06:25 AM, Pierre Giraud wrote:
> 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
>
>



More information about the Users mailing list