I am using Leaflet with jQuery Mobile and having an issue using the 'pageinit' events.
Here is the code:
$('#location').live('pageinit',function() {
//$(document).ready(function() {
var locLat = $('#location_lat').html();
var locLon = $('#location_lon').html();
var locPos = new L.LatLng(locLat,locLon);
var tiles = new L.TileLayer('http://{s}.
tile.openstreetmap.org/{z}/{x}/{y}.png', {attribution:'woot!'})
var locMarker = new L.Marker(locPos,{
icon: new dddIcon
});
map = new L.Map('mapd');
map.addLayer(tiles);
map.addLayer(locMarker);
map.setView(locPos,18,true);
//$('#mapd').css({'height':'302px'});
//map.invalidateSize();
});
I've attached a screenshot of what happens....the map shows one tile. If you pull the map over it renders....maybe a couple of more tiles but there are always gaps. The marker may or may not show up.
If I attach this to the $(document).ready() function, it works great.....but breaks, naturally, using links in jQuery mobile unless its accesed directly.
As you can see I have tried setting the map to render, then manually changing the height by one pixel, then running the invalidateSize method, which also does not work.
I can fix this by using rel=external on any links going to the location page but I really would rather have something that will make the map render in the container properly.
Any ideas or things I can try?