将区域 latitudeDelta / longitudeDelta 转换为近似的 zoomLevel
Convert a Region latitudeDelta / longitudeDelta into an approximate zoomLevel
我在 react-native
应用程序上使用 Airbnb 的 react-native-maps
。
我在 JSON 文件中得到了一个标记列表,其中每个标记都有一个 属性 zoom
,它是标记应显示的近似缩放级别的整数/ 隐藏在地图上。
有没有一种方法可以根据 Region
的 latitudeDelta
和 longitudeDelta
获得当前缩放级别的近似值 double/integer,就像我们在 Google 地图(1 到 20)?
谢谢
好的,我有一个方便的解决方案,我不知道我们是否可以做得更好。
我添加了 onRegionChange
事件来检索区域,然后我使用了一些数学:
<MapView
style={styles.map}
initialRegion={this.state.region}
onRegionChange={region => {
clearTimeout(this.timerForMap)
this.timerForMap = setTimeout(() => {
this.showMarkers(region)
}, 100)
}}>
...
然后:
showMarkers(region) {
let zoom = Math.round(Math.log(360 / region.longitudeDelta) / Math.LN2)
...
}
如果有人有更好的方法,欢迎评论!
谢谢。
您可以在 MapView 中使用 onRegionChange 从 getCamera() 获取缩放级别
const [zoom, setZoom] = useState(''); //initiates variable zoom
const getZoom = async () => {
const coords = await mapRef.getCamera();
setZoom(coords.center.zoom); // sets variable zoom the value under coords.center.zoom
}
<MapView>
ref = {(ref) => mapRef = ref}
onRegionChange = {() => {getZoom();}}
</MapView>
我在 react-native
应用程序上使用 Airbnb 的 react-native-maps
。
我在 JSON 文件中得到了一个标记列表,其中每个标记都有一个 属性 zoom
,它是标记应显示的近似缩放级别的整数/ 隐藏在地图上。
有没有一种方法可以根据 Region
的 latitudeDelta
和 longitudeDelta
获得当前缩放级别的近似值 double/integer,就像我们在 Google 地图(1 到 20)?
谢谢
好的,我有一个方便的解决方案,我不知道我们是否可以做得更好。
我添加了 onRegionChange
事件来检索区域,然后我使用了一些数学:
<MapView
style={styles.map}
initialRegion={this.state.region}
onRegionChange={region => {
clearTimeout(this.timerForMap)
this.timerForMap = setTimeout(() => {
this.showMarkers(region)
}, 100)
}}>
...
然后:
showMarkers(region) {
let zoom = Math.round(Math.log(360 / region.longitudeDelta) / Math.LN2)
...
}
如果有人有更好的方法,欢迎评论!
谢谢。
您可以在 MapView 中使用 onRegionChange 从 getCamera() 获取缩放级别
const [zoom, setZoom] = useState(''); //initiates variable zoom
const getZoom = async () => {
const coords = await mapRef.getCamera();
setZoom(coords.center.zoom); // sets variable zoom the value under coords.center.zoom
}
<MapView>
ref = {(ref) => mapRef = ref}
onRegionChange = {() => {getZoom();}}
</MapView>