2010-06-08 3 views
1

Когда я создаю GMAP ей нужно установить центр и масштабGMap Ломаная положение центра

После того, как мы создали карту через конструктор GMap2, мы должны инициализировать его. Эта инициализация выполнена с использованием набора картCenter() . Метод 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); 
) 
)); 

ответ

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); 
    } 
}); 
1

вар TrainingGMap = Class.create ({ инициализации: функция (div_id , пункты, варианты) { this.options = Object.extend ({}, options) this.points = points; this.map = новый 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); 

} });

Смежные вопросы