[OpenLayers-Dev] this.events is null error on map.destroy()

Christopher Schmidt crschmidt at metacarta.com
Fri Dec 19 08:17:44 EST 2008


On Fri, Dec 19, 2008 at 05:00:33AM -0800, cjwhitmore wrote:
> 
> I've an openlayers (2.7) application where I would like to change the map
> projection depending on the zoom level. 
> As a test I change from EPSG:900913 to EPSG:4326.
> 
> To achieve this I destroy the map and then re-initalise the map adding the
> different options.
> I have attached an event on the zoomend of the map which is where the
> destroy and re-initalise takes place. 
> 
> Although it does work I get the error message this.events is null in FFOX
> error console. 
> 
> I've done a test where I don't destroy the original map, and so the number
> of maps grows, but I know longer get the error message. So the error does
> seem to come from destroying the map with an event attached to it. I have
> tried unregistering the event first but the application still errors.
> 
> I add the event using the following:
> 
> map1.events.register('zoomend', this, function(){
> 				testSwap();
> 			});

This is not correct. Instead, it should be ",this, testSwap". What you
are doing here is creating an anonymous function, which you can't refer
to later.

> and then in testSwap() I remove the event using the following:
> map1.events.unregister('zoomend',this, testSwap);

If you change the above, this should work, but I can't be sure this is
actually your problem.

Can you share the line number that the error happens on, in a
non-singlefile build? What function it's being called from is important
to solving the problem.


Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Dev mailing list