0

我想避免显示位于地图边缘的标记,因为它们的信息窗口是半可见的(并且我不想在显示信息窗口时拖动地图)。为此,我如何计算比原始边界小一点的地图边界(例如,从四面八方1 厘米40 像素)。

或者有没有更好的解决方案?

4

1 回答 1

0

我明白了......这是代码:

function setRectangle(center){
     var scale = Math.pow(2,MainMap.getZoom());
     var proj = MainMap.getProjection();
     var wc = proj.fromLatLngToPoint(center);
     var bounds = new google.maps.LatLngBounds();
     var sw = new google.maps.Point(((wc.x * scale) - (($('#google-map-canvas').width() - 75)*0.5))/ scale, ((wc.y * scale) - (($('#google-map-canvas').height() - 75)*0.5))/ scale);
bounds.extend(proj.fromPointToLatLng(sw));
var ne = new google.maps.Point(((wc.x * scale) + (($('#google-map-canvas').width() - 75)*0.5))/ scale, ((wc.y * scale) + (($('#google-map-canvas').height() - 75)*0.5))/ scale);
bounds.extend(proj.fromPointToLatLng(ne));
     var opts = {
        strokeColor: "#FF0000",
        strokeOpacity: 0.8,
        strokeWeight: 2,
        fillColor: "#FF0000",
        fillOpacity: 0,
        bounds: bounds,
        map: MainMap
     };
enclosedRectangle = new google.maps.Rectangle(opts);
}
于 2013-05-16T06:26:10.903 回答