Skip to content

Commit bb1b799

Browse files
committed
Makes renderCluster required (according to ClusterMarker deprecation warn)
1 parent b44d009 commit bb1b799

File tree

2 files changed

+4
-87
lines changed

2 files changed

+4
-87
lines changed

ClusterMarker.js

+1-70
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// base libs
44
import PropTypes from 'prop-types'
55
import React, { Component } from 'react'
6-
import { Marker } from 'react-native-maps'
7-
import { Text, View, StyleSheet } from 'react-native'
86

97
export default class ClusterMarker extends Component {
108
constructor(props) {
@@ -18,7 +16,6 @@ export default class ClusterMarker extends Component {
1816
}
1917

2018
render() {
21-
2219
const pointCount = this.props.properties.point_count // eslint-disable-line camelcase
2320
const latitude = this.props.geometry.coordinates[1],
2421
longitude = this.props.geometry.coordinates[0]
@@ -32,79 +29,13 @@ export default class ClusterMarker extends Component {
3229
return this.props.renderCluster(cluster, this.onPress)
3330
}
3431

35-
// keep default marker for backward compatibility, but it'll soon be deprecated
36-
console.warn('Deprecation notice: default markers will soon be deprecated. Please, start using "renderCluster" prop.') // eslint-disable-line
37-
38-
let scaleUpRatio = this.props.scaleUpRatio ? this.props.scaleUpRatio(pointCount) : (1 + (Math.min(pointCount, 999) / 100))
39-
if (isNaN(scaleUpRatio)) {
40-
console.warn('scaleUpRatio must return a Number, falling back to default') // eslint-disable-line
41-
scaleUpRatio = 1 + (Math.min(pointCount, 999) / 100)
42-
}
43-
44-
let textForCluster = '1'
45-
46-
let width = Math.floor(this.props.clusterInitialDimension * scaleUpRatio),
47-
height = Math.floor(this.props.clusterInitialDimension * scaleUpRatio),
48-
fontSize = Math.floor(this.props.clusterInitialFontSize * scaleUpRatio),
49-
borderRadius = Math.floor(width / 2)
50-
51-
// cluster dimension upper limit
52-
width = width <= (this.props.clusterInitialDimension * 2) ? width : this.props.clusterInitialDimension * 2
53-
height = height <= (this.props.clusterInitialDimension * 2) ? height : this.props.clusterInitialDimension * 2
54-
fontSize = fontSize <= 18 ? fontSize : 18
55-
56-
if (pointCount >= 2 && pointCount <= 10) {
57-
textForCluster = pointCount.toString()
58-
} else if (pointCount > 10 && pointCount <= 25) {
59-
textForCluster = '10+'
60-
} else if (pointCount > 25 && pointCount <= 50) {
61-
textForCluster = '25+'
62-
} else if (pointCount > 50 && pointCount <= 100) {
63-
textForCluster = '50+'
64-
} else if (pointCount > 100) {
65-
textForCluster = '100+'
66-
}
67-
68-
const { containerStyle, textStyle } = this.props
69-
70-
return (
71-
<Marker coordinate={{ latitude, longitude }} onPress={this.onPress}>
72-
<View style={[styles.container, containerStyle, { width, height, borderRadius }]}>
73-
<Text style={[styles.counterText, textStyle, { fontSize }]}>{textForCluster}</Text>
74-
</View>
75-
</Marker>
76-
)
32+
throw "Implement renderCluster method prop to render correctly cluster marker!"
7733
}
7834
}
7935

80-
ClusterMarker.defaultProps = {
81-
textStyle: {},
82-
containerStyle: {}
83-
}
84-
8536
ClusterMarker.propTypes = {
86-
scaleUpRatio: PropTypes.func,
8737
renderCluster: PropTypes.func,
8838
onPress: PropTypes.func.isRequired,
8939
geometry: PropTypes.object.isRequired,
90-
textStyle: PropTypes.object.isRequired,
9140
properties: PropTypes.object.isRequired,
92-
containerStyle: PropTypes.object.isRequired,
93-
clusterInitialFontSize: PropTypes.number.isRequired,
94-
clusterInitialDimension: PropTypes.number.isRequired,
9541
}
96-
97-
const styles = StyleSheet.create({
98-
container: {
99-
borderWidth: 1,
100-
alignItems: 'center',
101-
borderColor: '#65bc46',
102-
justifyContent: 'center',
103-
backgroundColor: '#fff'
104-
},
105-
counterText: {
106-
fontSize: 16,
107-
color: '#65bc46',
108-
fontWeight: '400'
109-
}
110-
})

ClusteredMapView.js

+3-17
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export default class ClusteredMapView extends PureComponent {
8787
}
8888

8989
onRegionChangeComplete(region) {
90-
let data = this.getClusters(region);
90+
let data = this.getClusters(region)
9191
this.setState({ region, data }, () => {
9292
this.props.onRegionChangeComplete && this.props.onRegionChangeComplete(region, data)
9393
})
@@ -139,13 +139,8 @@ export default class ClusteredMapView extends PureComponent {
139139
<ClusterMarker
140140
{...d}
141141
onPress={this.onClusterPress}
142-
textStyle={this.props.textStyle}
143-
scaleUpRatio={this.props.scaleUpRatio}
144142
renderCluster={this.props.renderCluster}
145-
key={`cluster-${d.properties.cluster_id}`}
146-
containerStyle={this.props.containerStyle}
147-
clusterInitialFontSize={this.props.clusterInitialFontSize}
148-
clusterInitialDimension={this.props.clusterInitialDimension} />
143+
key={`cluster-${d.properties.cluster_id}`} />
149144
)
150145
})
151146
}
@@ -162,12 +157,8 @@ ClusteredMapView.defaultProps = {
162157
minZoom: 1,
163158
maxZoom: 16,
164159
extent: 512,
165-
textStyle: {},
166-
containerStyle: {},
167160
animateClusters: true,
168161
clusteringEnabled: true,
169-
clusterInitialFontSize: 12,
170-
clusterInitialDimension: 30,
171162
clusterPressMaxChildren: 100,
172163
preserveClusterPressBehavior: true,
173164
width: Dimensions.get('window').width,
@@ -185,25 +176,20 @@ ClusteredMapView.propTypes = {
185176
extent: PropTypes.number.isRequired,
186177
minZoom: PropTypes.number.isRequired,
187178
maxZoom: PropTypes.number.isRequired,
188-
clusterInitialFontSize: PropTypes.number.isRequired,
189179
clusterPressMaxChildren: PropTypes.number.isRequired,
190-
clusterInitialDimension: PropTypes.number.isRequired,
191180
// array
192181
data: PropTypes.array.isRequired,
193182
// func
194183
onExplode: PropTypes.func,
195184
onImplode: PropTypes.func,
196-
scaleUpRatio: PropTypes.func,
197-
renderCluster: PropTypes.func,
198185
onClusterPress: PropTypes.func,
199186
renderMarker: PropTypes.func.isRequired,
187+
renderCluster: PropTypes.func.isRequired,
200188
// bool
201189
animateClusters: PropTypes.bool.isRequired,
202190
clusteringEnabled: PropTypes.bool.isRequired,
203191
preserveClusterPressBehavior: PropTypes.bool.isRequired,
204192
// object
205-
textStyle: PropTypes.object,
206-
containerStyle: PropTypes.object,
207193
layoutAnimationConf: PropTypes.object,
208194
edgePadding: PropTypes.object.isRequired,
209195
// string

0 commit comments

Comments
 (0)