我使用以下代码在react-native
中成功创建了一个标记(annotation)并添加到地图上。
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View
} from 'react-native';
import MapboxGL from '@mapbox/react-native-mapbox-gl';
import Mapbox from '@mapbox/react-native-mapbox-gl';
const columbusCircleCoordinates = [
-73.98197650909422, 40.768793007758816
];
Mapbox.setAccessToken('your access key');
export default class App extends Component {
renderAnnotations () {
return (
<Mapbox.PointAnnotation
key='pointAnnotation'
id='pointAnnotation'
coordinate={[11.254, 43.772]}>
<View style={styles.annotationContainer}>
<View style={styles.annotationFill} />
</View>
<Mapbox.Callout title='Look! An annotation!' />
</Mapbox.PointAnnotation>
)
}
render() {
return (
<View style={styles.container}>
<Mapbox.MapView
styleURL={Mapbox.StyleURL.Street}
zoomLevel={15}
centerCoordinate={[11.256, 43.770]}
showUserLocation={true}
style={styles.container}>
{this.renderAnnotations()}
</Mapbox.MapView>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
annotationContainer: {
width: 30,
height: 30,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'white',
borderRadius: 15,
},
annotationFill: {
width: 30,
height: 30,
borderRadius: 15,
backgroundColor: 'orange',
transform: [{ scale: 0.6 }],
}
});
从教程中了解到,我们可以使用 <MapboxGL.LineLayer />
在 mapbox
上绘制 折线
。但是没有演示如何实现的正确示例。
有人能提供一个样本 代码
给我吗?如何在 mapbox
的 react-native
环境下绘制两个标注之间的 线
。