mirror of
https://github.com/expo/react-native-maps.git
synced 2026-11-15 17:39:30 -10:00
152 lines
3.6 KiB
JavaScript
152 lines
3.6 KiB
JavaScript
let React = require('react');
|
|
const ReactNative = require('react-native');
|
|
let {
|
|
StyleSheet,
|
|
PropTypes,
|
|
View,
|
|
Text,
|
|
Dimensions,
|
|
TouchableOpacity,
|
|
Image,
|
|
} = ReactNative;
|
|
|
|
let MapView = require('react-native-maps');
|
|
const PriceMarker = require('./PriceMarker');
|
|
let CustomCallout = require('./CustomCallout');
|
|
|
|
let { width, height } = Dimensions.get('window');
|
|
|
|
const ASPECT_RATIO = width / height;
|
|
const LATITUDE = 37.78825;
|
|
const LONGITUDE = -122.4324;
|
|
const LATITUDE_DELTA = 0.0922;
|
|
const LONGITUDE_DELTA = LATITUDE_DELTA * ASPECT_RATIO;
|
|
const SPACE = 0.01;
|
|
|
|
const Callouts = React.createClass({
|
|
getInitialState() {
|
|
return {
|
|
region: {
|
|
latitude: LATITUDE,
|
|
longitude: LONGITUDE,
|
|
latitudeDelta: LATITUDE_DELTA,
|
|
longitudeDelta: LONGITUDE_DELTA,
|
|
},
|
|
markers: [
|
|
{
|
|
coordinate: {
|
|
latitude: LATITUDE + SPACE,
|
|
longitude: LONGITUDE + SPACE,
|
|
},
|
|
},
|
|
{
|
|
coordinate: {
|
|
latitude: LATITUDE,
|
|
longitude: LONGITUDE,
|
|
},
|
|
},
|
|
{
|
|
coordinate: {
|
|
latitude: LATITUDE + SPACE,
|
|
longitude: LONGITUDE - SPACE,
|
|
},
|
|
},
|
|
],
|
|
};
|
|
},
|
|
|
|
show() {
|
|
this.refs.m1.showCallout();
|
|
},
|
|
|
|
hide() {
|
|
this.refs.m1.hideCallout();
|
|
},
|
|
|
|
render() {
|
|
const { region, markers } = this.state;
|
|
return (
|
|
<View style={styles.container}>
|
|
<MapView
|
|
style={styles.map}
|
|
initialRegion={region}
|
|
>
|
|
<MapView.Marker
|
|
ref="m1"
|
|
coordinate={markers[0].coordinate}
|
|
title="This is a title"
|
|
description="This is a description"
|
|
/>
|
|
<MapView.Marker ref="m2" coordinate={markers[1].coordinate}>
|
|
<MapView.Callout>
|
|
<View>
|
|
<Text>This is a plain view</Text>
|
|
</View>
|
|
</MapView.Callout>
|
|
</MapView.Marker>
|
|
<MapView.Marker
|
|
ref="m3"
|
|
coordinate={markers[2].coordinate}
|
|
calloutOffset={{ x: -8, y: 28 }}
|
|
calloutAnchor={{ x: 0.5, y: 0.4 }}
|
|
>
|
|
<MapView.Callout tooltip>
|
|
<CustomCallout>
|
|
<Text style={{ color: '#fff' }}>This is a custom callout bubble view</Text>
|
|
</CustomCallout>
|
|
</MapView.Callout>
|
|
</MapView.Marker>
|
|
</MapView>
|
|
<View style={styles.buttonContainer}>
|
|
<View style={styles.bubble}>
|
|
<Text>Tap on markers to see different callouts</Text>
|
|
</View>
|
|
</View>
|
|
<View style={styles.buttonContainer}>
|
|
<TouchableOpacity onPress={this.show} style={[styles.bubble, styles.button]}>
|
|
<Text>Show</Text>
|
|
</TouchableOpacity>
|
|
<TouchableOpacity onPress={this.hide} style={[styles.bubble, styles.button]}>
|
|
<Text>Hide</Text>
|
|
</TouchableOpacity>
|
|
</View>
|
|
</View>
|
|
);
|
|
},
|
|
});
|
|
|
|
let styles = StyleSheet.create({
|
|
container: {
|
|
...StyleSheet.absoluteFillObject,
|
|
justifyContent: 'flex-end',
|
|
alignItems: 'center',
|
|
},
|
|
map: {
|
|
...StyleSheet.absoluteFillObject,
|
|
},
|
|
bubble: {
|
|
flex: 1,
|
|
backgroundColor: 'rgba(255,255,255,0.7)',
|
|
paddingHorizontal: 18,
|
|
paddingVertical: 12,
|
|
borderRadius: 20,
|
|
},
|
|
latlng: {
|
|
width: 200,
|
|
alignItems: 'stretch',
|
|
},
|
|
button: {
|
|
width: 80,
|
|
paddingHorizontal: 12,
|
|
alignItems: 'center',
|
|
marginHorizontal: 10,
|
|
},
|
|
buttonContainer: {
|
|
flexDirection: 'row',
|
|
marginVertical: 20,
|
|
backgroundColor: 'transparent',
|
|
},
|
|
});
|
|
|
|
module.exports = Callouts;
|