[OpenLayers-Users] Problem clicking on a map (OL-2.5) - RESOLVED

Christopher Schmidt crschmidt at metacarta.com
Tue Jun 10 10:36:59 EDT 2008


On Tue, Jun 10, 2008 at 10:31:49AM -0400, David R Robison wrote:
> I found the problem... On my page I have a fixed header and footer and a 
> client region with the style "overflow: scroll". The problem is in 
> getMousePosition:
> 
>    getMousePosition: function (evt) {
>        if (!this.element.offsets) {
>            this.element.offsets = 
> OpenLayers.Util.pagePosition(this.element);
>            this.element.offsets[0] += (document.documentElement.scrollLeft
>                         || document.body.scrollLeft);
>            this.element.offsets[1] += (document.documentElement.scrollTop
>                         || document.body.scrollTop);
>        }
>        return new OpenLayers.Pixel(
>            (evt.clientX + (document.documentElement.scrollLeft
>                         || document.body.scrollLeft)) - 
> this.element.offsets[0]
>                         - (document.documentElement.clientLeft || 0),
>            (evt.clientY + (document.documentElement.scrollTop
>                         || document.body.scrollTop)) - 
> this.element.offsets[1]
>                         - (document.documentElement.clientTop || 0)
>        );
>    },
> 
> The first conditional "caches" the offsets. However, if the client area 
> is scrolled, the new positions are not recalculated. If I comment out 
> the conditional, then everything works great. I'm not sure this is 
> clear... Any thoughts? David

If the position of the map within the page changes, call
'map.updateSize()' (which clears out the offsets). 

The offsets are cached for performance reasons -- though I'll admit that
that was originally done in the FF 1.0 series, and may no longer be
particularly important. If you could figure out a way to have the map
figure out when it has changed positions, and update the cache
accordingly, a patch would be great. 

> 
> Eric Lemoine wrote:
> >On Thu, Jun 5, 2008 at 6:18 PM, David R Robison
> ><drrobison at openroadsconsulting.com> wrote:
> >  
> >>We are having a pecular problem when clicking on a map. The map is on a
> >>large web page. If the page is scrolled partway down (not positioned at
> >>the top of the map), clicking on the map will return an XY position that
> >>is above the actual click. If we scroll the page back to the top, then
> >>the clicking works. We are using OL-2.5. Has anyone else experienced
> >>this?
> >>    
> >
> >No. Do you a public page where we can see that, or some code for
> >someone to reproduce?
> >
> >  
> >>Was it fixed in 2.6?
> >>    
> >
> >Dunno.
> >
> >  
> >>Thanks, David Robison
> >>    
> >
> >--
> >Eric
> >  
> 
> -- 
> 
> David R Robison
> Open Roads Consulting, Inc.
> 708 S. Battlefield Blvd., Chesapeake, VA 23322
> phone: (757) 546-3401
> e-mail: drrobison at openroadsconsulting.com
> web: http://openroadsconsulting.com
> blog: http://therobe.blogspot.com
> book: http://www.xulonpress.com/book_detail.php?id=2579
> 
> This e-mail communication (including any attachments) may contain 
> confidential and/or privileged material intended solely for the individual 
> or entity to which it is addressed.  If you are not the intended recipient, 
> you should immediately stop reading this message and delete it from all 
> computers that it resides on. Any unauthorized reading, distribution, 
> copying or other use of this communication (or its attachments) is strictly 
> prohibited.  If you have received this communication in error, please 
> notify us immediately.  
> 
> 
> 
> 

> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users


-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list