Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to have some very basic functionality with vector points with Openlayers 2.12 and I can't figure out how to track a click event on a point.

I create a map using the following code and add one point:

var map;
function init(){
    map = new OpenLayers.Map('map');

    var gsat = new OpenLayers.Layer.Google(
        "Google Satellite",
        {type: google.maps.MapTypeId.SATELLITE, numZoomLevels: 22}


    var vectorLayer = new OpenLayers.Layer.Vector("vector");

        new OpenLayers.Feature.Vector(
            new OpenLayers.Geometry.Point(-57.635021, -25.276987).transform(
            new OpenLayers.Projection("EPSG:4326"),

    map.setCenter(new OpenLayers.LonLat(10.2, 48.9).transform(
        new OpenLayers.Projection("EPSG:4326"),
        ), 2


Then, I've tried to identify when the point is clicked:

    // detect when points are clicked
    pointClick = new OpenLayers.Control.GetFeature(vectorLayer, OpenLayers.Handler.Point, 
    {eventListeners:{"click": clickNotice}};                                            

    // detect point events 
    function clickNotice(evt) {
        alert('Point clicked');


This is not working, (although I don't get any errors in Firebug), but I'm not sure of the correct syntax for handling points.

share|improve this question
up vote 9 down vote accepted

GetFeature control designed for retrieve features from a server and fires events that notify applications of the selected features. In your case you should use SelectFeature control:

selectFeature = new OpenLayers.Control.SelectFeature(
        onSelect: clickNotice,
        autoActivate: true

Your example is not working beacause you have to activate GetFeature control before using it.

share|improve this answer

@drnextgis is right. checkout this example here for some inspiration.

i hope it helps you...

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.