Skip to content

Commit 4249a4e

Browse files
committed
Fixing minor bug
1 parent b79ff86 commit 4249a4e

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"react": "16.8.3",
1313
"react-dom": "16.8.3",
1414
"react-native": "https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz",
15-
"react-native-map-clustering": "^3.0.3",
15+
"react-native-map-clustering": "^3.0.4",
1616
"react-native-maps": "^0.26.1",
1717
"react-native-web": "^0.11.7"
1818
},

lib/ClusteredMapView.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ const ClusteredMapView = ({
3131
const [markers, updateMarkers] = useState([]);
3232
const [otherChildren, updateChildren] = useState([]);
3333
const [superCluster, setSuperCluster] = useState(null);
34+
const [currentRegion, updateRegion] = useState(
35+
restProps.region || restProps.initialRegion
36+
);
3437
const mapRef = createRef();
3538

3639
const propsChildren = useMemo(() => React.Children.toArray(children), [
@@ -40,7 +43,6 @@ const ClusteredMapView = ({
4043
useEffect(() => {
4144
const rawData = [];
4245
const otherChildren = [];
43-
const region = restProps.region || restProps.initialRegion;
4446

4547
if (!clusteringEnabled) {
4648
updateChildren(propsChildren);
@@ -65,14 +67,14 @@ const ClusteredMapView = ({
6567

6668
superCluster.load(rawData);
6769

68-
const bBox = calculateBBox(region);
69-
const zoom = returnMapZoom(region, bBox, minZoom);
70+
const bBox = calculateBBox(currentRegion);
71+
const zoom = returnMapZoom(currentRegion, bBox, minZoom);
7072
const markers = superCluster.getClusters(bBox, zoom);
7173

7274
updateMarkers(markers);
7375
updateChildren(otherChildren);
7476
setSuperCluster(superCluster);
75-
}, [children]);
77+
}, [children, restProps.region, restProps.initialRegion]);
7678

7779
const _onRegionChangeComplete = region => {
7880
if (superCluster) {
@@ -86,6 +88,7 @@ const ClusteredMapView = ({
8688

8789
updateMarkers(markers);
8890
onRegionChangeComplete(region, markers);
91+
updateRegion(region);
8992
}
9093
};
9194

lib/helpers.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { Dimensions } from "react-native";
44
const { width, height } = Dimensions.get("window");
55

66
export const isMarker = child =>
7-
child.props && child.props.coordinate && child.props.cluster !== false;
7+
child &&
8+
child.props &&
9+
child.props.coordinate &&
10+
child.props.cluster !== false;
811

912
export const calculateBBox = region => {
1013
let lngD;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-map-clustering",
3-
"version": "3.0.3",
3+
"version": "3.0.4",
44
"description": "Map clustering both for Android and iOS",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)