Re: [OpenLayers-Users] associating events to geometries

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: [OpenLayers-Users] associating events to geometries

erilem
On 3/19/07, Eric Lemoine <[hidden email]> wrote:

> On 3/19/07, Eric Lemoine <[hidden email]> wrote:
> > On 3/19/07, Christopher Schmidt <[hidden email]> wrote:
> > > On Mon, Mar 19, 2007 at 11:40:22AM +0100, Eric Lemoine wrote:
> > > > Hello
> > > >
> > > > I'd like to associate events to geometries. With the old vector branch
> > > > I did that using
> > > >
> > > > feature.geometry.registerEventCallback('mouseover', null, callback);
> > > >
> > > > but the registerEventCallback() no longer exists in the new vector tree.
> > >
> > > Have a look at http://openlayers.org/dev/examples/openmnnd.html , and
> > > the SelectFeature control. (In this case, the 'move' callback).
> >
> > Good. Now I also need to handle 'mouseout' events, and I cannot find
> > an appropriate callback for mouseout...
>
> I just figured that using the SelectFeature control with the 'move'
> callback isn't the same as using registerEventCallback() with
> 'mouseover' as I used to do. Indeed, when using SelectFeature with
> 'move' the callback is called each time the mouse pointer starts
> moving on the feature. I don't want that. I want an event on
> 'mouseover' and another one on 'mouseout', not tons of events if the
> mouse pointer moves on the feature.
Christopher,

I changed my application code as follows to define mouseover and
mouseout callbacks:

        var ctl = new OpenLayers.Control.SelectFeature(
                pointLayer,
                { callbacks:
                        {
                                'over': mouseoverCallback,
                                'out': mouseoutCallback
                        }
                }
        );
        ctl.handler.mouseover = function(evt) {
                OpenLayers.Handler.Select.prototype.select.call(ctl.handler, 'over', evt);
        };
        ctl.handler.mouseout = function(evt) {
                OpenLayers.Handler.Select.prototype.select.call(ctl.handler, 'out', evt);
        };


and it works good :-)

However, I think these callbacks should be defined in the OpenLayers
lib - it's a bit tough to put that burden on the user, isn't it?

See attached patch.

Index: /home/elemoine/workspace/openlayers/lib/OpenLayers/Handler/Select.js
===================================================================
--- /home/elemoine/workspace/openlayers/lib/OpenLayers/Handler/Select.js
   (revision 2816)
+++ /home/elemoine/workspace/openlayers/lib/OpenLayers/Handler/Select.js
   (working copy)
@@ -62,6 +62,22 @@
     mouseup: function(evt) {
         return this.select('up', evt);
     },
+
+   /**
+    *
+    * @param {Object} evt
+    */
+   mouseover: function(evt) {
+       return this.select('over', evt);
+   },
+
+   /**
+    *
+    * @param {Object} evt
+    */
+   mouseout: function(evt) {
+       return this.select('out', evt);
+   },

     /**
      * Capture double-clicks.

--
Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : [hidden email]
http://www.camptocamp.com

_______________________________________________
Dev mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/dev

patch.txt (1K) Download Attachment