Files
react-native-mapbox-gl/android/example.js
T

146 lines
4.8 KiB
JavaScript
Raw Normal View History

2015-10-11 11:53:56 -07:00
2016-05-06 14:19:12 -07:00
import React, { Component } from 'react';
2015-10-11 11:53:56 -07:00
var Mapbox = require('react-native-mapbox-gl');
2016-05-06 14:19:12 -07:00
var mapRef = 'mapRef';
import {
2015-10-11 11:53:56 -07:00
AppRegistry,
StyleSheet,
2016-05-06 14:19:12 -07:00
Text,
StatusBar,
View
} from 'react-native';
2015-10-11 11:53:56 -07:00
var MapExample = React.createClass({
2015-12-12 12:40:14 -08:00
mixins: [Mapbox.Mixin],
2015-10-11 11:53:56 -07:00
getInitialState() {
return {
center: {
latitude: 40.7223,
longitude: -73.9878
},
annotations: [{
coordinates: [40.7223, -73.9878],
type: 'point',
title: 'Important!',
subtitle: 'Neat, this is a custom annotation image',
2015-12-17 11:47:22 -08:00
id: 'marker2',
annotationImage: {
url: 'https://cldup.com/7NLZklp8zS.png',
height: 25,
width: 25
}
2015-10-11 11:53:56 -07:00
}, {
coordinates: [40.7923, -73.9178],
type: 'point',
title: 'Important!',
2015-10-24 22:29:40 -07:00
subtitle: 'Neat, this is a custom annotation image'
2015-10-11 11:53:56 -07:00
}, {
2016-01-11 14:27:27 -08:00
coordinates: [[40.76572150042782,-73.99429321289062],[40.743485405490695, -74.00218963623047],[40.728266950429735,-74.00218963623047],[40.728266950429735,-73.99154663085938],[40.73633186448861,-73.98983001708984],[40.74465591168391,-73.98914337158203],[40.749337730454826,-73.9870834350586]],
type: 'polyline',
strokeColor: '#00FB00',
strokeWidth: 3,
alpha: 0.5,
id: 'foobar'
2015-10-11 11:53:56 -07:00
}, {
2016-01-11 14:27:27 -08:00
coordinates: [[40.749857912194386, -73.96820068359375], [40.741924698522055,-73.9735221862793], [40.735681504432264,-73.97523880004883], [40.7315190495212,-73.97438049316406], [40.729177554196376,-73.97180557250975], [40.72345355209305,-73.97438049316406], [40.719290332250544,-73.97455215454102], [40.71369559554873,-73.97729873657227], [40.71200407096382,-73.97850036621094], [40.71031250340588,-73.98691177368163], [40.71031250340588,-73.99154663085938]],
type: 'polygon',
alpha:1,
fillColor: '#FFFFFF',
strokeColor: '#FFFFFF',
strokeWidth: 1,
id: 'zap'
2015-10-11 11:53:56 -07:00
}]
}
},
2015-12-14 10:51:13 -08:00
onUserLocationChange(location) {
console.log(location);
},
2016-01-15 11:09:47 -08:00
onLongPress(location) {
console.log(location);
},
onOpenAnnotation(annotation) {
console.log(annotation);
},
2015-12-12 12:40:14 -08:00
render() {
2015-10-11 11:53:56 -07:00
return (
<View style={styles.container}>
2016-01-15 11:09:47 -08:00
<Text onPress={() => this.setDirectionAnimated(mapRef, 0)}>
2015-12-12 12:40:14 -08:00
Set direction to 0
</Text>
2016-01-15 11:09:47 -08:00
<Text onPress={() => this.setCenterCoordinateAnimated(mapRef, 40.68454331694491, -73.93592834472656)}>
2015-12-12 12:40:14 -08:00
Go to New York at current zoom level
</Text>
2016-01-15 11:09:47 -08:00
<Text onPress={() => this.setCenterCoordinateZoomLevelAnimated(mapRef, 35.68829, 139.77492, 14)}>
2015-12-12 12:40:14 -08:00
Go to Tokyo at fixed zoom level 14
</Text>
2016-01-15 11:09:47 -08:00
<Text onPress={() => this.addAnnotations(mapRef, [{
2015-12-12 12:40:14 -08:00
coordinates: [40.73312,-73.989],
type: 'point',
title: 'This is a new marker',
id: 'foo'
}, {
'coordinates': [[40.75974059207392, -74.02484893798828], [40.68454331694491, -73.93592834472656]],
'type': 'polyline'
}])}>
Add new marker
</Text>
2016-01-15 11:09:47 -08:00
<Text onPress={() => this.setUserTrackingMode(mapRef, this.userTrackingMode.follow)}>
2015-12-12 12:40:14 -08:00
Set userTrackingMode to follow
</Text>
2016-01-15 11:09:47 -08:00
<Text onPress={() => this.removeAllAnnotations(mapRef)}>
2015-12-12 12:40:14 -08:00
Remove all annotations
</Text>
2016-01-15 11:09:47 -08:00
<Text onPress={() => this.setTilt(mapRef, 50)}>
2015-12-12 12:40:14 -08:00
Set tilt to 50
</Text>
2016-01-15 11:09:47 -08:00
<Text onPress={() => this.setVisibleCoordinateBoundsAnimated(mapRef, 40.712, -74.227, 40.774, -74.125, 100, 100, 100, 100)}>
2015-12-14 10:51:13 -08:00
Set visible bounds to 40.7, -74.2, 40.7, -74.1
</Text>
2016-01-15 11:09:47 -08:00
<Text onPress={() => {
this.getDirection(mapRef, (direction) => {
console.log(direction);
2016-01-15 11:09:47 -08:00
});
}}>
Get direction
</Text>
2016-01-15 11:09:47 -08:00
<Text onPress={() => {
this.getCenterCoordinateZoomLevel(mapRef, (location) => {
console.log(location);
2016-01-15 11:09:47 -08:00
});
}}>
Get location
</Text>
2015-10-11 11:53:56 -07:00
<Mapbox
annotations={this.state.annotations}
2015-12-12 12:40:14 -08:00
accessToken={'your-mapbox.com-access-token'}
2015-10-11 11:53:56 -07:00
centerCoordinate={this.state.center}
debugActive={false}
2015-12-17 11:47:22 -08:00
direction={10}
2015-12-14 10:51:13 -08:00
ref={mapRef}
2015-10-24 22:29:40 -07:00
onRegionChange={this.onRegionChange}
2016-01-08 10:30:21 -08:00
rotateEnabled={true}
2015-10-11 11:53:56 -07:00
scrollEnabled={true}
2016-01-15 11:09:47 -08:00
style={styles.container}
2015-10-24 22:29:40 -07:00
showsUserLocation={true}
styleURL={this.mapStyles.emerald}
2015-12-17 11:47:22 -08:00
userTrackingMode={this.userTrackingMode.none}
2015-10-11 11:53:56 -07:00
zoomEnabled={true}
2015-10-31 10:19:55 -07:00
zoomLevel={10}
2015-12-14 10:51:13 -08:00
compassIsHidden={true}
onUserLocationChange={this.onUserLocationChange}
2016-01-15 11:09:47 -08:00
onLongPress={this.onLongPress}
onOpenAnnotation={this.onOpenAnnotation}
2015-10-11 11:53:56 -07:00
/>
</View>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1
}
});
AppRegistry.registerComponent('your-app-name', () => MapExample);