[OpenLayers-Users] mouseover event creation for looped marker creation

Eric Lemoine eric.c2c at gmail.com
Thu Oct 2 03:16:21 EDT 2008


On Tue, Sep 30, 2008 at 7:47 PM, Andrew Schuh <andys at neptuneinc.org> wrote:
>
> I have a question regarding event handling.  I'm new to this and I'm having a
> bit of trouble.  I'm looping over marker creation and I have a vector of
> data that is updated on each iteration of loop (tmpmarks array with 4
> members).  This works fine for the marker creation and placement but I would
> like to add information to be placed within a div tag on the web page based
> on mouseover.  It seems that the mouseover event is not statically created
> at the time it is defined and when it is called it always pulls the last
> value of tmpmarks for all markers.  I'm sure this is just my lack of
> understanding about event handling but could anybody give me advice on how
> to get around this?   Thanks in advance for any advice.
>
> ......
> var marktmp = new OpenLayers.Marker(new
> OpenLayers.LonLat(tmpmarks[0],tmpmarks[1]),iconblue.clone())
> marktmp.events.register('mouseover',marktmp,function(evt)
>
> {filldiv('clustersizediv',tmpmarks[2]);filldiv('samplediv',tmpmarks[3]); });
> marktmp.events.register('mouseout',marktmp,function(evt)
>
> {blankdiv('clustersizediv');blankdiv('samplediv');OpenLayers.Event.stop(evt);
> });
> markers.addMarker(marktmp);}

Try (untested):

var marktmp = new OpenLayers.Marker(new
    OpenLayers.LonLat(tmpmarks[0], tmpmarks[1]), iconblue.clone());

marktmp.events.register('mouseover', marktmp,
    OpenLayers.Function.bind(function(evt) {
        filldiv('clustersizediv', this.clustersizediv);
        filldiv('samplediv', this.samplediv);
     },  {clustersizediv: tmpmarks[2], samplediv: tmpmarks[3]})
);

--
Eric



More information about the Users mailing list