将setBounds一次设置为两个不同的featureGroups mapbox传单? [英] setBounds to two different featureGroups at once mapbox leaflet?

查看:167
本文介绍了将setBounds一次设置为两个不同的featureGroups mapbox传单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作有两个要素图层的地图.

I am working on a map where I have two feature layers.

var myFeatureGroup1 = L.featureGroup().addTo(map);
var myFeatureGroup2 = L.featureGroup().addTo(map);

我正在设置边界,例如:

I am setting bounds like:

map.fitBounds(myFeatureGroup1.getBounds());
map.fitBounds(myFeatureGroup2.getBounds());

但是出于明显的原因,将myFeatureGroup2设置为开.这是使边界适合多个layerGroups的一种方法吗?像他们两个一样吗?有没有办法将它们合并到第三layerGroup中并适合其边界?

But for obvious reasons, myFeatureGroup2 is set bounds on. Is ther a way by which I can fit bounds to multiple layerGroups? Like both of them at once? Is there a way I can merge them into a third layerGroup and fit bounds on it?

推荐答案

map.fitBounds(myFeatureGroup1.getBounds().extend(myFeatureGroup2.getBounds()));

请参见 LatLngBounds 文档,这是第一个记录的方法.

See the LatLngBounds documentation, this is the first documented method.

这篇关于将setBounds一次设置为两个不同的featureGroups mapbox传单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆