기본적으로 숨겨진 하나의 요소 (# hidden-element)가 있습니다. 버튼 (# btn-toggle)을 클릭하면이 요소가 표시됩니다. 지금은 모든 것이 좋습니다. 요소가 실제로 나타나지만 처음 버튼을 클릭하면지도가 표시되지 않습니다. 그런 다음 요소를 숨기려면 클릭하고, 두 번째로 숨겨진 요소를 표시하려면 다시 클릭하십시오. 이제지도가 나타납니다.숨겨진 요소에서 Gmaps를 시작하는 방법
내 질문은지도가 처음으로 표시 될 수있는 방법 (지도를 초기화해야하는 것 또는 그와 비슷한 것)을 어떻게 표현할 수 있으며 맵 객체를 삭제할 수 있습니까? 그리고 심지어 필요한지도 객체를 파괴하고 있습니까?
$(document).ready(function(){
// function for showing the map with markers - gmaps4rails gem
function showMap(){
var handler = Gmaps.build('Google');
handler.buildMap({ internal: {id: 'multi_markers'}}, function(){
var markers = handler.addMarkers([
{ lat: 43, lng: 3.5},
{ lat: 45, lng: 4},
{ lat: 47, lng: 3.5},
{ lat: 49, lng: 4},
{ lat: 51, lng: 3.5}
]);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
});
}
// this will hide the element when document is ready
$("#hidden-element").hide();
// if I click on button with ID btn-toggle, element will shows up or hide
$("#btn-toggle").click(function(){
if ($('#hidden-element').is(':hidden')){
// is necesarry to have condition and check if element is hidden or visible?
} else if ($('#hidden-element').is(':visible')){
// element is hidden? Show it!
showMap();
}
$("#hidden-element").toggle(1000);
});
});
숨겨진 요소 Google지도가 표시되지 않았습니다.지도를 표시하기 위해 요소를 표시 할 때지도를 다시 만들어야합니다 .. – scaisEdge
@scaisEdge Ok.하지만 이것은 두 번째 질문에 대한 답변 일 것입니다. 먼저지도를 클릭 한 후지도가 표시되는지 확인해야합니다. 어쨌든, 당신의 대답에 감사드립니다. – Boomerange
지도를로드 할 시간과 관련이 없는지 확인하십시오. – scaisEdge