I am trying to zoom to a point in ArcGIS JavaScript API (3.9). I am doing this one of two ways, I am either grabbing a point feature from ArcGIS Server (10.1), or I am grabbing the center of a polygon and zooming to that.

I was getting an error "exception in animation handler for: onAnimate" when zooming to any point. I found here that adding a setTimeout() around your map.centerAndZoom() solves the problem. However, that was only for the point feature being brought back from the server.

The problem still persists when I try to get the center point of a polygon:

zoom to point code

I have tried both increasing and decreasing the timeout time, but I have not had any success. The map will seem to zoom to the location, but then immediate zoom back to its original location and then spit this error:

onAnimate error screenshot

I have found a little research done on "Cannot read property 'left' of undefined" and the most I could find is something about symbology - So, just to help out, here is the symbology as it is in ArcGIS Server:

  Simple Renderer:
           Style: esriSFSSolid 
           Color: [0, 0, 0, 0] 
                   Style: esriSLSSolid 
                   Color: [76, 230, 0, 255] 
                   Width: 1
 Transparency: 0 
 Labeling Info:

If anyone could shed some light on this problem, I would be grateful.

  • 1
    relying on a timeout to make something work may eventually result in troublesome bugs that are very difficult to reproduce. If you are zooming to a point feature that is requested from the server you must ensure that the zooming happens in an event handler that fires when that request is complete, instead of guessing how long the request will take.
    – tomfumb
    Dec 16 '14 at 16:43
  • 1
    sounds like a conflict with a popup opening. When clicking on a graphic, if a infoTemplate is associated with it then zooming at the same time can result in an Animation error Jan 28 '15 at 18:14

If you look at the documentation for the map.centerAndZoom function, you'll find that it requires both a point and a zoom level. Because it doesn't know how far to zoom in, it can't establish a "left" bound, "right" bound, or any bound. That is why it mentions the "left" property. Try this instead

setTimeout(function () {
    map.centerAndZoom(point, 12); // or some arbitrary number
}, 500);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.