javascript - 谷歌地图调整大小 css 显示无

标签 javascript jquery css

这个问题在这里被问过很多次了,就是谷歌地图显示不全。我的问题是:我使用航点在我的页面上触发 CSS3 动画。在带有 Google map 的页面上,我将 CSS 设置为 display: none; 直到到达航路点。这会导致 Google map 崩溃。

根据我在 Stack Overflow 上的研究和搜索,修复是这样的(如果我错了请纠正我):

google.maps.event.trigger(map, 'resize');

这是我从其他在线开发人员那里获得的 JavaScript 代码,我不知道将 Google map 调整大小触发器放在哪里?:

var directionDisplay;
var directionsService = new google.maps.DirectionsService();
function initialize() {
    var latlng = new google.maps.LatLng(-33.8333406,18.6470022);
    directionsDisplay = new google.maps.DirectionsRenderer();
    var myOptions = {
        zoom: 8,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        mapTypeControl: false
    };
    var map = new google.maps.Map(document.getElementById("map"),myOptions);

    directionsDisplay.setMap(map);
    directionsDisplay.setPanel(document.getElementById("directionsPanel"));
    var marker = new google.maps.Marker({
        position: latlng, 
        map: map, 
        title:"Get Directions"
    }); 
}
function calcRoute() {
    var start = document.getElementById("routeStart").value;
    var end = "-33.8333406,18.6470022";
    var request = {
        origin:start,
        destination:end,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
    directionsService.route(request, function(response, status) {
        if (status == google.maps.DirectionsStatus.OK) {
            directionsDisplay.setDirections(response);
        } else {
            if (status == 'ZERO_RESULTS') {
                alert('No route could be found between the origin and destination.');
            } else if (status == 'UNKNOWN_ERROR') {
                alert('A directions request could not be processed due to a server error. The request may succeed if you try again.');
            } else if (status == 'REQUEST_DENIED') {
                alert('This webpage is not allowed to use the directions service.');
            } else if (status == 'OVER_QUERY_LIMIT') {
                alert('The webpage has gone over the requests limit in too short a period of time.');
            } else if (status == 'NOT_FOUND') {
                alert('At least one of the origin, destination, or waypoints could not be geocoded.');
            } else if (status == 'INVALID_REQUEST') {
                alert('The DirectionsRequest provided was invalid.');                   
            } else {
                alert("There was an unknown error in your request. Requeststatus: \n\n"+status);
            }
        }
    });
}

这是触发显示的路点 jquery 代码: block

// Studio Page
jQuery('.studio-page').waypoint(function() {
jQuery('.kickass-studio').addClass( 'show animated bounceInLeft' );
jQuery('.location').addClass( 'show animated bounceInRight' );
jQuery('.geo-address').addClass( 'show animated bounceInDown' );

},
{
offset: '10%'
});

最佳答案

只需在初始化函数的末尾添加它.... 此外,您还需要将 map 对象保存在变量中,并在使谷歌地图的 css 显示时再次调用调整大小事件:使用此 map 对象 block

关于javascript - 谷歌地图调整大小 css 显示无,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23868251/

相关文章:

css - 悬停效果在多选上无法正常工作

jquery - 多维菜单悬停问题

javascript - 使用 forEach 循环遍历 Array(n),未定义值的数组

jQuery 与 find() 相反

javascript - 使用值选择选择框的选项

javascript - jQuery用存储在各种变量中的数据动态替换div的内容

CSS calc() 与多个单位相乘

javascript - NodeJS - 从多级对象数组中提取数据

javascript - 向下滚动时隐藏的粘性标题 + 固定进度条

javascript - 用 BR 标签替换 SPAN 标签内的空格