1、leaflet地图容器大小改变时,使地图自适应新容器的方法
this.$nextTick(() => {
this.$refs["gaode"].map.invalidateSize(true);
})
这里因为改变了地图容器的大小,dom结构随数据而发生了改变,所以把方法写在this.$nextTick里面
2、leaflet地图多屏联动,同时放大和缩小
let that = this;
this.maps.map(item => {
item.on({
drag: () => {
that.maps.map(i => {
if (i !== item) {
i.setView(item.getCenter(), item.getZoom());
}
});
},
zoom: () => {
that.maps.map(i => {
if (i !== item) {
i.setView(item.getCenter(), item.getZoom());
}
});
}
});
});
this.maps是多个地图的集合。通过遍历地图集合去绑定drag和zoom方法。
3.leaflet地图中在贴上google图层
效果如图: