Cluster.js 2.1 KB

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