2014-03-28 98 views
0

我使用他們的圈子API繪製一個谷歌地圖上的某些點問題https://developers.google.com/maps/documentation/javascript/examples/circle-simple繪製圓與縮放級別

我遇到的問題是,並非所有的點顯示在地圖上,預定義的縮放級別爲4,如果我只放大一個級別,則它們顯示出來。無論如何,讓他們即使在遠處放大也能出現?

這裏是我的添加標記到地圖代碼:

addMarker: function(opts) { 
    var gLatLng = this.gLatLng(opts); 
    var radius = opts.population/20; 
    var self = this; 

    this._configure_circle(radius); 

    var circle = { 
     strokeColor: this.color, 
     strokeOpacity: 0.8, 
     strokeWeight: this.stroke, 
     fillColor: this.color, 
     fillOpactiy: 1, 
     map: this.map, 
     center: gLatLng, 
     radius: this.radius 
    } 
    var gCirle = new google.maps.Circle(circle); 
    gCirle.setValues({_id: opts._id}); 
    this.markers.push(gCirle); 

    google.maps.event.addListener(gCirle, 'click', function(event){ 
    self.map.setZoom(8); 
    self.map.setCenter(new google.maps.LatLng(gCirle.getCenter().lat(), gCirle.getCenter().lng())); 
    Session.set('currentMapArea', gCirle.get('_id')); 
    }); 

    return gCirle; 
}, 
_configure_circle: function(num) { 
    if(num > 4000) { 
     this.stroke = 50; 
     this.color = '#66FF00' 
     this.radius = num + 300; 
    } else if(num <= 4000 && num > 3400) { 
     this.stroke = 25; 
     this.color = '#44E030'; 
     this.radius = num + 200; 
    } else { 
     this.stroke = 15; 
     this.color = '#22DD60'; 
     this.radius = num; 
    } 
} 

回答

0

創建LatLngBounds -object,每個圓圈的範圍擴展這些的LatLngBounds,當你完成圓的創建調用fitBounds - 將LatLngBounds作爲參數傳遞給map的方法。