OpenLayers OpenLayers

Ticket #1034 (closed bug: fixed)

Opened 2 years ago

Last modified 2 years ago

OpenLayers.Util.pagePosition regression

Reported by: crschmidt Assigned to:
Priority: minor Milestone: 2.5 Release
Component: Util Version: 2.5 RC3
Keywords: Cc:
State:

Description

using 2.5RC3 I have a problem in the above mentioned function, whereas this 
works fine in version 2.4. The problem is only in IE.                       
                                                                            
The error occurs in the following line of getStyle (style is null or not an 
object):                                                                    
                                                                            
var value = element.style[OpenLayers.String.camelize(style)];               
                                                                            
If I change the following line (back to its 2.4 equivalent):                
                                                                            
if(element == document.body) {                                              
                                                                            
to:                                                                         
                                                                            
if(element.offsetParent == document.body) {                                 
                                                                            
it works fine again.                                                        

Date: Tue, 25 Sep 2007 13:11:30 +0200, Subject: [OpenLayers-Dev] problem in OpenLayers.Util.pagePosition

Attachments

pagePosition.patch (1.4 kB) - added by crschmidt on 10/03/07 15:35:58.

Change History

09/30/07 16:15:32 changed by crschmidt

10/03/07 07:12:43 changed by openlayers

The HTML is basically this:

http://www.rijkswaterstaat.nl/apps/geoservices/rwsnl/index.html?

The error happens when you click in the custom zoombar. This website uses 2.4 though right now, but I've tested with 2.5RC3 on our development machine.

So basically this part of the HTML:

<div id="slider_m"><a href="#" onclick="zoomOut();return false;"><img src="data/slider_minus.gif" alt="Uitzoomen" title="Uitzoomen" border="0" /></a></div> <div id="slider">

<div id="slidercurrentzoom"><img src="data/slider.gif" alt="slider" /></div>

</div>

which has associated css in style.css.

Then the javascript is in: http://www.rijkswaterstaat.nl/apps/geoservices/rwsnl/_js/geotool.js

mainly: function divClick(evt) {

zoomStopHeight = document.getElementById('slidercurrentzoom').offsetWidth+1; if (OpenLayers.Event.isLeftClick(evt)) return; var y = evt.xy.x; var top = OpenLayers.Util.pagePosition(evt.object)[0]; var levels = Math.floor((y - top)/zoomStopHeight); if (map) {

if (levels == 0) map.zoomToMaxExtent(); else

map.zoomTo(levels);

} OpenLayers.Event.stop(evt);

}

Chris, if you need a clearer trimmed-down example, let me know.

10/03/07 15:17:41 changed by crschmidt

evt.object is the JS object that the events are registered on -- *not* a DOM element.

in your particular code, you create your events like:

new OL.Events(this, ...)

Which means that evt.object is null.

The thing you want to call pagePosition on is evt.*element*, which is a DOM element that the event is registered on.

I'm not really sure how the code could have worked before -- it seems like it probably would have just always returned 0,0. However, the fact that this throws an error now is a regression, and we'll fix it -- but you should be aware that this function is probably not doing what you think it is (and change your application appropriately).

10/03/07 15:35:58 changed by crschmidt

  • attachment pagePosition.patch added.

10/03/07 15:50:22 changed by crschmidt

  • keywords set to review.

Patch makes pagePosition way more paranoid -- probably even more so than it needs to be, but after a couple loops through the while loop, it seems like it's possible something else could blow up, so I'm just going the 'better safe than sorry' route to get things going for 2.5.

We should fix this in 2.6

10/03/07 16:11:37 changed by euzuro

  • keywords changed from review to commit.

Thanks for the detailed bug report, bart and for the great sleuthing on this one, cr5. good patch all tests pass ie6/ff. please commit, mark pullup.

10/03/07 16:16:01 changed by crschmidt

  • keywords changed from commit to pullup.

10/03/07 16:16:23 changed by crschmidt

10/03/07 20:27:17 changed by crschmidt

  • keywords deleted.
  • status changed from new to closed.
  • resolution set to fixed.

(In [4794]) Pull up most of the changes for what will be 2.5RC4:

  • Clone on WMS/MS Untiled, 4760:4761 (Closes #1013)
  • serviceVersion on TMS, 4720:4721 (Closes #1023)
  • W3CGeo in Format.GeoRSS, 4768:4769, 4778:4779 (Closes #1024)
  • GeoJSON Draft4 Update, 4769:4770 (Closes #1028)
  • pagePosition Regression 4782:4783, (Closes #1034)
  • example changes 4691:4692 (Closes #1040)
  • WFS missing registerTileListener 4759:4760 (Closes #1045)
  • Yahoo API to stop dragging 4792:4793 (Closes #1052)