[OpenLayers-Users] combining handlers, or hover + select

Jesse V Griffis jvgriffis at gmail.com
Tue Feb 3 09:02:12 EST 2009


Thanks Eric,

I wasn't sure if dumping a bunch of code to the list would be useful.

Essentially, I just copied the Hover Control from the example page
(http://openlayers.org/dev/examples/hover-handler.html) and tried to
copy the stuff from the SelectFeature Control (in the source).

Testing it, I know the hover/pause part of this is working, but I
can't figure out how to apply the selection piece.  Please don't laugh
too hard:

OpenLayers.Control.Hover = OpenLayers.Class(OpenLayers.Control,
  {
    layer: null,

    isPaused: false,

    defaultHandlerOptions: {
    'delay': 1000,
    'pixelTolerance': 1,
    'stopMove': false
    },

    initialize: function(layer, options)
    {
      this.layer = layer;
      this.handlerOptions = OpenLayers.Util.extend(
        {}, this.defaultHandlerOptions
      );
      OpenLayers.Control.prototype.initialize.apply(
        this, arguments
      );

      this.handlers = {
        feature: new OpenLayers.Handler.Feature(
          this, this.layer, { 'over': this.over}, {}
        ),
        hover: new OpenLayers.Handler.Hover( this,
          {'pause': this.onPause, 'move': this.onMove}, this.handlerOptions
        )
      }
    },

    draw: function() {
      return false;
    },

    activate: function() {
      this.handlers.feature.activate();
      this.handlers.hover.activate();
    },

    deactivate: function() {
      this.handlers.feature.deactivate();
      this.handlers.hover.deactivate();
    },


    onPause: function(evt) {
      this.isPaused = true;
    },

    onMove: function(evt) {
      this.isPaused = false;
    },

    over: function(feature) {
      if ( this.isPaused)
      {
        console.log(feature);
      }
    }
  });



On Tue, Feb 3, 2009 at 1:03 AM, Eric Lemoine <eric.c2c at gmail.com> wrote:
> Hi
>
> It is hard to help you without seeing actual code. Feel free to come
> back to the list with your code.
>
> Cheers,
>
> Eric
>
> 2009/2/3, Jesse V Griffis <jvgriffis at gmail.com>:
>> Greetings,
>>
>> I can successfully use the hover examples to create a "Hover" Control
>> that uses the Hover handler to pop up info when you pause in one place
>> long enough.  I can successfully use the SelectFeature Control to
>> click and display info about Vectors.
>>
>> What I can't figure out is how to combine them, and make a pause on
>> the map select the feature under the mouse.  It's frustrating to get
>> so close and yet be so far.
>>
>> Does anyone have an example of this?
>>
>> Thanks,
>>
>> Jesse
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>>
>



More information about the Users mailing list