wayne-m
wayne-m

Reputation: 45

How do I change var map = L.mapbox.map on click (mapbox.js)

I have a base map set.

var map = L.mapbox.map('map', 'wmarci.i6n42nl5', {
    fullscreenControl: true,
    fullscreenControlOptions: {
    position: 'topleft'
  }
}).setView([38.8929,-100.0252], 4);

How do I change it to then #2012 is clicked it changed that variable?

The following,

$('#2012').click(function(){
    map = L.mapbox.map('map', 'wmarci.hao88g0d')
}); 

doesn't seem to be working...

Upvotes: 1

Views: 278

Answers (1)

Alcides Queiroz
Alcides Queiroz

Reputation: 9576

Once a map container is initialized, you'll have to remove this map in order to set another to the same container.

Try this:

$('#2012').click(function(){
    map.remove();//<<Here comes the magic!
    map = L.mapbox.map('map', 'wmarci.hao88g0d');
}); 

Upvotes: 1

Related Questions