Skip to content

Commit 6e10a96

Browse files
chetantomekvenits
authored andcommitted
added spiral funtion in helper class
1 parent 89867ef commit 6e10a96

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed

lib/ClusteredMapView.js

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
isMarker,
88
markerToGeoJSONFeature,
99
calculateBBox,
10-
returnMapZoom
10+
returnMapZoom,
11+
generateSpiral
1112
} from "./helpers";
1213

1314
const ClusteredMapView = ({
@@ -86,6 +87,7 @@ const ClusteredMapView = ({
8687
let positions = generateSpiral(
8788
markers[0].properties.point_count,
8889
markers[0].geometry.coordinates,
90+
clusterChildren,
8991
);
9092
updateSpiderMarker(positions);
9193
updateSpiderfierMarker({
@@ -97,29 +99,6 @@ const ClusteredMapView = ({
9799
}
98100
}, [isSpiderfier]);
99101

100-
/**
101-
* To generate coordinates in spiral way
102-
* @param count Number of coordinates you want
103-
* @param centerLocation center location
104-
*/
105-
const generateSpiral = (count, centerLocation) => {
106-
let res = [];
107-
res.length = count;
108-
let angle = 0;
109-
for (let i = 0; i < count; i++) {
110-
angle = 0.1 * (i * 0.5);
111-
let latitude = centerLocation[1] + 0.00025 * angle * Math.cos(angle);
112-
let longitude = centerLocation[0] + 0.00025 * angle * Math.sin(angle);
113-
res[i] = {
114-
longitude,
115-
latitude,
116-
image: clusterChildren[i].properties.image,
117-
onPress: clusterChildren[i].properties.onPress,
118-
};
119-
}
120-
return res;
121-
};
122-
123102
const _onRegionChangeComplete = region => {
124103
if (superCluster) {
125104
const bBox = calculateBBox(region);

lib/helpers.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,24 @@ export const markerToGeoJSONFeature = (marker, index) => {
4949
};
5050
};
5151

52+
export const generateSpiral = (count, centerLocation, clusterChildren) => {
53+
let res = [];
54+
res.length = count;
55+
let angle = 0;
56+
for (let i = 0; i < count; i++) {
57+
angle = 0.1 * (i * 0.5);
58+
let latitude = centerLocation[1] + 0.00025 * angle * Math.cos(angle);
59+
let longitude = centerLocation[0] + 0.00025 * angle * Math.sin(angle);
60+
res[i] = {
61+
longitude,
62+
latitude,
63+
image: clusterChildren[i].properties.image,
64+
onPress: clusterChildren[i].properties.onPress,
65+
};
66+
}
67+
return res;
68+
};
69+
5270
export const returnMarkerStyle = points => {
5371
if (points >= 50) {
5472
return {

0 commit comments

Comments
 (0)