[OpenLayers-Users] Click on OpenLayers.Feature.Vector

Andreas Hocevar ahocevar at opengeo.org
Thu Feb 25 08:36:48 EST 2010


Hi,

you need to create an OpenLayers.Control.SelectFeature instance, 
configure it with your vector layer, and add it to the map. You can then 
listen for the layer's "featureselected" event.

See the [1] example if you need a code snippet. The example does exactly 
the same, but on two different layers instead of just one.

Regards,
Andreas.

[1] http://openlayers.org/dev/examples/select-feature-multilayer.html

Christoph Lingg wrote:
> Hello!
> 
> I changed from GoogleMap to OpenLayers, and although I enjoy to use the opensource equivalent, sometimes I feel lost in the OL documentation ;-)
> 
> Would anyone be so kind and could give me hint how to achieve this very low level problem: I have a Vector Layer (I can't use marker class as I use the dragging feature as well) to which I add some Feature Vector, that are displayed on the map. What I need now is triggering an event when a feature was clicked. Very basically my code looks like this:
>> layer = new OpenLayers.Layer.Vector("layer");
>> map.addLayers([layer]);
>> ftr = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(lon, lat), null, styleMarker); // an icon
>> layer.addFeatures([ftr]);
> I tried different approaches that never worked out! What is the right way to go?
> 
> Thank you in advance for any help!
> 
> Christoph 
> 
> 
> 
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users


-- 
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.



More information about the Users mailing list