Skip to content

Commit

Permalink
fix: Always move to data layer bounds when adding new one
Browse files Browse the repository at this point in the history
  • Loading branch information
josebui committed May 9, 2024
1 parent b7eb2af commit 29cd854
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 84 deletions.
44 changes: 0 additions & 44 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"@turf/bbox": "^6.5.0",
"@turf/center": "^6.5.0",
"@turf/helpers": "^6.5.0",
"@turf/intersect": "^6.5.0",
"canvg": "^4.0.1",
"filesize": "^10.1.1",
"get-video-id": "^4.1.5",
Expand Down
40 changes: 1 addition & 39 deletions src/storyMap/components/StoryMapForm/MapLocationDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import React, {
useRef,
useState,
} from 'react';
import * as turf from '@turf/helpers';
import turfIntersect from '@turf/intersect';
import _ from 'lodash/fp';
import { Trans, useTranslation } from 'react-i18next';
import DeleteIcon from '@mui/icons-material/Delete';
Expand Down Expand Up @@ -50,36 +48,6 @@ import VisualizationMapRemoteSource from 'sharedData/visualization/components/Vi
import DataLayerDialog from './DataLayerDialog';
import { useStoryMapConfigContext } from './storyMapConfigContext';

const getDatalayerBoundsIntersection = (currentBounds, dataLayerBounds) => {
if (!dataLayerBounds) {
return true;
}
if (!currentBounds) {
return false;
}
const currentPoly = turf.polygon([
[
[currentBounds.getSouthWest().lng, currentBounds.getSouthWest().lat],
[currentBounds.getSouthWest().lng, currentBounds.getNorthEast().lat],
[currentBounds.getNorthEast().lng, currentBounds.getNorthEast().lat],
[currentBounds.getNorthEast().lng, currentBounds.getSouthWest().lat],
[currentBounds.getSouthWest().lng, currentBounds.getSouthWest().lat],
],
]);

const dataLayerPoly = turf.polygon([
[
[dataLayerBounds.southWest.lng, dataLayerBounds.southWest.lat],
[dataLayerBounds.southWest.lng, dataLayerBounds.northEast.lat],
[dataLayerBounds.northEast.lng, dataLayerBounds.northEast.lat],
[dataLayerBounds.northEast.lng, dataLayerBounds.southWest.lat],
[dataLayerBounds.southWest.lng, dataLayerBounds.southWest.lat],
],
]);

return turfIntersect(currentPoly, dataLayerPoly);
};

const BearingIcon = () => {
const { t } = useTranslation();
return (
Expand Down Expand Up @@ -327,13 +295,7 @@ const MapLocationDialog = props => {
}, []);

const onAddDataLayer = useCallback(dataLayerConfig => {
const currentBounds = mapRef.current?.getBounds();
const dataLayerBounds = dataLayerConfig?.viewportConfig?.bounds;
const intersection = getDatalayerBoundsIntersection(
currentBounds,
dataLayerBounds
);
setChangeBounds(!intersection);
setChangeBounds(true);
setDataLayerConfig(dataLayerConfig);
}, []);

Expand Down

0 comments on commit 29cd854

Please sign in to comment.