GMap 折线中心位置

发布于 2024-09-04 12:40:32 字数 1101 浏览 8 评论 0原文

当我创建 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); 
  ) 
));

When I create Gmap she needed to establish the center and zoom

Once we've created a map via the GMap2
constructor, we need to initialize it.
This initialization is accomplished
with use of the map's setCenter ()
method. The setCenter () method
requires a GLatLng coordinate and a
zoom level and this method must be
sent before any other operations are
performed on the map, including
setting any other attributes of the
map itself.

Because of this route is not positioned at the center - this is an example http://grab.by/4OD6

I should on the basis of the coordinates to get the center?

And get a zoom which displays all objects map?

My code:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

注定孤独终老 2024-09-11 12:40:32

我解决了我的问题

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

I resolve my problem

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

New code

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);
  }
});
风流物 2024-09-11 12:40:32

var TrainingGMap = Class.create({
初始化:函数(div_id,点,选项){
this.options = Object.extend({}, 选项)
this.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);
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);

}
});

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

}
});

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文