Test.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import React, { Component } from 'react';
  2. import { View, Text } from 'react-native';
  3. import apiStation from '../../../api/apiStation';
  4. import Dialog from '../../../components/Dialog';
  5. import utils from '../../../utils/utils';
  6. import Button from '../../../components/Button';
  7. import { PageList } from '../../Router';
  8. import MapView from 'react-native-maps';
  9. export default class Test extends Component {
  10. constructor(props) {
  11. super(props);
  12. this.state = {
  13. region: {
  14. latitude: 1.3532623163977149,
  15. longitude: 103.87092316860532,
  16. latitudeDelta: 0.0922,
  17. longitudeDelta: 0.0421,
  18. zoom: 10
  19. },
  20. stopList: [{
  21. id: 1,
  22. latitude: 1.3532623163977149,
  23. longitude: 103.87092316860532,
  24. name: "Text",
  25. available: false
  26. }],
  27. };
  28. }
  29. viewChargeStation(e) {
  30. console.log("onMarkerPress", e);
  31. }
  32. getGeoLocation() {
  33. Dialog.showProgressDialog();
  34. apiStation.getAllStation({}).then(res => {
  35. Dialog.dismissLoading();
  36. if (res.data.sites) {
  37. const list = [];
  38. res.data.sites.forEach(item => {
  39. let available = false
  40. if (item.allConnector && item.allConnector.available) {
  41. available = true
  42. }
  43. list.push({
  44. id: item.sitePk,
  45. name: item.siteName,
  46. //address: item.siteAddress,
  47. available: available,
  48. latitude: item.locationLatitude,
  49. longitude: item.locationLongitude,
  50. favorite: item?.favorite ? true : false,
  51. /*acConnector: item.acConnector,
  52. allConnector: item.allConnector,
  53. dcConnector: item.dcConnector,*/
  54. //distance: utils.getDistance(item.distance)
  55. });
  56. });
  57. this.setState({
  58. stopList: list
  59. });
  60. }
  61. }).catch(err => {
  62. Dialog.dismissLoading();
  63. this.setState({
  64. stopList: []
  65. });
  66. })
  67. }
  68. render() {
  69. return (
  70. <View style={ui.flex1}>
  71. <View style={[ui.flexc, $padding(8, 16)]}>
  72. <Text style={ui.flex1}>Vbe Map Test</Text>
  73. <Button
  74. style={ui.flex2}
  75. text="Move"
  76. onClick={() => {
  77. if (this.state.mapReady) {
  78. this.setState({
  79. region: {
  80. latitude: 1.3532623163977140,
  81. longitude: 103.87092316860532,
  82. latitudeDelta: 0.0922,
  83. longitudeDelta: 0.0421,
  84. zoom: 17
  85. }
  86. });
  87. } else {
  88. this.setState({
  89. mapReady: true
  90. }, () => {
  91. this.getGeoLocation();
  92. });
  93. }
  94. }}/>
  95. </View>
  96. <MapView
  97. style={ui.flex1}
  98. data={this.state.stopList}
  99. region={this.state.region}
  100. animation={true}
  101. onMapReady={() => {
  102. this.setState({
  103. mapReady: true
  104. }, () => {
  105. this.getGeoLocation();
  106. });
  107. }}
  108. onMarkerPress={e => this.viewChargeStation(e)}
  109. />
  110. <Button
  111. text="Test Page"
  112. onClick={() => startPage(PageList.paymentMethod)}
  113. />
  114. </View>
  115. );
  116. }
  117. }