簡體   English   中英

在Google地圖上繪制圓圈和縮放級別問題

[英]Plotting Circles on a Google Map and issues with zoom level

我正在使用他們的Circle API在Google地圖上繪制一些點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;
    }
}

創建一個LatLngBounds ,用每個圓的邊界擴展這些LatLngBounds,完成創建圓后,通過將LatLngBounds作為參數,調用地圖的fitBounds方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM