1

私が Gmap を作成するとき、彼女は中心とズームを確立する必要がありました

GMap2 コンストラクターを使用してマップを作成したら、それを初期化する必要があります。この初期化は、マップの setCenter () メソッドを使用して実行されます。setCenter () メソッドには GLatLng 座標とズーム レベルが必要であり、このメソッドは、マップ自体の他の属性の設定を含め、マップで他の操作を実行する前に送信する必要があります。

このため、ルートは中央に配置されていません - これは例ですhttp://grab.by/4OD6

座標に基づいて中心を取得する必要がありますか?

そして、すべてのオブジェクトマップを表示するズームを取得しますか?

私のコード:

var TrainingGMap = Class.create (( 
  initialize: function (div_id, points, options) ( 
    this.options = Object.extend ((), options) 
    this.points = points; 
    this.map = new GMap2 (document.getElementById (div_id)); 
    this.map.setCenter (new GLatLng (this.points [0]. lan, this.points [0]. lon), 12); 
    this.map.setUIToDefault (); 
    this.set_route (); 
  ) 

  set_route: function () ( 
    var line = new Array (); 
    for (var i = 0; i <this.points.length; i + +) ( 
      line [i] = new GLatLng (this.points [i]. lat, this.points [i]. lon); 
    ) 
    var polyline = new GPolyline (line, "# aa0000", 5); 
    this.map.addOverlay (polyline); 
  ) 
));
4

2 に答える 2

2

問題を解決します

this.map.setCenter(polyline.getBounds().getCenter());
this.map.setZoom(this.map.getBoundsZoomLevel(polyline.getBounds()));

新しいコード

var TrainingGMap = Class.create({
  initialize: function(div_id, points, options) {
    this.options = Object.extend({}, options)
    this.points  = points;
    this.map     = new GMap2(document.getElementById(div_id));
    this.map.setCenter(new GLatLng(this.points[0].lan, this.points[0].lon), 12);

    this.map.setUIToDefault();
    var line = new Array();
    for (var i = 0; i < this.points.length; i++) {  
      line[i] = new GLatLng(this.points[i].lan,this.points[i].lon);
    }
    var polyline = new GPolyline(line, "#aa0000", 5);

    this.map.setCenter(polyline.getBounds().getCenter());
    this.map.setZoom(this.map.getBoundsZoomLevel(polyline.getBounds()));
    this.map.addOverlay(polyline);
  }
});
于 2010-06-08T14:29:56.610 に答える
1

var TrainingGMap = Class.create({ initialize: function(div_id, points, options) { this.options = Object.extend({}, options) this.points = points; this.map = new GMap2(document.getElementById(div_id) )); this.map.setCenter(新しい GLatLng(this.points[0].lan, this.points[0].lon), 12);

this.map.setUIToDefault();
var line = new Array();
for (var i = 0; i < this.points.length; i++) {  
  line[i] = new GLatLng(this.points[i].lan,this.points[i].lon);
}
var polyline = new GPolyline(line, "#aa0000", 5);
var tengah=Math.round(polyline.getVertexCount()/2)-1;
this.map.setCenter(polyline.getVertex(tengah));
this.map.setZoom(this.map.getBoundsZoomLevel(polyline.getBounds()));
this.map.addOverlay(polyline);

} });

于 2010-10-22T07:15:06.493 に答える