Test.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 VbeClusterMap from 'vbe-cluster-map'
  7. import Button from '../../../components/Button';
  8. import { PageList } from '../../Router';
  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. /*acConnector: item.acConnector,
  51. allConnector: item.allConnector,
  52. dcConnector: item.dcConnector,*/
  53. //distance: utils.getDistance(item.distance)
  54. });
  55. });
  56. this.setState({
  57. stopList: list
  58. });
  59. }
  60. }).catch(err => {
  61. Dialog.dismissLoading();
  62. this.setState({
  63. stopList: []
  64. });
  65. })
  66. }
  67. render() {
  68. return (
  69. <View style={ui.flex1}>
  70. <View style={[ui.flexc, $padding(8, 16)]}>
  71. <Text style={ui.flex1}>Vbe Map Test</Text>
  72. <Button
  73. style={ui.flex2}
  74. text="Move"
  75. onClick={() => {
  76. if (this.state.mapReady) {
  77. this.setState({
  78. region: {
  79. latitude: 1.3532623163977140,
  80. longitude: 103.87092316860532,
  81. latitudeDelta: 0.0922,
  82. longitudeDelta: 0.0421,
  83. zoom: 17
  84. }
  85. });
  86. } else {
  87. this.setState({
  88. mapReady: true
  89. }, () => {
  90. this.getGeoLocation();
  91. });
  92. }
  93. }}/>
  94. </View>
  95. <VbeClusterMap
  96. style={ui.flex1}
  97. data={this.state.stopList}
  98. region={this.state.region}
  99. animation={true}
  100. onMapReady={() => {
  101. this.setState({
  102. mapReady: true
  103. }, () => {
  104. this.getGeoLocation();
  105. });
  106. }}
  107. onMarkerPress={e => this.viewChargeStation(e)}
  108. />
  109. <Button
  110. text="Test Page"
  111. onClick={() => startPage(PageList.home)}
  112. />
  113. </View>
  114. );
  115. }
  116. }