Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am working on an application that renders land parcels from PostGIS as polygons in Leaflet. I have an event handler set for 'viewreset' on the map:

this.leaflet_map.on('viewreset', this.viewport.regenerate, this.viewport);

The this in this case is an object I've created, called pt_map. viewport is an object I've created to wrap the methods for regenerating the view based on the current map bounds. My code works on initial load, as well as on panning the map. However, when I zoom in or out, I get the following error in line 4842 of leaflet-src.js:

Uncaught TypeError: Cannot call method 'latLngToLayerPoint' of null

Any ideas? My full code is available at

share|improve this question

try wrapping the function you call in a closure

this.leaflet_map.on('viewreset', function(e){this.viewport.regenerate(e)}, this);

it's vastly more complex than what I'm about to say but as a general rule of thumb it's a bad idea to use a function with a dot in it as an argument to something else without using a closure.

share|improve this answer
check the scope of this inside of the anonymous function. It may not mean what you think it means. – raykendo May 23 '13 at 13:46
my bad especially as my answer was telling him not to do that, fixed the typo. – Calvin May 25 '13 at 0:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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