Issue with displaying full screen Google map within a large modal in Bootstrap 4

I successfully integrated a Google map into a large modal using Bootstrap 4. However, I encountered an issue where the map would not display when clicking the fullscreen button within the modal. I am struggling to find a solution for this problem. How can I fix it?

Before: https://i.sstatic.net/YkyAk.png
(source: image.ibb.co)

After:

Here is my JavaScript code:

$(document).ready(function() {
var marker, i;
var markers=[];
function load_map(){
  if (typeof google === 'object' && typeof google.maps === 'object') {

    var myLatLng = new google.maps.LatLng(<?=$row->lat?>,<?=$row->lon?>);

    map = new google.maps.Map(document.getElementById('map'), {
      zoom: 20,
      center: myLatLng,
      fullscreenControl: true,
      scaleControl:true,
      streetViewControl:true,
      mapTypeId: google.maps.MapTypeId.HYBRID
    });

    infowindow = new google.maps.InfoWindow();

    //set markers
    var locations=<?=json_encode($kordinat)?>;
    for (i = 0; i < locations.length; i++) { 
      marker = new google.maps.Marker({
        animation: google.maps.Animation.DROP,
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map,
        icon: {
          url:base_url+'assets/base/images/marker_black.png'
        }
      });
      markers.push(marker);
    }
    //target marker
    marker = new google.maps.Marker({
        animation: google.maps.Animation.DROP,
        position: myLatLng,
        map: map
    });
    markers.push(marker);

    var markerCluster = new MarkerClusterer(map, markers,{imagePath: base_url+'assets/base/images/m'});
    map.setCenter(myLatLng);

  }else{
  $('#show-map').slideDown();
  $('#map').slideUp();
     alert('Tidak dapat memuat peta ! Periksa koneksi internet !');
  }
}

$('#show-map').click(function(){
    $(this).slideUp();
    $('#map').slideDown();
    setTimeout(function(){load_map()}, 1000);
});});

This is my HTML code:

<div class="modal fade modal-3d-slit show" id="modal-detail" aria-labelledby="exampleModalPrimary" role="dialog" tabindex="-1"><div class="modal-dialog modal-lg">
<div class="modal-content">
  <div class="modal-header">
      <div class="ribbon ribbon-corner ribbon-info ribbon-reverse">
        <a href="#" data-dismiss="modal">
          <span class="ribbon-inner"><i class="icon md-close" aria-hidden="true"></i></span>
        </a>
      </div>
      <h4 class="modal-title"><span class="icon md-account-circle"</span>Detail Izin</h4>
    </div>
  <div class="modal-body"><style type="text/css">li.list-group-item:hover{background: #eeeeee}</style>
    <div class="nav-tabs-animate nav-tabs-inverse nav-tabs-horizontal" data-plugin="tabs"><ul class="nav nav-tabs" role="tablist">
          <li class="nav-item" role="presentation"><a class="nav-link" data-toggle="tab" href="#tab-pemohon" aria-expanded="false">Pemohon</a></li>
            <li class="nav-item" role="presentation"><a class="nav-link active" data-toggle="tab" href="#tab-izin" aria-expanded="true">Izin</a></li>
          <li class="nav-item" role="presentation"><a class="nav-link" data-toggle="tab" href="#tab-persyaratan" aria-expanded="false">Persyaratan</a></li>
          <li class="nav-item" role="presentation"><a class="nav-link" data-toggle="tab" href="#tab-tindakan" aria-expanded="false">Riwayat Tindakan</a></li>
        </ul>

        <div class="tab-content">
            <div class="tab-pane animation-scale-up mt-10 active" id="tab-izin" role="tabpanel" aria-expanded="true">
              <table class="table table-hover"></table>
              <button type="button" class="btn btn-primary waves-effect waves-classic btn-block btn-lg" id="show-map"><i class="icon md-map"></i> Show Map</button>

              <div id="map" style="height: 400px; width: 100%;"></div>

          </div>
        </div>
    </div>
  </div>
</div>

Answer №1

Currently, I am working on a project that involves utilizing Esri's JS-mapping library instead of Google Maps within Bootstrap. My goal is to display the map in a modal while maximizing the available space. Working with JS maps can be tricky as it requires setting dimensions in pixels for the browser to properly render the map. In the past, this was necessary unless using 100% for both dimensions. It seems like when switching to full screen mode, the map loses its connection to the modal container.

To address this issue, I have implemented an iframe (id="mapiFrame") inside the modal-body div along with specific CSS styles to achieve a desired layout:

#mapiFrame {
  height: calc(80vh - 5px);
  width: calc(90vw - 5px);
}

.modal-dialog {
  max-width: none;
  max-height: none;
  margin: 2px;
  padding: 2px;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Experiencing issues while trying to initialize with the given function

Below is the function I am using in a JS file to initialize other parameters: $(document).bind("ready", initialize); When refreshing a page or visiting it for the first time, this function works well. However, if there is an ajax call on the page, the do ...

In the Bootstrap Grid system, all posts are aligned to the left side

I have created a gallery with Bootstrap in React.js. The posts are currently displayed using the bootstrap grid system, however, all posts appear on the left side and I am struggling to center them. Any ideas on how to achieve this? https://i.sstatic.net/ ...

Tips for utilizing the verticesNeedUpdate feature in threejs for refreshing the vertex positions of a 3D cube

let geometry = new THREE.BoxGeometry(500, 500, 500); scene.add(geometry); let edgesGeometry = new THREE.EdgesGeometry(geometry); scene.add(edgesGeometry); let material = new THREE.LineBasicMaterial({ color: 0xffffff, linewidth: 2 }); scene.add(material); ...

CORS blocking Axios POST request to Heroku causing a Network Error 503

Using the MERN Stack, everything was functioning correctly until modifications were made to the UI (such as relocating code to different components and altering styles). The issue lies with a specific POST request, while other requests that utilize Axio ...

The Redux store has been modified, yet the changes are not reflected in the

In my Posts.js component, I am mapping every object in the posts array. Within this function, I attempt to filter all notes that have the same post_id as the id of the current mapped post object and store them in a variable called filteredNotes. I then pas ...

Tips for refreshing captcha without the need to refresh the entire page

<img id="imgCaptcha" src="SandCaptcha.aspx?CHA=0azSeOdr7S7gTkFxtL6/5B6h2vj+naZnDR5jl/dvceoJHNXcooHfP2MkoWxPRVWvdK7NJHckH" style="height:60px;width:160px;"> (function() { 'use strict'; function refreshCaptcha() { document.querySe ...

What is the best way to send a JavaScript variable to PHP for storage in a WordPress database?

I am currently in the process of developing a star rating system within Wordpress and am looking to store the rating data in the Wordpress database. To achieve this, I have saved the star rating PHP code as a template within my Wordpress theme folder. Belo ...

Transforming numbers into arrays in JavaScript/TypeScript for Angular 7

What is the best way to convert the number 10 into an array in JavaScript? expected output: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] OR How can I transform the number 10 into the number of items within an array using JavaScript? ...

Ways to restart the random number generator in JavaScript

Just embarked on my first JavaScript project and I'm aiming to create a personalized slot machine. However, I've hit a roadblock - I can't figure out how to restart my program or the function for generating new random values repeatedly. Here ...

Troubleshooting problems with hosting create-react-app on IIS and Internet Explorer

Having some trouble setting up my React application that was built using the React Create App template. When trying to host it with IIS, I encountered some issues. The index.html main page seems to be loading fine, but the compiled JS file is not loading ...

jquery: displaying repeated divs on mouse hover - a tutorial

Let's say we have a div like this: <div class="y1"> <img src="i/o.png" /> </div> Also, we have this div for pre-loading: <!-- pre load --> <div class="p1" style="display:none"> <h5 class="ob">Title</h5> < ...

Obtain additional information to address concerns related to onZoom and onPan issues on the line

Attempting to enhance my Chart.js line chart by fetching more data or utilizing cached backup data during onZoom/onPan events has proven quite challenging. The original code base is too intricate to share entirely, but I will outline the approaches I have ...

Uploading files in React.js using Yii2 API

I am working with react.js (version 15) and I need to upload files using yii2 api. Here is my code: My component in react: import React, { Component } from 'react'; import Header from './Heaader'; /* global $ */ class New ...

How can I efficiently remove elements from the end of an array in Vue.js?

Is there a way to splice data starting from the back with a higher index? When clicking on the .delete div, how can I make it so the .image-box div deletes starting from the end? I need help implementing this feature in my code. Here is a snippet: < ...

The sequencing of AJAX calls on the server side may not necessarily match the order in which they were initiated on the client side

I am working on an ASP.NET MVC application that includes a JavaScript function within a view. Here is the code snippet: function OnAmountChanged(s, fieldName, keyValue, url) { console.log("Get Number: " + s.GetNumber()); console.log(" "); ...

Saving a complicated schema in Node using Mongoose fails to save or update when encountering an error

Greetings, I am facing challenges while trying to save a complex schema in MongoDB. const itemsSchema =new Schema({ cat: {type: String, required: true}, catItems: [{ items:{type: String}, isActive: {type: Boolean, default: true} }] }) ...

Targeting lightgallery.js on dynamically added elements in Javascript: The solution to dynamically add elements to

I am facing a challenge in targeting dynamically added elements to make them work with lightgallery.js. Take a look at the example below: <div id="animated-thumbs" class="page-divs-middle"> <!-- STATIC EXAMPLE --> ...

Tips for canceling an http request in angularjs when the requesting controller has exited its scope

Developed a custom angularjs application with ng-view for loading four different modules using route provider. Each module makes HTTP requests as shown below: var requestManager = { "locations": {}, "employees": {}, "items": {}, "templates ...

The function of React's useState is not available

https://i.sstatic.net/ltglP.png This error is new to me and I'm unsure why my code isn't working correctly. I noticed a similar example on the React.js Org website. Can someone please explain what's happening in my code? Any help would be ...

Including a unicode escape sequence in a variable string value

I'm struggling to find the right way to include a unicode escape in a dynamic string value to display emojis in React. My database stores the hexcode for the emoji (1f44d) I have set up a styled-component with the necessary css for rendering an emoj ...