javascript - google map api 调整 map 大小

标签 javascript css google-maps google-maps-api-3

我的网站上有一张完整的谷歌地图,点击一个标记,左侧的面板会弹出。问题是我的 map 大小仍然相同,其中面板覆盖了一半。

我有一个代码可以让所选标记居中,并在左侧面板弹出后调整 map 大小以适应新窗口,但它似乎不起作用:

function initialize() {

    var center = new google.maps.LatLng(XXXXXX, XXXXXXX);

    var map = new google.maps.Map(document
    .getElementById('MAP'), {
        zoom : 13,
        minZoom: 5,
        center : center,
        styles : googleStyle,
        mapTypeId : google.maps.MapTypeId.ROADMAP
    });

    var markers = [];
    var infoBubble = new InfoBubble({
        map: map,
        padding: 10,
        arrowPosition: 30,
        arrowSize: 10,
        backgroundColor: 'white',
        borderColor: 'white',
        borderRadius: 4,
        arrowStyle: 2,
        maxWidth: 250,
        hideCloseButton: true,
    });

    Some more codes related to marker...

    google.maps.event.addListener(markers[i], 'click', function(e) {

        Some more codes related to marker...

        // THIS I THINK IS THE ONE TO RESIZE THE MAP
        var latLngAdjust = new google.maps.LatLng(csCoordinateLat, csCoordinateLng + 0.00018);
        layoutV.layout.open('west');   // THE LAYOUT THAT WILL POP OUT

        window.setTimeout(function() {
            map.setZoom(17);
            map.panTo(latLngAdjust);  // THIS I ASSUME TO RESIZE THE MAP AND CENTER THE MARKER CHOSEN
        }, 300);
    }
}

有人知道为什么 map 不调整大小,而是面板只是放在 map 的顶部吗?

最佳答案

点击后添加

var resize=document.getElementId('map').style;
resize.width = '50%';//put your desire width
//other option here

关于javascript - google map api 调整 map 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25131571/

相关文章:

javascript - 脚本 438 : Object doesn't support property or method 'circular'

javascript - 在新窗口中使用 d3.js

javascript - 将我的数据 json 放入其他文件中并将其调用到我的 Controller 中

html - 页脚出现在内容区域

javascript - 使用 markercluster 时从 map 标记中删除标签

javascript - 如何在asp.net中使用jquery方法

javascript - 通过 JavaScript 将两个按钮添加到一个 div

ASP.NET MVC 要求我重新验证 PNG 文件而不是 GIF 或 JPEG

google-maps - 即使设置正确,Google map InfoWindow 宽度也会被覆盖

android - 每 1 分钟从服务器获取的 Gps LatLong 在 map 中显示为标记。但是标记正在复制