React-native-maps MapView.Circle

问题描述 投票:0回答:1

我试图在缩放时获得相同大小的圆圈。我试图用设置 "scale "来做,但它也不工作。我怎么能做到这一点?有人能告诉我如何能做到这一点,也许与任何例子?

               <MapView.Circle
                    key = { (this.state.longitude + this.state.latitude).toString() }
                    center = {{latitude: this.state.latitude,
                        longitude: this.state.longitude} }
                    radius = { 100 }
                    strokeWidth = { 1 }
                    strokeColor = { '#1a66ff' }
                    fillColor = { '#1a66ff' }


                />

最好的问候

react-native geometry zooming react-native-maps
1个回答
0
投票

一种方法是将当前的地图区域保存到状态,这表达了浏览者看到的坐标域......

onRegionChange(region) {
    // Update state
    this.setState({ mapRegion: region });
  }
  <MapView 
     onRegionChange={this.onRegionChange.bind(this)}
  />

有了这个,你就可以用简单的三角函数来调整半径的大小,有点像这样的...

size = {radius / Math.sqrt(this.state.mapRegion.longitudeDelta*this.state.mapRegion.longitudeDelta + this.state.mapRegion.latitudeDelta*this.state.mapRegion.latitudeDelta)}
© www.soinside.com 2019 - 2024. All rights reserved.