问题描述
如何在react mapbox gl中获取当前地图缩放比例?
How can i get current zoom of map in react mapbox gl?
包装: https://github.com/alex3165/react-mapbox -gl/tree/0df46b1dcf194cdf140638f653221d8a82f0b195
我已经尝试过如何开始"中的示例,以在Map
上使用getZoom
方法,但是它不起作用.我有一个错误,认为Map.getZoom不是一个函数.
I have tried on example from "How to start" to use getZoom
method on Map
but it's not working. I have error that Map.getZoom is not a function.
编辑===============
EDIT ================
当我尝试通过引用访问它时,我遇到了类似屏幕截图的问题.如何获得具有我的getZoom功能的.state.map.e?
When i try to access it by refs then i have problem like on screenshot. How to get this .state.map.e which have my getZoom function?
推荐答案
您正在使用的Map
是ReactMapboxGl
对象,它是mapbox-gl-js的包装.您要在 getZoom()
>对象.
The Map
you are using is a ReactMapboxGl
object which is a wrapper of mapbox-gl-js. You want to call getZoom()
on the mapboxgl.Map
object.
因此您可以从以下位置获取它:
So you can get it from:
<ReactMapboxGl onStyleLoad={ el => this.map = el } />
然后您可以在这里使用它:
Then you could use it here:
componentDidMount() {
const currentZoom = this.map.getZoom();
}
这篇关于如何在React-Mapbox-GL中获得当前缩放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!