I'm having a problem that has been asked by various questions but I haven't been able to solve it through the method that has been provided in various answers.
My issue is that tiles are not rendering correctly inside a jQuery Modal that included a Leaflet map generated through a rails application.
The previous questions (such as this Leaflet map not showing properly in bootstrap 3.0 modal) have suggested using invalidateSize(); method through a jQuery function after the modal is shown.
My application differs to the question in that I'm using the jQuery Modal library.
I'm currently trying with something like this
<% @clinics.each_with_index do |clinic, index| %>
<div class="link-to-map">
<a href="#ex1" rel="modal:open" id="to-modal">
<span class="glyphicon glyphicon-arrow-right"></span>
</a>
</div>
<div id="ex1" class="map-modal" style="display:none;">
<div class="row">
<div class="col-sm-7">
<div id="mapid-<%= index %>" class="mapas-modal">
</div>
</div>
</div>
<% end %>
</div>
<script>
var mymap = L.map('mapid-<%= index %>').setView([19.419444, -99.145556], 13);
L.tileLayer('https://api.mapbox.com/styles/v1/eclarkgd/ciwfc2mce004b2plkmujdb3no/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoiZWNsYXJrZ2QiLCJhIjoiY2lraXVvaWlzMDUzN3RubTZ2OHBscWRxciJ9.ikI5wjFM2RNcoOrssqx2Zg', {
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
maxZoom: 18,
}).addTo(mymap);
var marker = L.marker([19.419444, -99.145556]).addTo(mymap);
marker.bindPopup("<%= clinic.institucion %>").openPopup();
</script>
<script>
$('#to-modal').click(function() {
setTimeout(function() {
mymap.invalidateSize();
alert("corre corre");
}, 1000);
});
</script>
Still my tiles are not rendering correctly within the div. I've used this method previously in an application that used the traditional bootstrap modal and it worked
Any ideas would be greatly appreciated.
**Edited to add the modal opening link