Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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 https://github.com/CoherentLogic/ptarmigan/blob/experimental/web/ptarmigan/parcels/layers.js

Thanks much in advance! John W.

share|improve this question
add comment

1 Answer

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
1  
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
add comment

Your Answer

 
discard

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.