Test.js 3.1 KB

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