Cluster.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. return (
  10. <Marker
  11. key={id}
  12. coordinate={coordinate}
  13. onPress={onPress}>
  14. { coordinate.favorite
  15. ? coordinate.available
  16. ? <Image
  17. style={styles.marker}
  18. source={require('../../../images/maps/ic_marker_star.png')}/>
  19. : <Image
  20. style={styles.marker}
  21. source={require('../../../images/maps/ic_marker_unstar.png')}/>
  22. : coordinate.available
  23. ? <Image
  24. style={styles.marker}
  25. source={require('../../../images/maps/ic_marker.png')}/>
  26. : <Image
  27. style={styles.marker}
  28. source={require('../../../images/maps/ic_marker_un.png')}/>
  29. }
  30. </Marker>
  31. )
  32. }
  33. export const MyCluster = (props) => {
  34. const {id, location, properties, onPress, available=false, onOpen} = props;
  35. const pointCount = props.pointCount ? props.pointCount : properties.point_count
  36. //console.log('renderCluster', props);
  37. return (
  38. <Marker
  39. key={id}
  40. style={{ zIndex: pointCount + 1 }}
  41. coordinate={location}
  42. onPress={() => onOpen ? onOpen(location) : onPress()}>
  43. <ClusterView pointCount={pointCount} available={available}/>
  44. </Marker>
  45. );
  46. }
  47. export const ClusterView = ({pointCount, available=false}) => {
  48. const getStyle = (count) => {
  49. if (count >= 100) {
  50. return [ui.flexcc, styles.large];
  51. } else if (count >= 10) {
  52. return [ui.flexcc, styles.middle];
  53. } else {
  54. return [ui.flexcc, styles.small];
  55. }
  56. }
  57. return (
  58. <ImageBackground
  59. style={getStyle(pointCount)}
  60. source={available
  61. ? require('../../../images/maps/ic_cluster.png')
  62. : require('../../../images/maps/ic_cluster_un.png')}
  63. >
  64. <Text style={available ? styles.textAvailable : styles.textUnavailable}>{pointCount}</Text>
  65. </ImageBackground>
  66. );
  67. }
  68. const styles = StyleSheet.create({
  69. marker: {
  70. width: 29.52,
  71. height: 34.28
  72. },
  73. small: {
  74. width: 29.52,
  75. height: 34.28
  76. },
  77. middle: {
  78. width: 31,
  79. height: 36
  80. },
  81. large: {
  82. width: 34.1,
  83. height: 39.6
  84. },
  85. textAvailable: {
  86. color: textLight,
  87. fontSize: 16,
  88. paddingBottom: 7
  89. },
  90. textUnavailable: {
  91. color: '#999',
  92. fontSize: 16,
  93. paddingBottom: 7
  94. }
  95. })