0

在我的应用程序中,我使用的是 google 的 google map api v3。当我打开地址面板时,我想移动我的地图控件,但是当我尝试在地图上重绘控件时,地图控件没有移动。我想像谷歌地图一样转移所有地图控制。出于演示目的,请访问https://maps.google.co.in/并搜索酒店或其他任何内容,然后隐藏侧面地址面板。在那里您可以看到地图控件总是将表单边缘移动到面板边缘。我想像这样改变我的地图控件。请提供任何解决方案以在地图上移动我的控件,例如谷歌地图。

4

1 回答 1

0

您可以尝试做的是将您的地图margin放在左边一点,当您关闭地址面板时,将其删除margin并更新地图。

所以像:

<div id="map" style="width: 400px; height:400px; margin-left:100px"></div>
<a href="#">Expand</a>

<script>
    var map = new google.maps.Map($('#map').get(0));
    map.setCenter(new google.maps.latLng(40.736852, -74.002748));
    map.setZoom(12);

    var o = new google.maps.OverlayView();
    o.draw = function() {}
    o.setMap(map);

    $('a').on('click', function(){
        // Remove margin
        $('#map').css('marginLeft','0px');
        // Get current position in pixels on the map
        var current = o.getProjection().fromLatLngToContainerPixel(map.getCenter());
        // Set position to current - to margin-left.
        map.setCenter(o.getProjection().fromContainerPixelToLatLng({x:current.x - 100, y:current.y}));
    });
</script>
于 2013-08-30T18:21:53.493 回答