启用实时重新加载时,不会在地图上渲染折线


我正在使用react-native-map包使用API调用中收到的坐标绘制折线。当在世博会上启用热重载而不是启用实时重载时,正在绘制分界线。

我已经在下面的模板中将所有坐标转换为对象数组。{纬度:33.00,经度:-74.00},{纬度:33.10,经度:-74.02},并将此数组传递给MapView.Polyline中的坐标。

这就是我呈现MapView的方式

<MapView
                    showsUserLocation
                    followsUserLocation
                    style={{ flex: 1 }}
                    initialRegion={{
                        latitude: 31.5623499,
                        longitude: 74.3287183,
                        latitudeDelta: 0.0922,
                        longitudeDelta: 0.0421,
                    }}>

                    {this.state.allPlants.map((item, index) => {
                    return <MapView.Marker
                    key={item.id.toString()}
                    coordinate={{
                    latitude: item.latitude,
                    longitude: item.longitude,
                    }}>
                    <Image source={item.isDead?require("../../assets/dead_tree.png"):require("../../assets/tree.png")} key={item.id.toString()} />                  </MapView.Marker>
                    })}

                    <MapView.Polyline
                        coordinates={this.allCoords}
                        strokeWidth={6}
                        strokeColor="red"
                        fillColor="rgba(100,0,0,0.5)"
                        />
                </MapView>

这就是我创建坐标对象数组的方法

        let tmpArray=[]
        if(tmp.length!==0){
            for(let i=0; i<tmp.length;i++){
                let tmpObj={
                    latitude:tmp[i].latitude,
                    longitude:tmp[i].longitude
                }
                tmpArray.push( tmpObj)
            }
        }
        this.allCoords=tmpArray

它应该能够显示折线,因为它已经显示在热重新加载,我不知道这是预期的行为或这是一些错误。

转载请注明出处:http://www.cxyjjj.com/article/20230526/1799322.html