[OpenLayers-Dev] [OpenLayers-Users] associating events to geometries

Eric Lemoine Eric.Lemoine at camptocamp.com
Tue Mar 20 07:36:31 EDT 2007


On 3/19/07, Eric Lemoine <Eric.Lemoine at camptocamp.com> wrote:
> On 3/19/07, Eric Lemoine <Eric.Lemoine at camptocamp.com> wrote:
> > On 3/19/07, Christopher Schmidt <crschmidt at metacarta.com> 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 : eric.lemoine at camptocamp.com
http://www.camptocamp.com
-------------- next part --------------

Property changes on: /home/elemoine/workspace/openlayers
___________________________________________________________________
Name: svn:ignore
   + .project


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.


More information about the Dev mailing list