[OpenLayers-Dev] panning enhancements

Julien-Samuel Lacroix jlacroix at mapgears.com
Mon Jun 16 11:21:37 EDT 2008


Kudos to you! I confirm that this makes a difference in the navigation 
experience on my computer. The panMap is way much smoother.

I modified your page to add a scrollbar in the page and found some 
problems though. For examples the zoom with the mouse wheel seems to 
contain an offset when it's executed. I suppose we could have the same 
problem with full screen maps if we resize the window.

I made some test and by reseting the cached values once in while I fixed 
the issue. Here's what I've done. Note that it's not optimal and I did 
not go through the profiler to test this.

var mouseCacheTimeout = null;
OpenLayers.Events.prototype.clearMousePosition = function()
     this.element.lefttop = null;
     this.element.scrolls = null;
     this.element.offsets = null;
     mouseCacheTimeout = null;

OpenLayers.Events.prototype.getMousePosition = function (evt) {


     mouseCacheTimeout =
//    clearTimeout(mouseCacheTimeout);
//    mouseCacheTimeout =
//    setTimeout(this.clearMousePosition.bind(this),1000);

return new OpenLayers.Pixel(


Pierre GIRAUD wrote:
> Hello,
> Once again here are some thoughts about enhancements to the panning in
> OpenLayers.
> Some time ago, one user (Tono) complained about issues with panning
> being slow on old machines and proposed to fix this by modifying the
> panMap method and introduce a timeout so that map is moved every 25
> ms.
> http://trac.openlayers.org/ticket/1509
> I must admit that I also find that, in some cases, dragging the map is
> not as smooth as I would expect. In particular, when we want to put an
> OpenLayers map into a complex Ext layout, the map panning is often
> jerky, at least on my computer.
> By digging into it myself, I opened firebug and profiled the pan of a
> map whose div is intentionally put into a (relatively) complex HTML
> code. The profiler tells me that the most called method is
> getMousePosition with more than 50%. This is really huge, I think.
> I'm convinced that there could be something done and I feel confident
> with my first tests.
> Please take a look at
> http://dev.openlayers.org/sandbox/camptocamp/getmouseposition/examples/getmouseposition.html.
> In this example, I rewrote OL.Events.getMousePosition to avoid
> expensive calculations and cache some values. Indeed, in my opinion,
> scrollLeft/scrollTop and clientLeft/clientTop are relatively static.
> I also think that we have enough events available for window or
> document to manage modifications on those values if required.
> I launched the profiler again and getMousePosition is now the 8th or
> 9th most called method and takes only 3 or 4% of the process. This
> sounds better.
> Please give me feedbacks on this. I may be completely wrong, don't
> hesitate to yell at me if this is the case.
> Regards
> Pierre
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev

Julien-Samuel Lacroix

More information about the Dev mailing list