我是V3的新手。我正在将V2代码转换为V3。在下面的功能中,投影值不会到来。从该投影中,它们使用来自LatLngToPixel和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;
}
}
答案 0 :(得分: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;
}
}