Cluster.js 2.5 KB

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