Cluster.js 2.7 KB

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