I've been having this problem, as well, but it sounds like our Jquery
Mobile pages are set up differently. I have a basic index.html page
with a couple of JQM "pages" using a navbar for navigation. The
content of one of those pages is a populates with a Leaflet map, but
breaks when using the navbar navigation with the Error "Error: Map
container is already initialized." Something about the way JQM loads
the content (ajax).
Seems like I've been able to fix this by intercepting using the
pagebeforechange event, and manually setting the correct "page".
For example:
$(document).bind('pagebeforechange', function(e, data) {
console.log("url: " + data.toPage);
if(typeof(data.toPage) !== 'string')
return;
//get the hashtag target
var hashParts =
$.mobile.path.parseUrl(data.toPage).hash.split('-');
var index = -1;
if(hashParts.length === 2)
index = parseInt(hashParts[1]);
var options = data.options;
if(hashParts[0] === "#map")
window.app.refreshMap (index, options);
else
return; // fall back to default behavior
e.preventDefault();
});
var app = refreshMap:function(){
$.mobile.changePage($("#map-page")); //the id of my jqm page
};