避免缩小 this.map.fitBounds()
Avoiding zoomout for this.map.fitBounds()
如何避免 this.map.fitBounds() 上的缩小?
执行 this.map.fitBounds 将放大或缩小地图以适合边界值。我想避免 fitBounds 的缩小功能。我该怎么做?
试过 Following.This会在执行fitBounds()后执行。在执行fitBounds()
之前需要执行
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));
您必须为地图实例设置 minZoom
选项。问题是您需要手动编辑地图实例的选项对象。 setMinZoom
和 setMaxZoom
方法已在 Leaflet v1.0.0-beta.2 中引入,而 Mapbox 尚未使用该版本。否则你可以简单地做 map.setMinZoom(number)
,现在你将不得不求助于 map.options.minZoom = number
。因此,在调整边界后,使用 map.getZoom
方法获取地图的当前缩放因子,并将该因子值设置为 minZoom
选项。
如何避免 this.map.fitBounds() 上的缩小? 执行 this.map.fitBounds 将放大或缩小地图以适合边界值。我想避免 fitBounds 的缩小功能。我该怎么做?
试过 Following.This会在执行fitBounds()后执行。在执行fitBounds()
之前需要执行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));
您必须为地图实例设置 minZoom
选项。问题是您需要手动编辑地图实例的选项对象。 setMinZoom
和 setMaxZoom
方法已在 Leaflet v1.0.0-beta.2 中引入,而 Mapbox 尚未使用该版本。否则你可以简单地做 map.setMinZoom(number)
,现在你将不得不求助于 map.options.minZoom = number
。因此,在调整边界后,使用 map.getZoom
方法获取地图的当前缩放因子,并将该因子值设置为 minZoom
选项。