Skip to content

Commit

Permalink
Fix map cluster zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Apr 12, 2024
1 parent a50f998 commit 96169f0
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/map/MapPositions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { map } from './core/MapView';
import { formatTime, getStatusColor } from '../common/util/formatter';
import { mapIconKey } from './core/preloadImages';
import { useAttributePreference, usePreference } from '../common/util/preferences';
import { useCatchCallback } from '../reactHelper';

const MapPositions = ({ positions, onClick, showStatus, selectedPosition, titleField }) => {
const id = useId();
Expand Down Expand Up @@ -66,19 +67,16 @@ const MapPositions = ({ positions, onClick, showStatus, selectedPosition, titleF
}
}, [onClick]);

const onClusterClick = useCallback((event) => {
const onClusterClick = useCatchCallback(async (event) => {
event.preventDefault();
const features = map.queryRenderedFeatures(event.point, {
layers: [clusters],
});
const clusterId = features[0].properties.cluster_id;
map.getSource(id).getClusterExpansionZoom(clusterId, (error, zoom) => {
if (!error) {
map.easeTo({
center: features[0].geometry.coordinates,
zoom,
});
}
const zoom = await map.getSource(id).getClusterExpansionZoom(clusterId);
map.easeTo({
center: features[0].geometry.coordinates,
zoom,
});
}, [clusters]);

Expand Down

0 comments on commit 96169f0

Please sign in to comment.