Cluster.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. * 地图聚合组件
  3. * @邠心vbe on 2021/08/13
  4. */
  5. import React from 'react';
  6. import { Image, ImageBackground, StyleSheet, Text } from 'react-native';
  7. import { Marker } from 'react-native-maps';
  8. export const MyMarker = ({id, coordinate, onPress}) => {
  9. if (coordinate.upcoming) {
  10. return (
  11. <Marker
  12. key={id}
  13. zIndex={1}
  14. coordinate={coordinate}
  15. onPress={onPress}>
  16. <Image
  17. style={styles.marker}
  18. source={require('../../../images/maps/ic_marker_upcoming.png')}/>
  19. </Marker>
  20. )
  21. } else {
  22. return (
  23. <Marker
  24. key={id}
  25. zIndex={1}
  26. coordinate={coordinate}
  27. onPress={onPress}
  28. style={ui.center}>
  29. { coordinate.hasLabel &&
  30. <Image
  31. style={styles.markerTop}
  32. source={require('../../../images/maps/ic_marker_additional.png')}/>
  33. }
  34. { coordinate.favorite
  35. ? coordinate.available
  36. ? <Image
  37. style={styles.marker}
  38. source={require('../../../images/maps/ic_marker_star.png')}/>
  39. : <Image
  40. style={styles.marker}
  41. source={require('../../../images/maps/ic_marker_unstar.png')}/>
  42. : coordinate.available
  43. ? <Image
  44. style={styles.marker}
  45. source={require('../../../images/maps/ic_marker.png')}/>
  46. : <Image
  47. style={styles.marker}
  48. source={require('../../../images/maps/ic_marker_un.png')}/>
  49. }
  50. </Marker>
  51. )
  52. }
  53. }
  54. export const MyCluster = (props) => {
  55. const {id, location, properties, onPress, available=false, onOpen} = props;
  56. const pointCount = props.pointCount ? props.pointCount : properties.point_count
  57. //console.log('renderCluster', props);
  58. return (
  59. <Marker
  60. key={id}
  61. style={{ zIndex: pointCount + 1 }}
  62. coordinate={location}
  63. zIndex={pointCount + 1}
  64. onPress={() => onOpen ? onOpen(location) : onPress()}>
  65. <ClusterView pointCount={pointCount} available={available}/>
  66. </Marker>
  67. );
  68. }
  69. export const ClusterView = ({pointCount, available=false}) => {
  70. const getStyle = (count) => {
  71. if (count >= 100) {
  72. return [ui.flexcc, styles.large];
  73. } else if (count >= 10) {
  74. return [ui.flexcc, styles.middle];
  75. } else {
  76. return [ui.flexcc, styles.small];
  77. }
  78. }
  79. return (
  80. <ImageBackground
  81. style={getStyle(pointCount)}
  82. source={available
  83. ? require('../../../images/maps/ic_cluster.png')
  84. : require('../../../images/maps/ic_cluster_un.png')}>
  85. <Text style={available ? styles.textAvailable : styles.textUnavailable}>{pointCount}</Text>
  86. </ImageBackground>
  87. );
  88. }
  89. const styles = StyleSheet.create({
  90. marker: {
  91. width: 48,
  92. height: 48
  93. },
  94. markerTop: {
  95. width: 24,
  96. height: 24,
  97. marginBottom: -2
  98. },
  99. small: {
  100. width: 48,
  101. height: 48
  102. },
  103. middle: {
  104. width: 50,
  105. height: 50
  106. },
  107. large: {
  108. width: 52,
  109. height: 52
  110. },
  111. textAvailable: {
  112. color: textLight,
  113. fontSize: 18,
  114. fontWeight: 'bold',
  115. paddingBottom: 10
  116. },
  117. textUnavailable: {
  118. color: '#999',
  119. fontSize: 18,
  120. fontWeight: 'bold',
  121. paddingBottom: 10
  122. }
  123. })