Commit e0ce0319 authored by Qiu Xiang's avatar Qiu Xiang

调整示例代码

parent 98f2754c
...@@ -13,7 +13,7 @@ export default class AnimatedExample extends Component { ...@@ -13,7 +13,7 @@ export default class AnimatedExample extends Component {
title: '动画移动', title: '动画移动',
} }
_animatedToZGC() { _animatedToZGC = () => {
this.mapView.animateTo({ this.mapView.animateTo({
tilt: 45, tilt: 45,
rotation: 90, rotation: 90,
...@@ -25,7 +25,7 @@ export default class AnimatedExample extends Component { ...@@ -25,7 +25,7 @@ export default class AnimatedExample extends Component {
}) })
} }
_animatedToTAM() { _animatedToTAM = () => {
this.mapView.animateTo({ this.mapView.animateTo({
tilt: 0, tilt: 0,
rotation: 0, rotation: 0,
...@@ -42,12 +42,12 @@ export default class AnimatedExample extends Component { ...@@ -42,12 +42,12 @@ export default class AnimatedExample extends Component {
<MapView ref={ref => this.mapView = ref} style={styles.body}/> <MapView ref={ref => this.mapView = ref} style={styles.body}/>
<View style={styles.buttons}> <View style={styles.buttons}>
<View style={styles.button}> <View style={styles.button}>
<TouchableOpacity onPress={() => this._animatedToZGC()}> <TouchableOpacity onPress={this._animatedToZGC}>
<Text style={styles.text}>中关村</Text> <Text style={styles.text}>中关村</Text>
</TouchableOpacity> </TouchableOpacity>
</View> </View>
<View style={styles.button}> <View style={styles.button}>
<TouchableOpacity onPress={() => this._animatedToTAM()}> <TouchableOpacity onPress={this._animatedToTAM}>
<Text style={styles.text}>天安门</Text> <Text style={styles.text}>天安门</Text>
</TouchableOpacity> </TouchableOpacity>
</View> </View>
......
...@@ -31,15 +31,38 @@ export default class MarkerExample extends Component { ...@@ -31,15 +31,38 @@ export default class MarkerExample extends Component {
this.mounted = false this.mounted = false
} }
_handleDragEvent = ({nativeEvent}) =>
Alert.alert(`新坐标:${nativeEvent.latitude}, ${nativeEvent.longitude}`)
_handleInfoWindowPress = () => Alert.alert('信息窗口点击事件')
_handleCustomInfoWindowPress = () => Alert.alert('Custom View InfoWindow onPress')
_renderCustomMarker = () =>
<View style={styles.customMarker}>
<Text style={styles.markerText}>{this.state.time.toLocaleTimeString()}</Text>
</View>
_renderColoredMarker = () =>
<View style={styles.customIcon}>
<Image
style={[styles.customIcon, styles.coloredImage]}
source={require('../../images/marker.png')}/>
</View>
_renderImageMarker = () =>
<View style={styles.customIcon}>
<Image style={styles.customIcon} source={require('../../images/flag.png')}/>
</View>
render() { render() {
return <MapView style={StyleSheet.absoluteFill}> return <MapView style={StyleSheet.absoluteFill}>
<Marker <Marker
active active
draggable draggable
title={'一个可拖拽的 Marker ' + this.state.time.toLocaleTimeString()} title={'一个可拖拽的 Marker ' + this.state.time.toLocaleTimeString()}
onDragEnd={({nativeEvent}) => onDragEnd={this._handleDragEvent}
Alert.alert(`新坐标:${nativeEvent.latitude}, ${nativeEvent.longitude}`)} onInfoWindowPress={this._handleInfoWindowPress}
onInfoWindowPress={() => Alert.alert('信息窗口点击事件')}
coordinate={{ coordinate={{
latitude: 39.806901, latitude: 39.806901,
longitude: 116.397972, longitude: 116.397972,
...@@ -51,18 +74,14 @@ export default class MarkerExample extends Component { ...@@ -51,18 +74,14 @@ export default class MarkerExample extends Component {
latitude: 39.806901, latitude: 39.806901,
longitude: 116.297972, longitude: 116.297972,
}}> }}>
<TouchableOpacity activeOpacity={0.9} onPress={() => Alert.alert('Custom View InfoWindow onPress')}> <TouchableOpacity activeOpacity={0.9} onPress={this._handleCustomInfoWindowPress}>
<View style={styles.customInfoWindow}> <View style={styles.customInfoWindow}>
<Text>Custom View InfoWindow</Text> <Text>Custom View InfoWindow</Text>
</View> </View>
</TouchableOpacity> </TouchableOpacity>
</Marker> </Marker>
<Marker <Marker
icon={() => icon={this._renderImageMarker}
<View style={styles.customIcon}>
<Image style={styles.customIcon} source={require('../../images/flag.png')}/>
</View>
}
title='自定义图片' title='自定义图片'
description="Note the use of nativeOnly above. Sometimes you'll have some special properties that you need to expose for the native component, but don't actually want them as part of the API for the associated React component." description="Note the use of nativeOnly above. Sometimes you'll have some special properties that you need to expose for the native component, but don't actually want them as part of the API for the associated React component."
coordinate={{ coordinate={{
...@@ -71,13 +90,7 @@ export default class MarkerExample extends Component { ...@@ -71,13 +90,7 @@ export default class MarkerExample extends Component {
}} }}
/> />
<Marker <Marker
icon={() => icon={this._renderColoredMarker}
<View style={styles.customIcon}>
<Image
style={[styles.customIcon, {tintColor: '#e91e63'}]}
source={require('../../images/marker.png')}/>
</View>
}
title='自定义颜色' title='自定义颜色'
coordinate={{ coordinate={{
latitude: 39.806901, latitude: 39.806901,
...@@ -86,11 +99,7 @@ export default class MarkerExample extends Component { ...@@ -86,11 +99,7 @@ export default class MarkerExample extends Component {
/> />
<Marker <Marker
title='Custom View Marker' title='Custom View Marker'
icon={() => icon={this._renderCustomMarker}
<View style={styles.customMarker}>
<Text style={styles.markerText}>{this.state.time.toLocaleTimeString()}</Text>
</View>
}
coordinate={{ coordinate={{
latitude: 39.706901, latitude: 39.706901,
longitude: 116.397972, longitude: 116.397972,
...@@ -122,4 +131,7 @@ const styles = StyleSheet.create({ ...@@ -122,4 +131,7 @@ const styles = StyleSheet.create({
markerText: { markerText: {
color: '#fff', color: '#fff',
}, },
coloredImage: {
tintColor: '#e91e63',
},
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment