反应本地地图更改地图上活动标记的背景颜色

时间:2019-07-20 00:19:25

标签: reactjs react-native react-native-maps

如何动态更改地图上标记的活动索引的背景颜色?它会不断改变它们,任何帮助将不胜感激。谢谢。

我尝试过:


        this.state = {
            activeItem: 'red',
            defaultItem: 'black'

        };

                    <MapView
                        ref={ (map) => (this.map = map) }
                        style={ styles.map }
                        initialRegion={ initialRegion }
                        zoomEnabled={ true }
                        pitchEnabled={ true }
                        fitToElements={ true }
                        style={ styles.map }
                    >
                        { markers.map((marker, index) => {



                            return (
                                <MapView.Marker
                                    identifier={ marker.id }
                                    key={ index }
                                    coordinate={ marker.coor }

                                >
                                    <View style={ [ styles.markerContainer, { backgroundColor: activeItem ?  activeItem: defaultItem, } ] }>
                                        <Text style={ styles.markerStyle }>{ index + 1 }</Text>
                                    </View>
                                </MapView.Marker>
                            );
                        }) }
                    </MapView>

0 个答案:

没有答案
相关问题