繁体   English   中英

如何设置地图的缩放比例,以便可以完全看到我的路线? (here.com API)

[英]How can I set the zoom of the map so that my routes can be entirely seen? (here.com api)

我正在使用here.com api开发应用程序,并且需要自动调整地图的缩放比例,以便在加载时完全可见显示的路线? 基本上,我希望所有折线都在起始帧的边界内。 照原样,如果我的路线太长,它们的一部分会隐藏在框架之外。

您可以在JavaScript API Explorer的 developer.here.com上找到该功能的示例。

function addRouteShapeToMap(route){
  var strip = new H.geo.Strip(),
    routeShape = route.shape,
    polyline;

  routeShape.forEach(function(point) {
    var parts = point.split(',');
    strip.pushLatLngAlt(parts[0], parts[1]);
  });

  polyline = new H.map.Polyline(strip, {
    style: {
      lineWidth: 4,
      strokeColor: 'rgba(0, 128, 255, 0.7)'
    }
  });
  // Add the polyline to the map
  map.addObject(polyline);
  // And zoom to its bounding rectangle
  map.setViewBounds(polyline.getBounds(), true);
}

重要的一点是线map.setViewBounds() -方法,传入polyline.getBounds() 如果您有多个polyline ,请将其添加到H.map.Group对象,然后使用该组的getBounds()方法

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM