javascript - Leaflet map freezing in bootstrap 3.0 modal -


i'm trying load map in bootstrap modal map appear partly, it's freezing can't select region. despite of using map.invalidatesize() problem still resisting. there make work in bootstrap modal or other kind of modal?

leaflet-modal

here code:

<script type="text/javascript">      var lbsconfig = {          url:'https://map.ghasedakbahar.ir:6443/arcgis/rest/services/iran/featureserver/0',          view: [35.6970, 51.4079],          mapid: 'map-id',          color: {              default: '#9ab9ff',              selected: '#ff0659'          }      };        var map = lbsmap();      lbsshownew(map, function (regions) {          var maxregions = 5;          var errregions = 'the number of areas more 5 areas';          if (regions.length > maxregions) {              alert(errregions);              return;          }          jquery('#regions').val(regions.join(','));          jquery('#count-selected').html(regions.length);      });        $('#mymap').on('show.bs.modal', function () {          settimeout(function () {              map.invalidatesize();          }, 10);      });    </script>
#map-id {          padding: 0;          width: auto;          height: 400px;      }
<!-- modal -->  <div class="modal fade" id="mymap" role="dialog" style="margin-top:70px">      <div class="modal-dialog">          <!-- modal content-->          <div class="modal-content font-yekan">              <div class="modal-header">                  <button type="button" class="close" data-dismiss="modal">&times;</button>                  <h4 class="modal-title">'sendsmsdetail'</h4>              </div>              <div class="modal-body" id="modal-body">                  <div id="map-id"></div>              </div>              <div class="modal-footer">                  <button type="button" class="btn btn-default" data-dismiss="modal">close</button>              </div>          </div>        </div>  </div>

i remember having same problem before. there lot of similar problem on internet , maybe 1 can :

leaflet map not showing in bootstrap 3.0 modal

i think happening that, when map created, container width/height `map-canvas' element has not yet been adjusted width/height of modal dialog. causes map size incorrect (smaller) should be.

you can fix calling map.invalidatesize(). work re-adjust width/height bounds of l.map's container.

you can automatically call hooking event bootstrap modal becomes shown.

$('#mymodal').on('show.bs.modal', function(){   settimeout(function() {     map.invalidatesize();   }, 10);  }); 

insert code javascript. when modal shown, map invalidate size. timeout because there may animation/transition time modal display , added dom.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

c# - Asp.net web api : redirect unauthorized requst to forbidden page -