首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >避免this.map.fitBounds()的放大

避免this.map.fitBounds()的放大
EN

Stack Overflow用户
提问于 2015-10-19 08:30:28
回答 1查看 161关注 0票数 0

如何避免放大this.map.fitBounds()?执行this.map.fitBounds将放大或缩小地图以拟合定界值。我想避免放大fitBounds的功能。我怎么能那样做?

尝试过的Following.This将在执行fitBounds()之后执行。需要在执行fitBounds()之前执行

代码语言:javascript
复制
var lineBounds = this._trail.getLineBounds()
 , current_zoom = this.map.getZoom()
 , center = this.map.getCenter();

 this.map.fitBounds(lineBounds, {
    padding: [29, 29],
 });

this.map.once('zoomend', function() {
   if (current_zoom > this.map.getZoom()) {
      this.map.setView(center, current_zoom);
   }
}.bind(this));
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-19 11:14:01

您必须设置映射实例的minZoom选项。问题是您需要手动编辑映射实例的options对象。setMinZoomsetMaxZoom方法已经在传单v1.0.0-beta.2中引入,Mapbox还没有使用该版本。否则,您可以简单地执行map.setMinZoom(number),现在您将不得不求助于map.options.minZoom = number。因此,在拟合好您的边界后,使用map.getZoom方法获取映射的当前缩放因子,并将该因子值设置为您的minZoom选项。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33209900

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档