none
The center property of map.getBounds() sometimes has an NaN for latitude or longitude RRS feed

  • Question

  • We've noticed that sometimes the center property of map.getBounds() has an NaN for latitude or longitude or both.

    Try here: https://geofeedia.com/mapbugcenterNaN.cshtml

    If you successfully recreate the issue, your view will show NaN log messages just below the map.

    This happens while the map is changing views, sporadically.  Sometimes, once the condition is hit, the center property will always have an NaN until the map is completely recreated using javascript.

    Can this issue be corrected?

    Thanks,

    Scott


    Monday, November 12, 2012 10:22 PM

Answers

  • Throttling the handler seems to stop the problem (at least on my machine).

    Try changing line 46 from:

    Microsoft.Maps.Events.addHandler(map, 'viewchange', function () {

    to

    Microsoft.Maps.Events.addThrottledHandler(map, 'viewchange', function () {

    and then add a small delay after the end of the anonymous function definition on line 53 - e.g 250ms:

                }, 250);

    Does that fix it for you?


    twitter: @alastaira blog: http://alastaira.wordpress.com/ | Pro Spatial with SQL Server 2012


    Wednesday, November 14, 2012 10:33 AM
    Moderator

All replies

  • Which browser are you seeing this in. I just spent the last 10 minutes testing in IE 7, 8, 9, and 10 and was unable to reproduce the issue no matter how fast I panned and zoom (getting weird looks from people sitting beside me due to the wild mouse movements :)

    http://rbrundritt.wordpress.com

    • Proposed as answer by Ricky_Brundritt Tuesday, November 13, 2012 9:19 AM
    • Unproposed as answer by Ricky_Brundritt Wednesday, November 14, 2012 9:59 AM
    Tuesday, November 13, 2012 9:18 AM
  • I couldn't seem to do it in Firefox 16.0.2 under Win7 either. Tried zooming/panning/going across the dateline etc.

    @scottkmitchell - can you recreate it on more than one machine?


    twitter: @alastaira blog: http://alastaira.wordpress.com/ | Pro Spatial with SQL Server 2012

    Tuesday, November 13, 2012 10:58 AM
    Moderator
  • Completely understand the weird looks.  Reproducing this makes me dizzy.  :)

    We're able to reproduce in just a few seconds of zooming and panning on every machine we've tried using Chrome.  There was a report of it from a Firefox user but we haven't been able to reproduce it with any Firefox version.

    Since a majority of our users are using Chrome and being able to access getBounds during the viewchange event is a critical feature of our app, we'd really like to help with a fix or a workaround.  

    Richard, if you can't reproduce, let me know and I'll record a short video.  Or I'd be happy to do some screen sharing to demonstrate.

    Thanks,

    Scott

    Wednesday, November 14, 2012 4:32 AM
  • I've now tested in latest versions of Firefox and Chrome without any luck of reproducing the issue. Not sure if a video would help. I'll pass this on to our development team for investigation to see if any of them can reproduce this issue.

    http://rbrundritt.wordpress.com

    Wednesday, November 14, 2012 9:50 AM
  • Ok, I have been able to reproduce in Chrome 23.0.1271.64 m under Win7 64bit, as shown below:

    It does seem Chrome-specific - despite some frantic arm-waving in IE and FF, I've not been able to reproduce in either of those.


    twitter: @alastaira blog: http://alastaira.wordpress.com/ | Pro Spatial with SQL Server 2012

    Wednesday, November 14, 2012 10:25 AM
    Moderator
  • Throttling the handler seems to stop the problem (at least on my machine).

    Try changing line 46 from:

    Microsoft.Maps.Events.addHandler(map, 'viewchange', function () {

    to

    Microsoft.Maps.Events.addThrottledHandler(map, 'viewchange', function () {

    and then add a small delay after the end of the anonymous function definition on line 53 - e.g 250ms:

                }, 250);

    Does that fix it for you?


    twitter: @alastaira blog: http://alastaira.wordpress.com/ | Pro Spatial with SQL Server 2012


    Wednesday, November 14, 2012 10:33 AM
    Moderator
  • Yep, that's it.  It's sporadic, and sometimes you get in a condition where every viewchange event fires with the NaN values.  It never resolves until the map is recreated from scratch.

    Our users are seeing this issue fairly often.  Is this something the dev team can look at?  I'll be happy to assist if they have questions.


    Wednesday, November 14, 2012 8:31 PM
  • Unfortunately, no, the throttled handlers won't work for us.  They do help work around the bug, but the reason we're using viewchange is to update the map as it changes, not with a delay of 250ms.  It's difficult to explain so try this example:

    https://geofeedia.com/geofeed.stream

    Click the "Add Stream" button then pan the map.  For each viewchange, the circle on the map is redrawn.  When the map's bounds are NaN, we can't draw the circle and it disappears.

    Our workaround, for now, is to use the map width & height along with getMetersPerPixel to determine the polygon for the circle.  It's a hack and we'd much rather have the NaN issue fixed.

    Wednesday, November 14, 2012 8:53 PM