Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple spiderfier #135

Merged
merged 2 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
added feature for multiple spinner on max zoom
  • Loading branch information
chetan committed Jan 31, 2020
commit f227d057f12f1a4654b28b5f3ab10c83eaf7b1a5
46 changes: 22 additions & 24 deletions lib/ClusteredMapView.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const ClusteredMapView = ({
);

const [isSpiderfier, updateSpiderfier] = useState(false);
const [spiderfierMarker, updateSpiderfierMarker] = useState(null);
const [clusterChildren, updateClusterChildren] = useState(null);
const mapRef = createRef();

Expand Down Expand Up @@ -85,16 +84,19 @@ const ClusteredMapView = ({

useEffect(() => {
if (isSpiderfier && markers.length > 0) {
let positions = generateSpiral(
markers[0].properties.point_count,
markers[0].geometry.coordinates,
clusterChildren
);
updateSpiderMarker(positions);
updateSpiderfierMarker({
latitude: markers[0].geometry.coordinates[1],
longitude: markers[0].geometry.coordinates[0]
});
let allPositions;
markers.map(marker => {
let positions = generateSpiral(
marker.properties.point_count,
marker.geometry.coordinates,
clusterChildren
);
if (allPositions instanceof Array)
allPositions = allPositions.concat(positions);
else
allPositions = positions;
})
updateSpiderMarker(allPositions);
} else {
updateSpiderMarker([]);
}
Expand All @@ -109,7 +111,7 @@ const ClusteredMapView = ({
if (animationEnabled && Platform.OS === "ios") {
LayoutAnimation.configureNext(layoutAnimationConf);
}
if (zoom >= 17 && markers.length === 1 && clusterChildren) {
if (zoom >= 17 && markers.length > 0 && clusterChildren) {
updateSpiderfier(true);
} else {
updateSpiderfier(false);
Expand Down Expand Up @@ -182,18 +184,14 @@ const ClusteredMapView = ({
></Marker>
))}
{spiderMarkers.map((marker, index) => {
{
return (
spiderfierMarker && (
<Polyline
key={index}
coordinates={[spiderfierMarker, marker, spiderfierMarker]}
strokeColor={spiderLineColor}
strokeWidth={1}
/>
)
);
}
return (
<Polyline
key={index}
coordinates={[marker.centerPoint, marker, marker.centerPoint]}
strokeColor={spiderLineColor}
strokeWidth={1}
/>
)
})}
</MapView>
);
Expand Down
6 changes: 5 additions & 1 deletion lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ export const generateSpiral = (count, centerLocation, clusterChildren) => {
longitude,
latitude,
image: clusterChildren[i] && clusterChildren[i].properties.image,
onPress: clusterChildren[i] && clusterChildren[i].properties.onPress
onPress: clusterChildren[i] && clusterChildren[i].properties.onPress,
centerPoint: {
latitude: centerLocation[1],
longitude: centerLocation[0]
}
};
}

Expand Down