【问题标题】:Google Maps: Calculate position not covered by div overlay谷歌地图:计算div覆盖未覆盖的位置
【发布时间】:2016-09-06 20:26:24
【问题描述】:

以下情况:

  • 我的 google maps div 占据了整个屏幕(100% 宽度和高度)
  • 一个按钮可以切换占据地图右侧的 div 叠加层(侧边栏)的可见性
  • 地图上有一个标记,可以隐藏在白色覆盖层下方
  • 为避免标记被隐藏,我想将地图向右移动,以便标记在框左侧黄色区域的中心可见
  • 页面基于 bootstrap+angular

碰撞复选框与标记不是问题,但我无法让它相应地移动地图。

这是我尝试过的:

google.maps.event.addListenerOnce($scope.map, "projection_changed", function() {
    $scope.projection = $scope.map.getProjection();
});

var sidebar = document.getElementById('sidebar');
var rect = sidebar.getBoundingClientRect();

var marker = $scope.mainmarker.getPosition();
marker = $scope.projection.fromLatLngToPoint(marker); 
marker.x = rect.left / 2;
marker = $scope.projection.fromPointToLatLng(marker);
$scope.map.setCenter(marker);

但据我所见,地图移动得太远了。

【问题讨论】:

    标签: javascript twitter-bootstrap google-maps google-maps-api-3 google-maps-markers


    【解决方案1】:

    我选择了这个对我来说效果很好的解决方案:

       if (underneath === true) {
            var marker = $scope.mainmarker.getPosition();
            var pixelpoint = $scope.projection.fromLatLngToPoint(point);
            pixelpoint.x += 250 / Math.pow(2, $scope.map.getZoom());
            point = $scope.projection.fromPointToLatLng(pixelpoint);
            $scope.map.setCenter(point);
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多