Google map not filling modal popup

前端 未结 5 527
心在旅途
心在旅途 2021-01-14 10:46

I\'m using a modal popup when users click the map on this page here, which brings up a larger map with directions.

The map isn\'t filling the entire space however an

5条回答
  •  北荒
    北荒 (楼主)
    2021-01-14 11:35

    You can trigger a resize event on the map, after the modal is launched, which will cause it to resize to fit the dimensions of the containing div. From the documentation:

    Developers should trigger this event on the map when the div changes size

    // Add this at the bottom of the script which defines your map
    // It will trigger the resize event on the map after the modal has launched
    $('#myModal').on('shown', function () {
      google.maps.event.trigger(map, 'resize');
    })
    

    I think when you launch dev tools the window.onResize event is causing the resize event to be triggered on the map. You can prove this by detaching dev tools from the browser window before clicking your modal.

提交回复
热议问题