[OpenLayers-Users] Mouse Drag Coordinates

Dave Thomas davidt at integeo.com
Thu Oct 29 21:23:14 EDT 2009


Hi Everyone,


Hi have what I though would be a simple task but its proving to be a little
more frustrating than I anticipated.

What I need to do is get the coordinates for pan events so that I know the
coordinates of when the drag started and when it ended. The logical way to
do this as far as I thought was to listen for the mousedown (or movestart)
and mouseup (or moveend) events and get the coordinates from there. Its not
behaving the way I anticipated though. I've tried a whole bunch of different
ideas - four of which I'll list here. Surely one of these is close.  I think
the first two are the closest.

I'd very much appreciate any input that may help.

Many Thanks

Dave


Method 1. Not all Events are recevied and of the ones that are I can't get
the coordinates from all of them.

click: yes
mousemove: yes
mouseup: yes
mousedown: no
movestart: yes - but coordinates recevied are NAN
moveend: yes - but coordinates received are NAN


   var options =
   {   
       ... other settings....

      eventListeners: {
         "movestart": doEvent
      }
   };

   function doEvent(event) {
      var obj = this.events.getMousePosition(event);
      alert(obj);
    }


Method 2. Same results as Method 1


   map.events.register("mousemove", map, function(e) {
      var position = this.events.getMousePosition(e);
      alert(position);
   });




Method 3. Clicks are called but not mousedowns.


   OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
      defaultHandlerOptions: {
         'single': true,
         'double': false,
         'pixelTolerance': 0,
         'stopSingle': false,
         'stopDouble': false
      },

      initialize: function(options) {
         this.handlerOptions = OpenLayers.Util.extend(
         {}, this.defaultHandlerOptions
            );
         OpenLayers.Control.prototype.initialize.apply(
            this, arguments
            );
         this.handler = new OpenLayers.Handler.Click(
            this, {
            'click': this.doClick,
            'down': this.doDown,
            'mousedown': this.doMouseDown
         }, this.handlerOptions
            );
      },

      doClick: function(e) {
         alert('click');
      },
      doDown: function(e) {
         alert('down');
      },
      doMouseDown: function(e) {
         alert('mouseDown');
      }
   });


Method 4.  Callbacks are only received if Navigation is deactivated.


   OpenLayers.Control.Drag = OpenLayers.Class(OpenLayers.Control, {
       defaultHandlerOptions: {
           stopDown: false
       },

       initialize: function(options) {
           this.handlerOptions = OpenLayers.Util.extend(
               {}, this.defaultHandlerOptions
           );
           OpenLayers.Control.prototype.initialize.apply(
               this, arguments
           );
           this.handler = new OpenLayers.Handler.Drag(
               this, {
                   'down': this.doDown,
                   'up': this.doUp,
                   'move': this.doMove,
                   'done': this.doDone
               }, this.handlerOptions
           );
       },

       doDown: function(e) {
           alert('down');
       },
      doUp: function(e) {
           alert('up')
      },
      doMove: function(e) {
           alert('move');
       },
      doDone: function(e) {
           alert('done');
       }
   });


-- 
View this message in context: http://n2.nabble.com/Mouse-Drag-Coordinates-tp3916580p3916580.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20091029/96c08efc/attachment.html


More information about the Users mailing list