Мой Отзывчивый [Solution] Google Map в Фонд 4 Modal
JS
Создать внешний JavaScript-файл (т.е. MyMap.JS) со следующим кодом
google.maps.visualRefresh = true; //Optional
var respMap;
function mymapini() {
var mapPos = new google.maps.LatLng(-0.172175,1.5); //Set the coordinates
var mapOpts = {
zoom: 10, //You can change this according your needs
disableDefaultUI: true, //Disabling UI Controls (Optional)
center: mapPos, //Center the map according coordinates
mapTypeId: google.maps.MapTypeId.ROADMAP
};
respMap = new google.maps.Map(document.getElementById('mymap'),
mapOpts);
var mapMarker = new google.maps.Marker({
position: mapPos,
map: respMap,
title: 'You can put any title'
});
//This centers automatically to the marker even if you resize your window
google.maps.event.addListener(respMap, 'idle', function() {
window.setTimeout(function() {
respMap.panTo(mapPos.getPosition());
}, 250);
});
}
google.maps.event.addDomListener(window, 'load', mymapini);
$("#modalOpen").click(function(){ //Use it like <a href="#" id="modalOpen"...
$("#myModal").show(); //ID from the Modal <div id="myModal">...
google.maps.event.trigger(respMap, 'resize');
});
HTML
Добавьте следующий код перед тегом:
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script src="js/mymap.js"></script>
Добавьте к этому коду модального:
<div id="mymap"></div>
CSS
Добавьте к таблице стилей:
#mymap { margin: 0; padding: 0; width:100%; height: 400px;}
Я искал какое-то время, чтобы получить это решение, по-видимому GoogleMaps не нравится, если и ширина и высота в процентах. Но ваше решение действительно работает, так или иначе! cheers – Martin