Skip to content

Commit

Permalink
fix: data map bounds fixes (#1167)
Browse files Browse the repository at this point in the history
  • Loading branch information
josebui authored Sep 8, 2023
1 parent 9c5c70d commit bfbb9fe
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ test('LandscapeSharedDataVisualization: Display visualization', async () => {
).toBeInTheDocument();

// Map
await waitFor(() => expect(map.addSource).toHaveBeenCalledTimes(3));
expect(map.addSource.mock.calls[2][0]).toEqual('visualization');
const geojson = map.addSource.mock.calls[2][1].data;
await waitFor(() => expect(map.addSource).toHaveBeenCalledTimes(1));
expect(map.addSource.mock.calls[0][0]).toEqual('visualization');
const geojson = map.addSource.mock.calls[0][1].data;
expect(geojson.features.length).toBe(3);

expect(map.addLayer).toHaveBeenCalledTimes(3);
Expand Down
7 changes: 5 additions & 2 deletions src/sharedData/visualization/components/Visualization.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,15 @@ const MapboxLayer = props => {
);
})();

const bounds = useConfigBounds ? visualizationConfigBounds : geoJsonBounds;
const bounds =
useConfigBounds && visualizationConfigBounds
? visualizationConfigBounds
: geoJsonBounds;

if (bounds && !bounds.isEmpty()) {
map.fitBounds(bounds, {
padding: 50,
animate: false,
maxZoom: 10,
});
}
}, [map, visualizationConfig?.viewportConfig?.bounds, useConfigBounds]);
Expand Down Expand Up @@ -376,6 +378,7 @@ const Visualization = props => {
<>
<Map
disableRotation
disableElevation
projection="mercator"
mapStyle={visualizationConfig?.viewportConfig?.baseMapStyle}
onBoundsChange={onBoundsChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const PreviewStep = props => {
[setViewportConfig]
);

const onPublish = () => {
const onPublish = useCallback(() => {
const completeConfig = {
...visualizationConfig,
viewportConfig,
Expand Down Expand Up @@ -104,7 +104,16 @@ const PreviewStep = props => {
onSaved(data.payload.slug);
}
});
};
}, [
dispatch,
group,
onSaved,
owner.name,
selectedFile,
trackEvent,
viewportConfig,
visualizationConfig,
]);

return (
<>
Expand Down

0 comments on commit bfbb9fe

Please sign in to comment.