[OpenLayers-Users] Identifiying which marker has been clicked in callback

Pierre GIRAUD bluecarto at gmail.com
Fri Mar 6 05:18:18 EST 2009


The second argument in the events.register correspond to the context
in which the callback will be executed. That means that by using the
"this" keyword in the callback you will access to object given as
context (scope).

In your case,

function markerClicked(evt) {
    alert (this.icon.url); // will return the url of the icon of the
clicked marker
}

Do you need something more specific ?

Regards,
Pierre

On Fri, Mar 6, 2009 at 9:35 AM, Robert Collier
<rcollier at alwaysongroup.com> wrote:
> I’m adding markers to a map, and I want to do things when they are clicked upon, so I’m doing this:
>
>      var marker = new OpenLayers.Marker(lonLat,icon);
>      sitelayer.addMarker(marker);
>        marker.events.register("mousedown", marker, markerclicked);
>
> But I really want to be able to pass another variable to the callback aswell that identifies the particular marker, is there any way I can achieve something like:
>
>        marker.events.register("mousedown", marker, markerclicked, myid);
>        ...
>        function markerclicked(evt, myid) {
>        }
>
> Or get the same result (identify a specific marker from the callback).
>
>        - Thanks, Robert Collier
>
> --
> Robert Collier
> Network Architect
> AlwaysON Group
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>



-- 
Pierre GIRAUD
http://www.camptocamp.com
Sent from: Paris J France.



More information about the Users mailing list