0

我是 V3 的新手。我正在将 V2 代码转换为 V3。在下面的函数中,投影值不会到来。从该投影中,它们用于 fromLatLngToPixel 和 fromPixelToLatLng。而不是这两个功能,如何在 V3 谷歌地图中使用。containsLatLng、getLatLang 还告诉如何在 V3 谷歌地图中使用。请帮忙。

  function flagContainedMarkers (){
// Iterate through the markers and only set makeVisible to
// true if the marker is inside the map bounds & padding
var pad = this.borderPadding;

var zoom        = this.map.getZoom();
var projection  = this.map.getCurrentMapType().getProjection();
var bounds      = this.map.getBounds();

var sw = bounds.getSouthWest();
sw = projection.fromLatLngToPixel(sw, zoom);
sw = new google.maps.Point(sw.x-pad, sw.y+pad);
sw = projection.fromPixelToLatLng(sw, zoom, true);

var ne = bounds.getNorthEast()
ne = projection.fromLatLngToPixel(ne, zoom);
ne = new google.maps.Point(ne.x+pad, ne.y-pad);
ne = projection.fromPixelToLatLng(ne, zoom, true);

var paddedBounds = new google.maps.LatLngBounds(sw, ne);

for (var i = this.markers.length-1; i>=0; i--) {
    var marker = this.markers[i];
    marker.makeVisible = paddedBounds.containsLatLng(marker.getLatLng()) ? true:false;
}
}
4

1 回答 1

0

这是您的代码中的一些替换...试试这个...

function flagContainedMarkers (){ // Iterate through the markers and only set makeVisible to true if the marker is inside the map bounds & padding
   var pad = this.borderPadding;
   var zoom        = this.map.getZoom();
   var projection  = this.map.getProjection();
   var bounds      = this.map.getBounds();

   var sw = bounds.getSouthWest();
       sw = projection.fromLatLngToPoint(sw, zoom);
       sw = new google.maps.Point(sw.lat()-pad, sw.lng()+pad);
       sw = projection.fromPointToLatLng(sw, zoom, true);

   var ne = bounds.getNorthEast()
       ne = projection.fromLatLngToPoint(ne, zoom);
       ne = new google.maps.Point(ne.lat()+pad, ne.lng()-pad);
       ne = projection.fromPointToLatLng(ne, zoom, true);

    var paddedBounds = new google.maps.LatLngBounds(sw, ne);
    for (var i = this.markers.length-1; i>=0; i--) {
       var marker = this.markers[i];
       marker.makeVisible = paddedBounds.contains(marker.position()) ? true:false;
    }
}
于 2013-06-20T05:33:52.757 回答